浏览代码

Merge with master

/main
Peter Bay Bastian 7 年前
当前提交
d60a0f8d
共有 10 个文件被更改,包括 573 次插入91 次删除
  1. 63
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  2. 99
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  3. 48
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  4. 89
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  5. 99
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs
  6. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs.meta
  7. 54
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs
  8. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs.meta
  9. 179
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs
  10. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs.meta

63
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs


using System;
using System.Linq;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using Object = UnityEngine.Object;
using UnityEditor.Experimental.UIElements.GraphView;
namespace UnityEditor.ShaderGraph.Drawing.Inspector
{

}
Add(topContainer);
var bottomContainer = new VisualElement {name = "bottom"};
{
m_PreviewTextureView = new PreviewTextureView { name = "preview", image = Texture2D.blackTexture };
m_PreviewTextureView.AddManipulator(new Draggable(OnMouseDrag, true));
bottomContainer.Add(m_PreviewTextureView);
m_PreviewScrollPosition = new Vector2(0f, 0f);
m_PreviewMeshPicker = new ObjectField { objectType = typeof(Mesh) };
m_PreviewMeshPicker.OnValueChanged(OnPreviewMeshChanged);
bottomContainer.Add(m_PreviewMeshPicker);
}
Add(bottomContainer);
m_PreviewRenderHandle = previewManager.masterRenderData;
m_PreviewRenderHandle.onPreviewChanged += OnPreviewChanged;
m_PreviewMeshPicker.SetValueAndNotify(m_Graph.previewData.serializedMesh.mesh);
Add(new ResizeSideHandle(this, ResizeHandleAnchor.TopLeft, new string[] {"resize", "diagonal", "top-left"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.Top, new string[] {"resize", "vertical", "top"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.TopRight, new string[] {"resize", "diagonal", "top-right"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.Right, new string[] {"resize", "horizontal", "right"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.BottomRight, new string[] {"resize", "diagonal", "bottom-right"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.Bottom, new string[] {"resize", "vertical", "bottom"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.BottomLeft, new string[] {"resize", "diagonal", "bottom-left"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.Left, new string[] {"resize", "horizontal", "left"}));
}
Add(new ResizeBorderFrame(this) { name = "resizeBorderFrame" });
MasterNode masterNode
{
get { return m_PreviewRenderHandle.shaderData.node as MasterNode; }
}
void OnMouseDrag(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);
this.AddManipulator(new WindowDraggable());
}
void OnAddProperty()

{
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;
}
public void HandleGraphChanges()

99
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.UIElements;

{
VisualElement m_ResizeTarget;
ResizeHandleAnchor m_HandleAnchor;
public Action OnResizeFinished;
public ResizeSideHandle(VisualElement resizeTarget, ResizeHandleAnchor anchor, string[] styleClasses)
public ResizeSideHandle(VisualElement resizeTarget, ResizeHandleAnchor anchor)
foreach (string styleClass in styleClasses)
AddToClassList("resize");
switch (anchor)
AddToClassList(styleClass);
case ResizeHandleAnchor.Top:
{
AddToClassList("vertical");
AddToClassList("top");
break;
}
case ResizeHandleAnchor.TopRight:
{
AddToClassList("diagonal");
AddToClassList("top-right");
break;
}
case ResizeHandleAnchor.Right:
{
AddToClassList("horizontal");
AddToClassList("right");
break;
}
case ResizeHandleAnchor.BottomRight:
{
AddToClassList("diagonal");
AddToClassList("bottom-right");
break;
}
case ResizeHandleAnchor.Bottom:
{
AddToClassList("vertical");
AddToClassList("bottom");
break;
}
case ResizeHandleAnchor.BottomLeft:
{
AddToClassList("diagonal");
AddToClassList("bottom-left");
break;
}
case ResizeHandleAnchor.Left:
{
AddToClassList("horizontal");
AddToClassList("left");
break;
}
case ResizeHandleAnchor.TopLeft:
{
AddToClassList("diagonal");
AddToClassList("top-left");
break;
}
m_HandleAnchor = anchor;
bool moveWhileResizeHorizontal = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.BottomLeft || anchor == ResizeHandleAnchor.Left;
bool moveWhileResizeVertical = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.TopRight || anchor == ResizeHandleAnchor.Top;
if (anchor == ResizeHandleAnchor.Left || anchor == ResizeHandleAnchor.Right)
{

resizeDirection = ResizeDirection.Any;
}
bool moveWhileResizeHorizontal = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.BottomLeft || anchor == ResizeHandleAnchor.Left;
bool moveWhileResizeVertical = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.TopRight || anchor == ResizeHandleAnchor.Top;
RegisterCallback<MouseUpEvent>(HandleDraggableMouseUp);
}
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizerVertical)

Vector2 minSize = new Vector2(60f, 60f);
if (!Mathf.Approximately(m_ResizeTarget.style.minWidth.value, 0f))
{
minSize.x = m_ResizeTarget.style.minWidth;
}
if (!Mathf.Approximately(m_ResizeTarget.style.minHeight.value, 0f))
{
minSize.y = m_ResizeTarget.style.minHeight.value;
}
if (direction == ResizeDirection.Vertical)
{
normalizedResizeDelta.x = 0f;

// Resize form bottom/right
if (!moveWhileResizeHorizontal)
{
newLayout.width = Mathf.Max(newLayout.width + normalizedResizeDelta.x, 60f);
newLayout.width = Mathf.Max(newLayout.width + normalizedResizeDelta.x, minSize.x);
newLayout.height = Mathf.Max(newLayout.height + normalizedResizeDelta.y, 60f);
newLayout.height = Mathf.Max(newLayout.height + normalizedResizeDelta.y, minSize.y);
normalizedResizeDelta.y = 0f;
}

newLayout.width = Mathf.Max(newLayout.width - normalizedResizeDelta.x, 60f);
newLayout.height = Mathf.Max(newLayout.height - normalizedResizeDelta.y, 60f);
newLayout.width = Mathf.Max(newLayout.width - normalizedResizeDelta.x, minSize.x);
newLayout.height = Mathf.Max(newLayout.height - normalizedResizeDelta.y, minSize.y);
newLayout.x = Mathf.Min(newLayout.x + normalizedResizeDelta.x, previousFarX - 60f);
newLayout.y = Mathf.Min(newLayout.y + normalizedResizeDelta.y, previousFarY - 60f);
newLayout.x = Mathf.Min(newLayout.x + normalizedResizeDelta.x, previousFarX - minSize.x);
newLayout.y = Mathf.Min(newLayout.y + normalizedResizeDelta.y, previousFarY - minSize.y);
}
void HandleDraggableMouseUp(MouseUpEvent evt)
{
if (OnResizeFinished != null)
{
OnResizeFinished();
}
}
}
}

48
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


namespace UnityEditor.ShaderGraph.Drawing
{
[Serializable]
class FloatingWindowsLayout
{
public Rect previewLayout;
}
MasterPreviewView m_MasterPreviewView;
private EditorWindow m_EditorWindow;
AbstractMaterialGraph m_Graph;

BlackboardProvider m_BlackboardProvider;
string m_FloatingWindowsLayoutKey;
FloatingWindowsLayout m_FLoatingWindowsLayout;
public Action saveRequested { get; set; }

var content = new VisualElement { name = "content" };
{
m_GraphView = new MaterialGraphView(graph) { name = "GraphView", persistenceKey = "MaterialGraphView" };
m_GraphView.SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
m_GraphView.SetupZoom(0.05f, ContentZoomer.DefaultMaxScale);
m_GraphView.AddManipulator(new ContentDragger());
m_GraphView.AddManipulator(new SelectionDragger());
m_GraphView.AddManipulator(new RectangleSelector());

m_BlackboardProvider = new BlackboardProvider(assetName, graph);
m_GraphView.Add(m_BlackboardProvider.blackboard);
m_BlackboardProvider.blackboard.layout = new Rect(new Vector2(10f, 10f), m_BlackboardProvider.blackboard.layout.size);
m_MasterPreviewView = new MasterPreviewView(assetName, previewManager, graph) { name = "masterPreview" };
WindowDraggable masterPreviewViewDraggable = new WindowDraggable();
masterPreviewViewDraggable.OnDragFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.AddManipulator(masterPreviewViewDraggable);
m_GraphView.Add(m_MasterPreviewView);
ResizeBorderFrame masterPreviewResizeBorderFrame = new ResizeBorderFrame(m_MasterPreviewView) { name = "resizeBorderFrame" };
masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.Add(masterPreviewResizeBorderFrame);
m_FloatingWindowsLayoutKey = "UnityEditor.ShaderGraph.FloatingWindowsLayout";
string serializedWindowLayout = EditorUserSettings.GetConfigValue(m_FloatingWindowsLayoutKey);
if (!String.IsNullOrEmpty(serializedWindowLayout))
{
m_FLoatingWindowsLayout = JsonUtility.FromJson<FloatingWindowsLayout>(serializedWindowLayout);
m_MasterPreviewView.layout = m_FLoatingWindowsLayout.previewLayout;
}
else
{
m_FLoatingWindowsLayout = new FloatingWindowsLayout();
}
}
m_SearchWindowProvider = ScriptableObject.CreateInstance<SearchWindowProvider>();

}
Stack<MaterialNodeView> m_NodeStack = new Stack<MaterialNodeView>();
BlackboardProvider m_BlackboardProvider;
void UpdateEdgeColors(HashSet<MaterialNodeView> nodeViews)
{

}
}
}
}
void UpdateSerializedWindowLayout()
{
m_FLoatingWindowsLayout.previewLayout = m_MasterPreviewView.layout;
string serializedWindowLayout = JsonUtility.ToJson(m_FLoatingWindowsLayout);
EditorUserSettings.SetConfigValue(m_FloatingWindowsLayoutKey, serializedWindowLayout);
}
public void Dispose()

