浏览代码

Add resize handle withh draggable functionality to MaterialNodeView

/main
Jens Holm 7 年前
当前提交
cc2d2e3f
共有 4 个文件被更改,包括 103 次插入0 次删除
  1. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  2. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  3. 61
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Draggable.cs
  4. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Draggable.cs.meta

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


using UnityEngine.MaterialGraph;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleSheets;
namespace UnityEditor.MaterialGraph.Drawing
{

List<GraphControlPresenter> m_CurrentControls;
VisualElement m_PreviewToggle;
VisualElement m_ResizeHandle;
Image m_PreviewImage;
bool m_IsScheduled;

pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};
m_ResizeHandle = new VisualElement() { name = "resize", text = "" };
m_ResizeHandle.AddManipulator(new Draggable(OnResize));
Add(m_ResizeHandle);
}
void OnResize(Vector2 deltaSize)
{
style.width = layout.width + deltaSize.x;
style.height = layout.height + deltaSize.y;
}
void OnPreviewToggle()

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


background-color: rgba(0, 0, 0, 0.66);
}
MaterialNodeView > #resize {
background-color: rgb(0, 0, 255);
position-type: absolute;
position-right: 5;
position-bottom: 5;
width: 10;
height: 10;
}
MaterialNodeView > #resize:hover {
background-color: rgb(0, 127, 127);
}
MaterialNodeView > #resize:active {
background-color: rgb(0, 225, 25);
}
GridBackground {
grid-background-color: rgb(20, 21, 21);
line-color: rgb(20, 21, 21);

61
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Draggable.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.MaterialGraph.Drawing
{
public class Draggable : MouseManipulator
{
Action<Vector2> m_Handler;
bool m_Active;
public Draggable(Action<Vector2> handler)
{
m_Handler = handler;
m_Active = false;
activators.Add(new ManipulatorActivationFilter()
{
button = MouseButton.LeftMouse
});
}
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);
}
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)
{
target.TakeCapture();
m_Active = true;
evt.StopPropagation();
}
void OnMouseMove(MouseMoveEvent evt)
{
if (m_Active)
{
m_Handler(evt.localMousePosition);
}
}
void OnMouseUp(MouseUpEvent evt)
{
m_Active = false;
target.ReleaseCapture();
evt.StopPropagation();
}
}
}

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


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