浏览代码

Add callback in resize handles that notifies when the mouse button is released

/main
Jens Holm 7 年前
当前提交
602ef408
共有 2 个文件被更改,包括 51 次插入10 次删除
  1. 47
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs
  2. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs

47
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs


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

public class ResizeBorderFrame : VisualElement
{
public Action OnResizeFinished;
public ResizeBorderFrame(VisualElement target)
{
pickingMode = PickingMode.Ignore;

Add(new ResizeSideHandle(target, ResizeHandleAnchor.TopLeft));
Add(new ResizeSideHandle(target, ResizeHandleAnchor.Top));
Add(new ResizeSideHandle(target, ResizeHandleAnchor.TopRight));
Add(new ResizeSideHandle(target, ResizeHandleAnchor.Right));
Add(new ResizeSideHandle(target, ResizeHandleAnchor.BottomRight));
Add(new ResizeSideHandle(target, ResizeHandleAnchor.Bottom));
Add(new ResizeSideHandle(target, ResizeHandleAnchor.BottomLeft));
Add(new ResizeSideHandle(target, ResizeHandleAnchor.Left));
ResizeSideHandle topLeft = new ResizeSideHandle(target, ResizeHandleAnchor.TopLeft);
ResizeSideHandle top = new ResizeSideHandle(target, ResizeHandleAnchor.Top);
ResizeSideHandle topRight = new ResizeSideHandle(target, ResizeHandleAnchor.TopRight);
ResizeSideHandle right = new ResizeSideHandle(target, ResizeHandleAnchor.Right);
ResizeSideHandle bottomRight = new ResizeSideHandle(target, ResizeHandleAnchor.BottomRight);
ResizeSideHandle bottom = new ResizeSideHandle(target, ResizeHandleAnchor.Bottom);
ResizeSideHandle bottomLeft = new ResizeSideHandle(target, ResizeHandleAnchor.BottomLeft);
ResizeSideHandle left = new ResizeSideHandle(target, ResizeHandleAnchor.Left);
topLeft.OnResizeFinished += HandleResizefinished;
top.OnResizeFinished += HandleResizefinished;
topRight.OnResizeFinished += HandleResizefinished;
right.OnResizeFinished += HandleResizefinished;
bottomRight.OnResizeFinished += HandleResizefinished;
bottom.OnResizeFinished += HandleResizefinished;
bottomLeft.OnResizeFinished += HandleResizefinished;
left.OnResizeFinished += HandleResizefinished;
Add(topLeft);
Add(top);
Add(topRight);
Add(right);
Add(bottomRight);
Add(bottom);
Add(bottomLeft);
Add(left);
}
void HandleResizefinished()
{
if (OnResizeFinished != null)
{
OnResizeFinished();
}
}
}

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


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

{
VisualElement m_ResizeTarget;
public Action OnResizeFinished;
public ResizeSideHandle(VisualElement resizeTarget, ResizeHandleAnchor anchor)
{
m_ResizeTarget = resizeTarget;

bool moveWhileResizeVertical = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.TopRight || anchor == ResizeHandleAnchor.Top;
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResizeHorizontal, moveWhileResizeVertical)));
RegisterCallback<MouseUpEvent>(HandleDraggableMouseUp);
}
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizerVertical)

newLayout.y = Mathf.Min(newLayout.y + normalizedResizeDelta.y, previousFarY - minSize.y);
m_ResizeTarget.layout = newLayout;
}
void HandleDraggableMouseUp(MouseUpEvent evt)
{
if (OnResizeFinished != null)
{
OnResizeFinished();
}
}
}
}
正在加载...
取消
保存