89
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


position-type: absolute;
position-right: 0;
position-top: 0;
width: 600;
height: 800;
width: 400;
min-width: 300;
}
GraphInspectorView * {

padding-bottom: 4;
}
GraphInspectorView > .resize {
MasterPreviewView {
flex-direction: column;
position-type: absolute;
position-right: 0;
position-bottom: 0;
background-color: rgb(79, 79, 79);
justify-content: flex-start;
min-width: 200;
min-height: 200;
}
MasterPreviewView > #top {
background-color: rgb(64, 64, 64);
}
MasterPreviewView > #top > #title {
font-style: bold;
font-size: 11;
}
MasterPreviewView > #top {
padding-top: 8;
padding-bottom: 8;
padding-left: 8;
padding-right: 8;
}
MasterPreviewView > #middle {
flex-grow: 1;
flex-direction: row;
margin-bottom: 40;
}
MasterPreviewView > #middle > #preview {
flex-grow: 1;
}
MasterPreviewView > #bottom {
background-color: rgb(79, 79, 79);
position-type: absolute;
position-bottom: 0;
position-left: 0;
position-right: 0;
padding-left: 10;
padding-right: 10;
padding-top: 8;
padding-bottom: 12;
}
MasterPreviewView > #bottom > #picker > ObjectFieldDisplay > Label {
font-size: 11;
}
#resizeBorderFrame > .resize {
GraphInspectorView > .resize.vertical {
#resizeBorderFrame > .resize.vertical {
cursor: resize-vertical;
height: 10;
position-left: 10;

margin-bottom: 0;
}
GraphInspectorView > .resize.horizontal {
#resizeBorderFrame > .resize.horizontal {
cursor: resize-horizontal;
width: 10;
position-top: 10;

margin-right: 0;
}
GraphInspectorView > .resize.diagonal {
#resizeBorderFrame > .resize.diagonal {
GraphInspectorView > .resize.diagonal.top-left {
#resizeBorderFrame > .resize.diagonal.top-left {
GraphInspectorView > .resize.diagonal.top-right {
#resizeBorderFrame > .resize.diagonal.top-right {
GraphInspectorView > .resize.diagonal.bottom-left {
#resizeBorderFrame > .resize.diagonal.bottom-left {
GraphInspectorView > .resize.diagonal.bottom-right {
#resizeBorderFrame > .resize.diagonal.bottom-right {
GraphInspectorView > .resize.vertical.top {
#resizeBorderFrame > .resize.vertical.top {
GraphInspectorView > .resize.vertical.bottom {
#resizeBorderFrame > .resize.vertical.bottom {
GraphInspectorView > .resize.horzontal.left {
#resizeBorderFrame > .resize.horzontal.left {
GraphInspectorView > .resize.horizontal.right {
#resizeBorderFrame > .resize.horizontal.right {
position-right: 0;
}
.reszieBorderFrame {
position-type: absolute;
position-top: 0;
position-bottom: 0;
position-left: 0;
}
ShaderPropertyView {

99
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs


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);
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs.meta


fileFormatVersion: 2
guid: 546947d46a85b284a971a3f056495735
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

54
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs


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();
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs.meta


fileFormatVersion: 2
guid: 1128492b211994d46be4acd2ccac15fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

179
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs


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;
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs.meta


fileFormatVersion: 2
guid: 604681490aa779348a355368c95cfcf5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存