浏览代码

Merge with master

/main
Peter Bay Bastian 7 年前
当前提交
6d5e2c25
共有 4 个文件被更改,包括 418 次插入45 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardProvider.cs
  2. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs
  3. 441
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  4. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardProvider.cs


blackboard.AddManipulator(m_WindowDraggable);
m_ResizeBorderFrame = new ResizeBorderFrame(blackboard) { name = "resizeBorderFrame" };
m_ResizeBorderFrame.stayWithinParentBounds = true;
blackboard.shadow.Add(m_ResizeBorderFrame);
m_Section = new BlackboardSection { headerVisible = false };

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs


return image;
}
void OnScroll(float scrollValue)
{
float rescaleAmount = -scrollValue * .03f;
m_Graph.previewData.scale = Mathf.Clamp(m_Graph.previewData.scale + rescaleAmount, 0.2f, 5f);
}
void BuildContextualMenu(ContextualMenuPopulateEvent evt)
{
foreach (var primitiveTypeName in Enum.GetNames(typeof(PrimitiveType)))

{
UnregisterCallback<PostLayoutEvent>(AdaptRenderTextureOnLayoutChange);
RefreshRenderTextureSize();
}
void OnScroll(float scrollValue)
{
float rescaleAmount = -scrollValue * .03f;
m_Graph.previewData.scale = Mathf.Clamp(m_Graph.previewData.scale + rescaleAmount, 0.2f, 5f);
DirtyMasterNode(ModificationScope.Node);
}
void OnMouseDragPreviewMesh(Vector2 deltaMouse)

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


using System;
using System.Collections.Generic;
using System.Xml;
using UnityEngine.EventSystems;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing

public Action OnResizeFinished;
bool m_DockingLeft;
bool m_DockingTop;
bool m_Dragging;
float m_InitialAspectRatio;
Rect m_ResizeBeginLayout;
Vector2 m_ResizeBeginMousePosition;
public ResizeSideHandle(VisualElement resizeTarget, ResizeHandleAnchor anchor)
{
m_ResizeTarget = resizeTarget;

{
AddToClassList("vertical");
AddToClassList("top");
RegisterCallback<MouseMoveEvent>(HandleResizeFromTop);
break;
}
case ResizeHandleAnchor.TopRight:

RegisterCallback<MouseMoveEvent>(HandleResizeFromTopRight);
break;
}
case ResizeHandleAnchor.Right:

RegisterCallback<MouseMoveEvent>(HandleResizeFromRight);
break;
}
case ResizeHandleAnchor.BottomRight:

RegisterCallback<MouseMoveEvent>(HandleResizeFromBottomRight);
break;
}
case ResizeHandleAnchor.Bottom:

RegisterCallback<MouseMoveEvent>(HandleResizeFromBottom);
break;
}
case ResizeHandleAnchor.BottomLeft:

RegisterCallback<MouseMoveEvent>(HandleResizeFromBottomLeft);
break;
}
case ResizeHandleAnchor.Left:

RegisterCallback<MouseMoveEvent>(HandleResizeFromLeft);
break;
}
case ResizeHandleAnchor.TopLeft:

RegisterCallback<MouseMoveEvent>(HandleResizeFromTopLeft);
ResizeDirection resizeDirection;
RegisterCallback<MouseDownEvent>(HandleMouseDown);
RegisterCallback<MouseUpEvent>(HandleDraggableMouseUp);
m_ResizeTarget.RegisterCallback<PostLayoutEvent>(InitialLayoutSetup);
}
void InitialLayoutSetup(PostLayoutEvent evt)
{
m_ResizeTarget.UnregisterCallback<PostLayoutEvent>(InitialLayoutSetup);
m_InitialAspectRatio = m_ResizeTarget.layout.width / m_ResizeTarget.layout.height;
}
Vector2 GetMinSize()
{
Vector2 minSize = new Vector2(60f, 60f);
if (!Mathf.Approximately(m_ResizeTarget.style.minWidth.value, 0f))
{
minSize.x = m_ResizeTarget.style.minWidth;
}
if (!Mathf.Approximately(m_ResizeTarget.style.minHeight.value, 0f))
{
minSize.y = m_ResizeTarget.style.minHeight.value;
}
return minSize;
}
float GetMaxHorizontalExpansion(bool expandingLeft)
{
float maxHorizontalExpansion;
if (expandingLeft)
{
maxHorizontalExpansion = m_ResizeBeginLayout.x;
}
else
{
maxHorizontalExpansion = m_ResizeTarget.parent.layout.width - m_ResizeBeginLayout.xMax;
}
if (anchor == ResizeHandleAnchor.Left || anchor == ResizeHandleAnchor.Right)
if (maintainAspectRatio)
resizeDirection = ResizeDirection.Horizontal;
if (!m_DockingTop)
{
maxHorizontalExpansion = Mathf.Min(maxHorizontalExpansion, m_ResizeBeginLayout.y);
}
else
{
maxHorizontalExpansion = Mathf.Min(maxHorizontalExpansion, m_ResizeTarget.parent.layout.height - m_ResizeBeginLayout.yMax);
}
else if (anchor == ResizeHandleAnchor.Top || anchor == ResizeHandleAnchor.Bottom)
return maxHorizontalExpansion;
}
float GetMaxVerticalExpansion(bool expandingUp)
{
float maxVerticalExpansion;
if (expandingUp)
resizeDirection = ResizeDirection.Vertical;
maxVerticalExpansion = m_ResizeBeginLayout.y;
resizeDirection = ResizeDirection.Any;
maxVerticalExpansion = m_ResizeTarget.parent.layout.height - m_ResizeBeginLayout.yMax;
}
if (maintainAspectRatio)
{
if (!m_DockingLeft)
{
maxVerticalExpansion = Mathf.Min(maxVerticalExpansion, m_ResizeBeginLayout.x);
}
else
{
maxVerticalExpansion = Mathf.Min(maxVerticalExpansion, m_ResizeTarget.parent.layout.width - m_ResizeBeginLayout.xMax);
}
}
return maxVerticalExpansion;
}
void HandleResizeFromTop(MouseMoveEvent mouseMoveEvent)
{
if (!m_Dragging)
{
return;
}
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginLayout.yMax - GetMinSize().y);
if (stayWithinParentBounds)
{
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, m_ResizeBeginMousePosition.y - GetMaxVerticalExpansion(true));
}
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.yMin = m_ResizeBeginLayout.yMin + delta.y;
if (maintainAspectRatio)
{
if (m_DockingLeft)
{
newLayout.width = newLayout.height * m_InitialAspectRatio;
}
else
{
newLayout.xMin = newLayout.xMax - (newLayout.height * m_InitialAspectRatio);
}
}
m_ResizeTarget.layout = newLayout;
mouseMoveEvent.StopPropagation();
}
void HandleResizeFromTopRight(MouseMoveEvent mouseMoveEvent)
{
if (!m_Dragging)
{
return;
}
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, m_ResizeBeginLayout.xMin + GetMinSize().x);
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginLayout.yMax - GetMinSize().y);
if (stayWithinParentBounds)
{
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginMousePosition.x + GetMaxHorizontalExpansion(false));
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, 0f);
}
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.width += delta.x;
newLayout.yMin += delta.y;
if (maintainAspectRatio)
{
if (newLayout.width < newLayout.height * m_InitialAspectRatio)
{
newLayout.yMin = Mathf.Min(newLayout.yMax - newLayout.width / m_InitialAspectRatio, newLayout.yMax - GetMinSize().y);
}
else
{
newLayout.width = newLayout.height * m_InitialAspectRatio;
}
}
m_ResizeTarget.layout = newLayout;
mouseMoveEvent.StopPropagation();
}
void HandleResizeFromRight(MouseMoveEvent mouseMoveEvent)
{
if (!m_Dragging)
{
return;
}
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, m_ResizeBeginLayout.xMin + GetMinSize().x);
if (stayWithinParentBounds)
{
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginMousePosition.x + GetMaxHorizontalExpansion(false));
}
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.xMax = m_ResizeBeginLayout.xMax + delta.x;
if (maintainAspectRatio)
{
if (m_DockingTop)
{
newLayout.height = newLayout.width / m_InitialAspectRatio;
}
else
{
newLayout.yMin = newLayout.yMax - (newLayout.width / m_InitialAspectRatio);
}
}
m_ResizeTarget.layout = newLayout;
mouseMoveEvent.StopPropagation();
}
void HandleResizeFromBottomRight(MouseMoveEvent mouseMoveEvent)
{
if (!m_Dragging)
{
return;
}
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, m_ResizeBeginLayout.xMin + GetMinSize().x);
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, m_ResizeBeginLayout.yMin + GetMinSize().y);
if (stayWithinParentBounds)
{
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginMousePosition.x + GetMaxHorizontalExpansion(false));
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginMousePosition.y + GetMaxVerticalExpansion(false));
}
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.size += delta;
if (maintainAspectRatio)
{
if (newLayout.width < newLayout.height * m_InitialAspectRatio)
{
newLayout.height = newLayout.width / m_InitialAspectRatio;
}
else
{
newLayout.width = newLayout.height * m_InitialAspectRatio;
}
bool moveWhileResizeHorizontal = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.BottomLeft || anchor == ResizeHandleAnchor.Left;
bool moveWhileResizeVertical = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.TopRight || anchor == ResizeHandleAnchor.Top;
m_ResizeTarget.layout = newLayout;
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResizeHorizontal, moveWhileResizeVertical, anchor)));
RegisterCallback<MouseUpEvent>(HandleDraggableMouseUp);
mouseMoveEvent.StopPropagation();
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizeVertical, ResizeHandleAnchor anchor)
void HandleResizeFromBottom(MouseMoveEvent mouseMoveEvent)
Vector2 normalizedResizeDelta = resizeDelta / 2f;
if (!m_Dragging)
{
return;
}
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
Vector2 minSize = new Vector2(60f, 60f);
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, m_ResizeBeginLayout.yMin + GetMinSize().y);
if (!Mathf.Approximately(m_ResizeTarget.style.minWidth.value, 0f))
if (stayWithinParentBounds)
minSize.x = m_ResizeTarget.style.minWidth;
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginMousePosition.y + GetMaxVerticalExpansion(false));
if (!Mathf.Approximately(m_ResizeTarget.style.minHeight.value, 0f))
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.yMax = m_ResizeBeginLayout.yMax + delta.y;
if (maintainAspectRatio)
minSize.y = m_ResizeTarget.style.minHeight.value;
if (m_DockingLeft)
{
newLayout.width = newLayout.height * m_InitialAspectRatio;
}
else
{
newLayout.xMin = newLayout.xMax - (newLayout.height * m_InitialAspectRatio);
}
if (direction == ResizeDirection.Vertical)
m_ResizeTarget.layout = newLayout;
mouseMoveEvent.StopPropagation();
}
void HandleResizeFromBottomLeft(MouseMoveEvent mouseMoveEvent)
{
if (!m_Dragging)
normalizedResizeDelta.x = 0f;
return;
else if (direction == ResizeDirection.Horizontal)
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginLayout.xMax - GetMinSize().x);
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, m_ResizeBeginLayout.yMin + GetMinSize().y);
if (stayWithinParentBounds)
normalizedResizeDelta.y = 0f;
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, 0f);
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginMousePosition.y + GetMaxVerticalExpansion(false));
Rect newLayout = m_ResizeTarget.layout;
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.xMin += delta.x;
newLayout.height += delta.y;
if (anchor == ResizeHandleAnchor.Left || anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.BottomLeft)
if (maintainAspectRatio)
newLayout.xMin = Mathf.Min(newLayout.xMin + normalizedResizeDelta.x, newLayout.xMax - minSize.x);
if (newLayout.width < newLayout.height * m_InitialAspectRatio)
{
newLayout.height = newLayout.width / m_InitialAspectRatio;
}
else
{
newLayout.xMin = Mathf.Min(newLayout.xMax - newLayout.height * m_InitialAspectRatio, newLayout.xMax - GetMinSize().x);
}
else
m_ResizeTarget.layout = newLayout;
mouseMoveEvent.StopPropagation();
}
void HandleResizeFromLeft(MouseMoveEvent mouseMoveEvent)
{
if (!m_Dragging)
newLayout.xMax = Mathf.Max(newLayout.xMax + normalizedResizeDelta.x, newLayout.xMin + minSize.x);
return;
if (anchor == ResizeHandleAnchor.Top || anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.TopRight)
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginLayout.xMax - GetMinSize().x);
if (stayWithinParentBounds)
{
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, m_ResizeBeginMousePosition.x - GetMaxHorizontalExpansion(true));
}
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.xMin = m_ResizeBeginLayout.xMin + delta.x;
if (maintainAspectRatio)
newLayout.yMin = Mathf.Min(newLayout.yMin + normalizedResizeDelta.y, newLayout.yMax - minSize.y);
if (m_DockingTop)
{
newLayout.height = newLayout.width / m_InitialAspectRatio;
}
else
{
newLayout.yMin = newLayout.yMax - (newLayout.width / m_InitialAspectRatio);
}
else
m_ResizeTarget.layout = newLayout;
mouseMoveEvent.StopPropagation();
}
void HandleResizeFromTopLeft(MouseMoveEvent mouseMoveEvent)
{
if (!m_Dragging)
newLayout.yMax = Mathf.Max(newLayout.yMax + normalizedResizeDelta.y, newLayout.yMin + minSize.y);
return;
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginLayout.xMax - GetMinSize().x);
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginLayout.yMax - GetMinSize().y);
newLayout.xMin = Mathf.Max(newLayout.xMin, 0f);
newLayout.yMin = Mathf.Max(newLayout.yMin, 0f);
newLayout.xMax = Mathf.Min(newLayout.xMax, m_ResizeTarget.parent.layout.width);
newLayout.yMax = Mathf.Min(newLayout.yMax, m_ResizeTarget.parent.layout.height);
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, 0f);
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, 0f);
}
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.xMin += delta.x;
newLayout.yMin += delta.y;
if (maintainAspectRatio)
{
if (newLayout.width < newLayout.height * m_InitialAspectRatio)
{
newLayout.yMin = Mathf.Min(newLayout.yMax - newLayout.width / m_InitialAspectRatio, newLayout.yMax - GetMinSize().y);
}
else
{
newLayout.xMin = Mathf.Min(newLayout.xMax - newLayout.height * m_InitialAspectRatio, newLayout.xMax - GetMinSize().x);
}
mouseMoveEvent.StopPropagation();
void HandleDraggableMouseUp(MouseUpEvent evt)
void HandleMouseDown(MouseDownEvent mouseDownEvent)
{
m_Dragging = true;
m_DockingLeft = m_ResizeTarget.layout.center.x / m_ResizeTarget.parent.layout.width < .5f;
m_DockingTop = m_ResizeTarget.layout.center.y / m_ResizeTarget.parent.layout.height < .5f;
m_ResizeBeginLayout = m_ResizeTarget.layout;
m_ResizeBeginMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseDownEvent.mousePosition);
m_Dragging = true;
this.TakeMouseCapture();
mouseDownEvent.StopPropagation();
}
void HandleDraggableMouseUp(MouseUpEvent mouseUpEvent)
m_Dragging = false;
if (this.HasMouseCapture())
{
this.ReleaseMouseCapture();
}
if (OnResizeFinished != null)
{
OnResizeFinished();

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs


}
}
void OnMouseUp(MouseUpEvent evt)
{
bool emitDragFinishedEvent = m_Active;

}
else
{
windowRect.y = (1f - normalizedDistanceFromEdge.y) * target.parent.layout.height- windowRect.height;
windowRect.y = (1f - normalizedDistanceFromEdge.y) * target.parent.layout.height - windowRect.height;
windowRect.width = Mathf.Max(Mathf.Min(windowRect.width, target.parent.layout.width), minSize.x);
windowRect.height = Mathf.Max(Mathf.Min(windowRect.height, target.parent.layout.height), minSize.y);
windowRect.width = Mathf.Max(windowRect.width, minSize.x);
windowRect.height = Mathf.Max(windowRect.height, minSize.y);
float maximumXPosition = Mathf.Max(target.parent.layout.width - windowRect.width, 0f);
float maximumYPosition = Mathf.Max(target.parent.layout.height - windowRect.height, 0f);

正在加载...
取消
保存