浏览代码

Inspector window changes (#138)

* Add resize handle class and reuse some resize handle uss styling in inspector window

* Reigister postlayout callback on graphview rather than inspector view

* Remove resize function from GraphInspectorView

* Add resize handles to corner of inspector window
/main
Peter Bay Bastian 7 年前
当前提交
758cf9e6
共有 5 个文件被更改,包括 179 次插入84 次删除
  1. 68
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  3. 76
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  4. 106
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  5. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs.meta

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


{
public class GraphInspectorView : VisualElement, IDisposable
{
enum ResizeDirection
{
Any,
Vertical,
Horizontal
}
int m_SelectionHash;
VisualElement m_PropertyItems;

foreach (var property in m_Graph.properties)
m_PropertyItems.Add(new ShaderPropertyView(m_Graph, property));
var resizeHandleTop = new Label { name = "resize-top", text = "" };
resizeHandleTop.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, ResizeDirection.Vertical, true)));
Add(resizeHandleTop);
var resizeHandleRight = new Label { name = "resize-right", text = "" };
resizeHandleRight.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, ResizeDirection.Horizontal, false)));
Add(resizeHandleRight);
var resizeHandleLeft = new Label { name = "resize-left", text = "" };
resizeHandleLeft.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, ResizeDirection.Horizontal, true)));
Add(resizeHandleLeft);
var resizeHandleBottom = new Label { name = "resize-bottom", text = "" };
resizeHandleBottom.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, ResizeDirection.Vertical, false)));
Add(resizeHandleBottom);
}
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResize)
{
Vector2 normalizedResizeDelta = resizeDelta / 2f;
if (direction == ResizeDirection.Vertical)
{
normalizedResizeDelta.x = 0f;
}
else if (direction == ResizeDirection.Horizontal)
{
normalizedResizeDelta.y = 0f;
}
Rect newLayout = layout;
// Resize form bottom/right
if (!moveWhileResize)
{
newLayout.width = Mathf.Max(layout.width + normalizedResizeDelta.x, 60f);
newLayout.height = Mathf.Max(layout.height + normalizedResizeDelta.y, 60f);
layout = newLayout;
return;
}
float previousFarX = layout.x + layout.width;
float previousFarY = layout.y + layout.height;
newLayout.width = Mathf.Max(layout.width - normalizedResizeDelta.x, 60f);
newLayout.height = Mathf.Max(layout.height - normalizedResizeDelta.y, 60f);
newLayout.x = Mathf.Min(layout.x + normalizedResizeDelta.x, previousFarX - 60f);
newLayout.y = Mathf.Min(layout.y + normalizedResizeDelta.y, previousFarY - 60f);
layout = newLayout;
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"}));
}
MasterNode masterNode

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


m_GraphInspectorView = new GraphInspectorView(assetName, previewManager, graph) { name = "inspector" };
m_GraphInspectorView.AddManipulator(new Draggable(OnMouseDrag, true));
m_GraphView.RegisterCallback<PostLayoutEvent>(OnPostLayout);
m_GraphView.Add(m_GraphInspectorView);
m_GraphView.graphViewChanged = GraphViewChanged;

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


padding-bottom: 4;
}
GraphInspectorView > #resize-right {
cursor: resize-horizontal;
GraphInspectorView > .resize {
width: 10;
position-right: 0;
position-top: 0;
position-bottom: 0;
}
GraphInspectorView > .resize.vertical {
cursor: resize-vertical;
height: 10;
position-left: 10;
position-right: 10;
padding-top: 0;
padding-bottom: 0;
margin-top: 0;
margin-bottom: 0;
GraphInspectorView > #resize-left {
GraphInspectorView > .resize.horizontal {
background-color: rgba(0, 0, 0, 0);
position-type: absolute;
position-left: 0;
position-top: 0;
position-bottom: 0;
position-top: 10;
position-bottom: 10;
padding-right: 0;
margin-right: 0;
GraphInspectorView > #resize-top {
cursor: resize-vertical;
background-color: rgba(0, 0, 0, 0);
position-type: absolute;
GraphInspectorView > .resize.diagonal {
width: 10;
}
GraphInspectorView > .resize.diagonal.top-left {
cursor: resize-up-left;
position-top: 0;
position-right: 0;
}
GraphInspectorView > .resize.diagonal.top-right {
cursor: resize-up-right;
padding-top: 0;
margin-top: 0;
position-right: 0;
GraphInspectorView > #resize-bottom {
cursor: resize-vertical;
background-color: rgba(0, 0, 0, 0);
position-type: absolute;
height: 10;
GraphInspectorView > .resize.diagonal.bottom-left {
cursor: resize-up-right;
position-bottom: 0;
}
GraphInspectorView > .resize.diagonal.bottom-right {
cursor: resize-up-left;
position-bottom: 0;
}
GraphInspectorView > .resize.vertical.top {
position-top: 0;
}
GraphInspectorView > .resize.vertical.bottom {
}
GraphInspectorView > .resize.horzontal.left {
position-left: 0;
}
GraphInspectorView > .resize.horizontal.right {
position-right: 0;
}
ShaderPropertyView {

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


using System;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing
{
enum ResizeDirection
{
Any,
Vertical,
Horizontal
}
public enum ResizeHandleAnchor
{
Top,
TopRight,
Right,
BottomRight,
Bottom,
BottomLeft,
Left,
TopLeft
}
public class ResizeSideHandle : VisualElement
{
VisualElement m_ResizeTarget;
ResizeHandleAnchor m_HandleAnchor;
public ResizeSideHandle(VisualElement resizeTarget, ResizeHandleAnchor anchor, string[] styleClasses)
{
m_ResizeTarget = resizeTarget;
foreach (string styleClass in styleClasses)
{
AddToClassList(styleClass);
}
m_HandleAnchor = anchor;
ResizeDirection resizeDirection;
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.Horizontal;
}
else if (anchor == ResizeHandleAnchor.Top || anchor == ResizeHandleAnchor.Bottom)
{
resizeDirection = ResizeDirection.Vertical;
}
else
{
resizeDirection = ResizeDirection.Any;
}
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResizeHorizontal, moveWhileResizeVertical)));
}
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizerVertical)
{
Vector2 normalizedResizeDelta = resizeDelta / 2f;
if (direction == ResizeDirection.Vertical)
{
normalizedResizeDelta.x = 0f;
}
else if (direction == ResizeDirection.Horizontal)
{
normalizedResizeDelta.y = 0f;
}
Rect newLayout = m_ResizeTarget.layout;
// Resize form bottom/right
if (!moveWhileResizeHorizontal)
{
newLayout.width = Mathf.Max(newLayout.width + normalizedResizeDelta.x, 60f);
normalizedResizeDelta.x = 0f;
Debug.Log("Not moving horizontally");
}
if (!moveWhileresizerVertical)
{
newLayout.height = Mathf.Max(newLayout.height + normalizedResizeDelta.y, 60f);
normalizedResizeDelta.y = 0f;
Debug.Log("Not moving vertically");
}
float previousFarX = m_ResizeTarget.layout.x + m_ResizeTarget.layout.width;
float previousFarY = m_ResizeTarget.layout.y + m_ResizeTarget.layout.height;
newLayout.width = Mathf.Max(newLayout.width - normalizedResizeDelta.x, 60f);
newLayout.height = Mathf.Max(newLayout.height - normalizedResizeDelta.y, 60f);
newLayout.x = Mathf.Min(newLayout.x + normalizedResizeDelta.x, previousFarX - 60f);
newLayout.y = Mathf.Min(newLayout.y + normalizedResizeDelta.y, previousFarY - 60f);
m_ResizeTarget.layout = newLayout;
}
}
}

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


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