浏览代码

Make resize side handle determine own uss classes

/main
Jens Holm 7 年前
当前提交
11b8912f
共有 2 个文件被更改,包括 69 次插入19 次删除
  1. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  2. 79
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs

9
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.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"}));
ResizeSideHandle.AddResizeHandleBorderFrame(this);
}
MasterNode masterNode

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


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

public class ResizeSideHandle : VisualElement
{
VisualElement m_ResizeTarget;
public static void AddResizeHandleBorderFrame(VisualElement targetElement)
{
targetElement.Add(new ResizeSideHandle(targetElement, ResizeHandleAnchor.TopLeft));
targetElement.Add(new ResizeSideHandle(targetElement, ResizeHandleAnchor.Top));
targetElement.Add(new ResizeSideHandle(targetElement, ResizeHandleAnchor.TopRight));
targetElement.Add(new ResizeSideHandle(targetElement, ResizeHandleAnchor.Right));
targetElement.Add(new ResizeSideHandle(targetElement, ResizeHandleAnchor.BottomRight));
targetElement.Add(new ResizeSideHandle(targetElement, ResizeHandleAnchor.Bottom));
targetElement.Add(new ResizeSideHandle(targetElement, ResizeHandleAnchor.BottomLeft));
targetElement.Add(new ResizeSideHandle(targetElement, ResizeHandleAnchor.Left));
}
ResizeHandleAnchor m_HandleAnchor;
VisualElement m_ResizeTarget;
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("vertical");
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;
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResizeHorizontal, moveWhileResizeVertical)));
}

正在加载...
取消
保存