Jens Holm
7 年前
当前提交
5f6443a4
共有 5 个文件被更改,包括 100 次插入 和 37 次删除
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterNodeView.cs
-
36MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
-
86MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs.meta
|
|||
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_Active; |
|||
|
|||
Vector2 m_LocalMosueOffset; |
|||
|
|||
public WindowDraggable() |
|||
{ |
|||
m_Active = false; |
|||
} |
|||
|
|||
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>(OnPostLayout); |
|||
} |
|||
|
|||
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) |
|||
{ |
|||
m_Active = false; |
|||
|
|||
if (target.HasMouseCapture()) |
|||
{ |
|||
target.ReleaseMouseCapture(); |
|||
} |
|||
|
|||
evt.StopPropagation(); |
|||
} |
|||
|
|||
void OnPostLayout(PostLayoutEvent postLayoutEvent) |
|||
{ |
|||
Rect inspectorViewRect = target.layout; |
|||
|
|||
float minimumXPosition = target.layout.width - inspectorViewRect.width; |
|||
float maximumXPosition = target.parent.layout.width - target.layout.width; |
|||
|
|||
float minimumYPosition = target.layout.height - inspectorViewRect.height; |
|||
float maximumYPosition = target.parent.layout.height - target.layout.height; |
|||
|
|||
inspectorViewRect.x = Mathf.Clamp(inspectorViewRect.x, minimumXPosition, maximumXPosition); |
|||
inspectorViewRect.y = Mathf.Clamp(inspectorViewRect.y, minimumYPosition, maximumYPosition); |
|||
|
|||
inspectorViewRect.width = Mathf.Min(inspectorViewRect.width, target.layout.width); |
|||
inspectorViewRect.height = Mathf.Min(inspectorViewRect.height, target.layout.height); |
|||
|
|||
target.layout = inspectorViewRect; |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 604681490aa779348a355368c95cfcf5 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue