浏览代码

Add resize handles to corner of inspector window

/main
Jens Holm 7 年前
当前提交
ff694d9c
共有 3 个文件被更改,包括 65 次插入19 次删除
  1. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  2. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  3. 37
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss

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


foreach (var property in m_Graph.properties)
m_PropertyItems.Add(new ShaderPropertyView(m_Graph, property));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.TopLeft, new string[] {"resize", "diagonal", "top-left"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.TopRight, new string[] {"resize", "diagonal", "top-right"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.BottomRight, new string[] {"resize", "diagonal", "bottom-right"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.BottomLeft, new string[] {"resize", "diagonal", "bottom-left"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.Left, new string[] {"resize", "horizontal", "left"}));
}

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


public enum ResizeHandleAnchor
{
Top,
TopRight,
BottomRight,
Left
BottomLeft,
Left,
TopLeft
}
public class ResizeSideHandle : VisualElement

ResizeDirection resizeDirection;
bool moveWhileResize = anchor == ResizeHandleAnchor.Top || anchor == ResizeHandleAnchor.Left;
bool moveWhileResizeHorizontal = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.BottomLeft || anchor == ResizeHandleAnchor.Left;
bool moveWhileResizeVertical = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.TopRight || anchor == ResizeHandleAnchor.Top;
else
else if (anchor == ResizeHandleAnchor.Top || anchor == ResizeHandleAnchor.Bottom)
else
{
resizeDirection = ResizeDirection.Any;
}
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResize)));
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResizeHorizontal, moveWhileResizeVertical)));
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResize)
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizerVertical)
{
Vector2 normalizedResizeDelta = resizeDelta / 2f;

Rect newLayout = m_ResizeTarget.layout;
// Resize form bottom/right
if (!moveWhileResize)
if (!moveWhileResizeHorizontal)
newLayout.width = Mathf.Max(m_ResizeTarget.layout.width + normalizedResizeDelta.x, 60f);
newLayout.height = Mathf.Max(m_ResizeTarget.layout.height + normalizedResizeDelta.y, 60f);
newLayout.width = Mathf.Max(newLayout.width + normalizedResizeDelta.x, 60f);
normalizedResizeDelta.x = 0f;
Debug.Log("Not moving horizontally");
}
m_ResizeTarget.layout = newLayout;
return;
if (!moveWhileresizerVertical)
{
newLayout.height = Mathf.Max(newLayout.height + normalizedResizeDelta.y, 60f);
normalizedResizeDelta.y = 0f;
Debug.Log("Not moving vertically");
newLayout.width = Mathf.Max(m_ResizeTarget.layout.width - normalizedResizeDelta.x, 60f);
newLayout.height = Mathf.Max(m_ResizeTarget.layout.height - normalizedResizeDelta.y, 60f);
newLayout.width = Mathf.Max(newLayout.width - normalizedResizeDelta.x, 60f);
newLayout.height = Mathf.Max(newLayout.height - normalizedResizeDelta.y, 60f);
newLayout.x = Mathf.Min(m_ResizeTarget.layout.x + normalizedResizeDelta.x, previousFarX - 60f);
newLayout.y = Mathf.Min(m_ResizeTarget.layout.y + normalizedResizeDelta.y, previousFarY - 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;
}

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


GraphInspectorView > .resize.vertical {
cursor: resize-vertical;
height: 10;
position-left: 0;
position-right: 0;
position-left: 10;
position-right: 10;
padding-top: 0;
padding-bottom: 0;
margin-top: 0;

GraphInspectorView > .resize.horizontal {
cursor: resize-horizontal;
width: 10;
position-top: 0;
position-bottom: 0;
position-top: 10;
position-bottom: 10;
}
GraphInspectorView > .resize.diagonal {
width: 10;
height: 10;
}
GraphInspectorView > .resize.diagonal.top-left {
cursor: resize-up-left;
position-top: 0;
position-left: 0;
}
GraphInspectorView > .resize.diagonal.top-right {
cursor: resize-up-right;
position-top: 0;
position-right: 0;
}
GraphInspectorView > .resize.diagonal.bottom-left {
cursor: resize-up-right;
position-bottom: 0;
position-left: 0;
}
GraphInspectorView > .resize.diagonal.bottom-right {
cursor: resize-up-left;
position-bottom: 0;
position-right: 0;
}
GraphInspectorView > .resize.vertical.top {

正在加载...
取消
保存