浏览代码

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

/main
Jens Holm 7 年前
当前提交
e72aef5a
共有 4 个文件被更改,包括 131 次插入46 次删除
  1. 26
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  2. 47
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  3. 93
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  4. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs.meta

26
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);
Add(new ResizeSideHandle(this, ResizeHandleAnchor.Top, new string[] {"resize", "vertical", "top"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.Right, new string[] {"resize", "horizontal", "right"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.Bottom, new string[] {"resize", "vertical", "bottom"}));
Add(new ResizeSideHandle(this, ResizeHandleAnchor.Left, new string[] {"resize", "horizontal", "left"}));
// Nodes missing custom editors:
// - PropertyNode

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


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

93
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,
Right,
Bottom,
Left
}
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 moveWhileResize = anchor == ResizeHandleAnchor.Top || anchor == ResizeHandleAnchor.Left;
if (anchor == ResizeHandleAnchor.Left || anchor == ResizeHandleAnchor.Right)
{
resizeDirection = ResizeDirection.Horizontal;
}
else
{
resizeDirection = ResizeDirection.Vertical;
}
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResize)));
}
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 = m_ResizeTarget.layout;
// Resize form bottom/right
if (!moveWhileResize)
{
newLayout.width = Mathf.Max(m_ResizeTarget.layout.width + normalizedResizeDelta.x, 60f);
newLayout.height = Mathf.Max(m_ResizeTarget.layout.height + normalizedResizeDelta.y, 60f);
m_ResizeTarget.layout = newLayout;
return;
}
float previousFarX = m_ResizeTarget.layout.x + m_ResizeTarget.layout.width;
float previousFarY = m_ResizeTarget.layout.y + m_ResizeTarget.layout.height;
newLayout.width = Mathf.Max(m_ResizeTarget.layout.width - normalizedResizeDelta.x, 60f);
newLayout.height = Mathf.Max(m_ResizeTarget.layout.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);
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:
正在加载...
取消
保存