GitHub
7 年前
当前提交
dfcf6af9
共有 10 个文件被更改,包括 575 次插入 和 125 次删除
-
63MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
-
99MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
-
84MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
-
89MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
-
99MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs.meta
-
54MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs.meta
-
179MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs.meta
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEditor.Graphing; |
|||
using Object = UnityEngine.Object; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Inspector |
|||
{ |
|||
public class MasterPreviewView : VisualElement |
|||
{ |
|||
AbstractMaterialGraph m_Graph; |
|||
|
|||
PreviewRenderData m_PreviewRenderHandle; |
|||
PreviewTextureView m_PreviewTextureView; |
|||
|
|||
Vector2 m_PreviewScrollPosition; |
|||
ObjectField m_PreviewMeshPicker; |
|||
|
|||
MasterNode m_MasterNode; |
|||
|
|||
public MasterPreviewView(string assetName, PreviewManager previewManager, AbstractMaterialGraph graph) |
|||
{ |
|||
m_Graph = graph; |
|||
|
|||
AddStyleSheetPath("Styles/MaterialGraph"); |
|||
|
|||
m_PreviewRenderHandle = previewManager.masterRenderData; |
|||
m_PreviewRenderHandle.onPreviewChanged += OnPreviewChanged; |
|||
|
|||
var topContainer = new VisualElement() { name = "top" }; |
|||
{ |
|||
var title = new Label(assetName + " master node preview") { name = "title" }; |
|||
topContainer.Add(title); |
|||
} |
|||
Add(topContainer); |
|||
|
|||
var middleContainer = new VisualElement {name = "middle"}; |
|||
{ |
|||
m_PreviewTextureView = new PreviewTextureView { name = "preview", image = Texture2D.blackTexture }; |
|||
m_PreviewTextureView.AddManipulator(new Draggable(OnMouseDragPreviwMesh, true)); |
|||
middleContainer.Add(m_PreviewTextureView); |
|||
|
|||
m_PreviewScrollPosition = new Vector2(0f, 0f); |
|||
|
|||
middleContainer.Add(m_PreviewTextureView); |
|||
} |
|||
Add(middleContainer); |
|||
|
|||
var bottomContainer = new VisualElement() { name = "bottom" }; |
|||
{ |
|||
m_PreviewMeshPicker = new ObjectField { name = "picker", objectType = typeof(Mesh) }; |
|||
m_PreviewMeshPicker.OnValueChanged(OnPreviewMeshChanged); |
|||
|
|||
bottomContainer.Add(m_PreviewMeshPicker); |
|||
} |
|||
Add(bottomContainer); |
|||
} |
|||
|
|||
MasterNode masterNode |
|||
{ |
|||
get { return m_PreviewRenderHandle.shaderData.node as MasterNode; } |
|||
} |
|||
|
|||
void OnPreviewChanged() |
|||
{ |
|||
m_PreviewTextureView.image = m_PreviewRenderHandle.texture ?? Texture2D.blackTexture; |
|||
m_PreviewTextureView.Dirty(ChangeType.Repaint); |
|||
} |
|||
|
|||
void OnPreviewMeshChanged(ChangeEvent<Object> changeEvent) |
|||
{ |
|||
Mesh changedMesh = changeEvent.newValue as Mesh; |
|||
|
|||
masterNode.Dirty(ModificationScope.Node); |
|||
|
|||
if (m_Graph.previewData.serializedMesh.mesh != changedMesh) |
|||
{ |
|||
m_Graph.previewData.rotation = Quaternion.identity; |
|||
} |
|||
|
|||
m_Graph.previewData.serializedMesh.mesh = changedMesh; |
|||
} |
|||
|
|||
void OnMouseDragPreviwMesh(Vector2 deltaMouse) |
|||
{ |
|||
Vector2 previewSize = m_PreviewTextureView.contentRect.size; |
|||
|
|||
m_PreviewScrollPosition -= deltaMouse * (Event.current.shift ? 3f : 1f) / Mathf.Min(previewSize.x, previewSize.y) * 140f; |
|||
m_PreviewScrollPosition.y = Mathf.Clamp(m_PreviewScrollPosition.y, -90f, 90f); |
|||
Quaternion previewRotation = Quaternion.Euler(m_PreviewScrollPosition.y, 0, 0) * Quaternion.Euler(0, m_PreviewScrollPosition.x, 0); |
|||
m_Graph.previewData.rotation = previewRotation; |
|||
|
|||
masterNode.Dirty(ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 546947d46a85b284a971a3f056495735 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEditor.ShaderGraph.Drawing; |
|||
|
|||
|
|||
public class ResizeBorderFrame : VisualElement |
|||
{ |
|||
public Action OnResizeFinished; |
|||
|
|||
public ResizeBorderFrame(VisualElement target) |
|||
{ |
|||
pickingMode = PickingMode.Ignore; |
|||
|
|||
AddToClassList("reszieBorderFrame"); |
|||
|
|||
ResizeSideHandle topLeft = new ResizeSideHandle(target, ResizeHandleAnchor.TopLeft); |
|||
ResizeSideHandle top = new ResizeSideHandle(target, ResizeHandleAnchor.Top); |
|||
ResizeSideHandle topRight = new ResizeSideHandle(target, ResizeHandleAnchor.TopRight); |
|||
ResizeSideHandle right = new ResizeSideHandle(target, ResizeHandleAnchor.Right); |
|||
ResizeSideHandle bottomRight = new ResizeSideHandle(target, ResizeHandleAnchor.BottomRight); |
|||
ResizeSideHandle bottom = new ResizeSideHandle(target, ResizeHandleAnchor.Bottom); |
|||
ResizeSideHandle bottomLeft = new ResizeSideHandle(target, ResizeHandleAnchor.BottomLeft); |
|||
ResizeSideHandle left = new ResizeSideHandle(target, ResizeHandleAnchor.Left); |
|||
|
|||
topLeft.OnResizeFinished += HandleResizefinished; |
|||
top.OnResizeFinished += HandleResizefinished; |
|||
topRight.OnResizeFinished += HandleResizefinished; |
|||
right.OnResizeFinished += HandleResizefinished; |
|||
bottomRight.OnResizeFinished += HandleResizefinished; |
|||
bottom.OnResizeFinished += HandleResizefinished; |
|||
bottomLeft.OnResizeFinished += HandleResizefinished; |
|||
left.OnResizeFinished += HandleResizefinished; |
|||
|
|||
Add(topLeft); |
|||
Add(top); |
|||
Add(topRight); |
|||
Add(right); |
|||
Add(bottomRight); |
|||
Add(bottom); |
|||
Add(bottomLeft); |
|||
Add(left); |
|||
} |
|||
|
|||
void HandleResizefinished() |
|||
{ |
|||
if (OnResizeFinished != null) |
|||
{ |
|||
OnResizeFinished(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1128492b211994d46be4acd2ccac15fb |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEditor.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing |
|||
{ |
|||
public class WindowDraggable : MouseManipulator |
|||
{ |
|||
bool m_ResizeWithParentWindow; |
|||
|
|||
bool m_Active; |
|||
|
|||
bool m_DockLeft; |
|||
bool m_DockTop; |
|||
|
|||
Vector2 m_LocalMosueOffset; |
|||
Rect m_PreviousParentRect; |
|||
|
|||
public Action OnDragFinished; |
|||
|
|||
public WindowDraggable(bool resizeWithParentwindow = false) |
|||
{ |
|||
m_ResizeWithParentWindow = resizeWithParentwindow; |
|||
m_Active = false; |
|||
m_PreviousParentRect = new Rect(0f, 0f, 0f, 0f); |
|||
} |
|||
|
|||
protected override void RegisterCallbacksOnTarget() |
|||
{ |
|||
target.RegisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), Capture.NoCapture); |
|||
target.RegisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), Capture.NoCapture); |
|||
target.RegisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), Capture.NoCapture); |
|||
target.RegisterCallback<PostLayoutEvent>(InitialLayoutSetup); |
|||
} |
|||
|
|||
protected override void UnregisterCallbacksFromTarget() |
|||
{ |
|||
target.UnregisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), Capture.NoCapture); |
|||
target.UnregisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), Capture.NoCapture); |
|||
target.UnregisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), Capture.NoCapture); |
|||
} |
|||
|
|||
void OnMouseDown(MouseDownEvent evt) |
|||
{ |
|||
m_Active = true; |
|||
m_LocalMosueOffset = target.WorldToLocal(evt.mousePosition); |
|||
|
|||
target.TakeMouseCapture(); |
|||
evt.StopPropagation(); |
|||
} |
|||
|
|||
void OnMouseMove(MouseMoveEvent evt) |
|||
{ |
|||
if (m_Active) |
|||
{ |
|||
Rect layout = target.layout; |
|||
layout.position = target.parent.WorldToLocal(evt.mousePosition - m_LocalMosueOffset); |
|||
target.layout = layout; |
|||
} |
|||
} |
|||
|
|||
void OnMouseUp(MouseUpEvent evt) |
|||
{ |
|||
bool emitDragFinishedEvent = m_Active; |
|||
|
|||
m_Active = false; |
|||
|
|||
if (target.HasMouseCapture()) |
|||
{ |
|||
target.ReleaseMouseCapture(); |
|||
} |
|||
|
|||
evt.StopPropagation(); |
|||
|
|||
RefreshDocking(); |
|||
|
|||
if (emitDragFinishedEvent && OnDragFinished != null) |
|||
{ |
|||
OnDragFinished(); |
|||
} |
|||
} |
|||
|
|||
void RefreshDocking() |
|||
{ |
|||
Vector2 windowCenter = new Vector2(target.layout.x + target.layout.width * .5f, target.layout.y + target.layout.height * .5f); |
|||
windowCenter /= target.parent.layout.size; |
|||
|
|||
m_DockLeft = windowCenter.x < .5f; |
|||
m_DockTop = windowCenter.y < .5f; |
|||
} |
|||
|
|||
void InitialLayoutSetup(PostLayoutEvent postLayoutEvent) |
|||
{ |
|||
m_PreviousParentRect = target.parent.layout; |
|||
target.UnregisterCallback<PostLayoutEvent>(InitialLayoutSetup); |
|||
target.RegisterCallback<PostLayoutEvent>(OnPostLayout); |
|||
|
|||
RefreshDocking(); |
|||
} |
|||
|
|||
void OnPostLayout(PostLayoutEvent postLayoutEvent) |
|||
{ |
|||
Rect windowRect = target.layout; |
|||
|
|||
Vector2 scaling = target.parent.layout.size / m_PreviousParentRect.size; |
|||
|
|||
Vector2 minSize = new Vector2(60f, 60f); |
|||
|
|||
if (!Mathf.Approximately(target.style.minWidth, 0f)) |
|||
{ |
|||
minSize.x = target.style.minWidth; |
|||
} |
|||
|
|||
if (!Mathf.Approximately(target.style.minHeight, 0f)) |
|||
{ |
|||
minSize.y = target.style.minHeight; |
|||
} |
|||
|
|||
Vector2 distanceFromParentEdge = Vector2.zero; |
|||
distanceFromParentEdge.x = m_DockLeft ? target.layout.x : (m_PreviousParentRect.width - target.layout.x - target.layout.width); |
|||
distanceFromParentEdge.y = m_DockTop ? target.layout.y: (m_PreviousParentRect.height - target.layout.y - target.layout.height); |
|||
|
|||
Vector2 normalizedDistanceFromEdge = distanceFromParentEdge / m_PreviousParentRect.size; |
|||
|
|||
if (m_ResizeWithParentWindow) |
|||
{ |
|||
if (scaling.x > 1f) |
|||
{ |
|||
scaling.x = target.parent.layout.width * .33f < minSize.x ? 1f : scaling.x; |
|||
} |
|||
|
|||
if (scaling.y > 1f) |
|||
{ |
|||
scaling.y = target.parent.layout.height * .33f < minSize.y ? 1f : scaling.y; |
|||
} |
|||
|
|||
windowRect.size *= scaling; |
|||
} |
|||
else |
|||
{ |
|||
normalizedDistanceFromEdge = distanceFromParentEdge / target.parent.layout.size; |
|||
} |
|||
|
|||
if (m_DockLeft) |
|||
{ |
|||
windowRect.x = normalizedDistanceFromEdge.x * target.parent.layout.width; |
|||
} |
|||
else |
|||
{ |
|||
windowRect.x = (1f - normalizedDistanceFromEdge.x) * target.parent.layout.width - windowRect.width; |
|||
} |
|||
|
|||
if (m_DockTop) |
|||
{ |
|||
windowRect.y = normalizedDistanceFromEdge.y * target.parent.layout.height; |
|||
} |
|||
else |
|||
{ |
|||
windowRect.y = (1f - normalizedDistanceFromEdge.y) * target.parent.layout.height- windowRect.height; |
|||
} |
|||
|
|||
windowRect.width = Mathf.Max(Mathf.Min(windowRect.width, target.parent.layout.width), minSize.x); |
|||
windowRect.height = Mathf.Max(Mathf.Min(windowRect.height, target.parent.layout.height), minSize.y); |
|||
|
|||
float maximumXPosition = Mathf.Max(target.parent.layout.width - windowRect.width, 0f); |
|||
float maximumYPosition = Mathf.Max(target.parent.layout.height - windowRect.height, 0f); |
|||
|
|||
windowRect.x = Mathf.Clamp(windowRect.x, 0f, maximumXPosition); |
|||
windowRect.y = Mathf.Clamp(windowRect.y, 0f, maximumYPosition); |
|||
|
|||
m_PreviousParentRect = target.parent.layout; |
|||
|
|||
target.layout = windowRect; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 604681490aa779348a355368c95cfcf5 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue