浏览代码

Merge branch 'master' into path-for-shaders

/main
Peter Bay Bastian 7 年前
当前提交
9cc55c03
共有 17 个文件被更改,包括 548 次插入468 次删除
  1. 25
      com.unity.shadergraph/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 1
      com.unity.shadergraph/Editor/Data/Graphs/Vector4MaterialSlot.cs
  3. 10
      com.unity.shadergraph/Editor/Data/SubGraph/SubGraphOutputNode.cs
  4. 15
      com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs
  5. 4
      com.unity.shadergraph/Editor/Drawing/Blackboard/Blackboard.cs
  6. 45
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs
  7. 144
      com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs
  8. 39
      com.unity.shadergraph/Editor/Drawing/Inspector/WindowDockingLayout.cs
  9. 46
      com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeBorderFrame.cs
  10. 412
      com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  11. 147
      com.unity.shadergraph/Editor/Drawing/Manipulators/WindowDraggable.cs
  12. 5
      com.unity.shadergraph/Editor/Drawing/PreviewManager.cs
  13. 69
      com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs
  14. 1
      com.unity.shadergraph/Editor/Resources/Styles/Blackboard.uss
  15. 2
      com.unity.shadergraph/Editor/Resources/Styles/Controls/EnumControlView.uss
  16. 4
      com.unity.shadergraph/Editor/Resources/Styles/GraphEditorView.uss
  17. 47
      com.unity.shadergraph/Editor/Resources/Styles/MasterPreviewView.uss

25
com.unity.shadergraph/Editor/Data/Graphs/AbstractMaterialGraph.cs


if (m_Properties.Contains(property))
return;
property.displayName = property.displayName.Trim();
if (m_Properties.Any(p => p.displayName == property.displayName))
m_Properties.Add(property);
m_AddedProperties.Add(property);
}
public string SanitizePropertyName(string displayName, Guid guid = default(Guid))
{
displayName = displayName.Trim();
if (m_Properties.Any(p => p.displayName == displayName && p.guid != guid))
var regex = new Regex(@"^" + Regex.Escape(property.displayName) + @" \((\d+)\)$");
var existingDuplicateNumbers = m_Properties.Select(p => regex.Match(p.displayName)).Where(m => m.Success).Select(m => int.Parse(m.Groups[1].Value)).Where(n => n > 0).ToList();
// Strip out the " (n)" part of the name.
var baseRegex = new Regex(@"^(.*) \((\d+)\)$");
var baseMatch = baseRegex.Match(displayName);
if (baseMatch.Success)
displayName = baseMatch.Groups[1].Value;
var regex = new Regex(@"^" + Regex.Escape(displayName) + @" \((\d+)\)$");
var existingDuplicateNumbers = m_Properties.Where(p => p.guid != guid).Select(p => regex.Match(p.displayName)).Where(m => m.Success).Select(m => int.Parse(m.Groups[1].Value)).Where(n => n > 0).Distinct().ToList();
var duplicateNumber = 1;
existingDuplicateNumbers.Sort();

}
}
}
property.displayName = string.Format("{0} ({1})", property.displayName, duplicateNumber);
displayName = string.Format("{0} ({1})", displayName, duplicateNumber);
m_Properties.Add(property);
m_AddedProperties.Add(property);
return displayName;
}
public void RemoveShaderProperty(Guid guid)

1
com.unity.shadergraph/Editor/Data/Graphs/Vector4MaterialSlot.cs


public Vector4MaterialSlot()
{
m_Labels = new[] { "X", "Y", "Z", "W" };
}
public Vector4MaterialSlot(

10
com.unity.shadergraph/Editor/Data/SubGraph/SubGraphOutputNode.cs


name = "SubGraphOutputs";
}
public override bool hasPreview
{
get { return true; }
}
public override PreviewMode previewMode
{
get { return PreviewMode.Preview3D; }
}
public virtual int AddSlot()
{
var index = this.GetInputSlots<ISlot>().Count() + 1;

15
com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs


var slots = new List<MaterialSlot>();
foreach (var activeNode in isUber ? activeNodeList.Where(n => ((AbstractMaterialNode)n).hasPreview) : ((INode)node).ToEnumerable())
{
if (activeNode is IMasterNode)
if (activeNode is IMasterNode || activeNode is SubGraphOutputNode)
slots.AddRange(activeNode.GetInputSlots<MaterialSlot>());
else
slots.AddRange(activeNode.GetOutputSlots<MaterialSlot>());

var outputSlot = activeNode.GetOutputSlots<MaterialSlot>().FirstOrDefault();
if (outputSlot != null)
surfaceDescriptionFunction.AddShaderChunk(String.Format("if ({0} == {1}) {{ surface.PreviewOutput = {2}; return surface; }}", outputIdProperty.referenceName, activeNode.tempId.index, ShaderGenerator.AdaptNodeOutputForPreview(activeNode, outputSlot.id, activeNode.GetVariableNameForSlot(outputSlot.id))), false);
}
// In case of the subgraph output node, the preview is generated
// from the first input to the node.
if (activeNode is SubGraphOutputNode)
{
var inputSlot = activeNode.GetInputSlots<MaterialSlot>().FirstOrDefault();
if (inputSlot != null)
{
var foundEdges = graph.GetEdges(inputSlot.slotReference).ToArray();
string slotValue = foundEdges.Any() ? activeNode.GetSlotValue(inputSlot.id, mode) : inputSlot.GetDefaultValue(mode);
surfaceDescriptionFunction.AddShaderChunk(String.Format("if ({0} == {1}) {{ surface.PreviewOutput = {2}; return surface; }}", outputIdProperty.referenceName, activeNode.tempId.index, slotValue), false);
}
}
activeNode.CollectShaderProperties(shaderProperties, mode);

4
com.unity.shadergraph/Editor/Drawing/Blackboard/Blackboard.cs


ClearClassList();
AddToClassList("sgblackboard");
// this.AddManipulator(new Dragger { clampToParentEdges = true });
this.AddManipulator(new Dragger { clampToParentEdges = true });
// shadow.Add(new Resizer());
shadow.Add(new Resizer());
}
}
}

45
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs


readonly Texture2D m_ExposedIcon;
readonly Dictionary<Guid, BlackboardRow> m_PropertyRows;
readonly BlackboardSection m_Section;
WindowDraggable m_WindowDraggable;
ResizeBorderFrame m_ResizeBorderFrame;
//WindowDraggable m_WindowDraggable;
//ResizeBorderFrame m_ResizeBorderFrame;
public Action onDragFinished
{
get { return m_WindowDraggable.OnDragFinished; }
set { m_WindowDraggable.OnDragFinished = value; }
}
//public Action onDragFinished
//{
// get { return m_WindowDraggable.OnDragFinished; }
// set { m_WindowDraggable.OnDragFinished = value; }
//}
public Action onResizeFinished
{
get { return m_ResizeBorderFrame.OnResizeFinished; }
set { m_ResizeBorderFrame.OnResizeFinished = value; }
}
//public Action onResizeFinished
//{
// get { return m_ResizeBorderFrame.OnResizeFinished; }
// set { m_ResizeBorderFrame.OnResizeFinished = value; }
//}
public BlackboardProvider(string assetName, AbstractMaterialGraph graph)
{

m_PathLabelTextField.RegisterCallback<KeyDownEvent>(OnPathTextFieldKeyPressed);
blackboard.shadow.Add(m_PathLabelTextField);
m_WindowDraggable = new WindowDraggable(blackboard.shadow.Children().First().Q("header"));
blackboard.AddManipulator(m_WindowDraggable);
// m_WindowDraggable = new WindowDraggable(blackboard.shadow.Children().First().Q("header"));
// blackboard.AddManipulator(m_WindowDraggable);
m_ResizeBorderFrame = new ResizeBorderFrame(blackboard) { name = "resizeBorderFrame" };
m_ResizeBorderFrame.stayWithinParentBounds = true;
blackboard.shadow.Add(m_ResizeBorderFrame);
// m_ResizeBorderFrame = new ResizeBorderFrame(blackboard) { name = "resizeBorderFrame" };
// blackboard.shadow.Add(m_ResizeBorderFrame);
m_Section = new BlackboardSection { headerVisible = false };
foreach (var property in graph.properties)

{
var field = (BlackboardField)visualElement;
var property = (IShaderProperty)field.userData;
if (newText != property.displayName)
if (!string.IsNullOrEmpty(newText) && newText != property.displayName)
newText = m_Graph.SanitizePropertyName(newText, property.guid);
public void HandleGraphChanges()
{

{
if (m_PropertyRows.ContainsKey(property.guid))
return;
if (create)
property.displayName = m_Graph.SanitizePropertyName(property.displayName);
var field = new BlackboardField(m_ExposedIcon, property.displayName, property.propertyType.ToString()) { userData = property };
var row = new BlackboardRow(field, new BlackboardFieldPropertyView(m_Graph, property));
row.userData = property;

if (create)
{
field.OpenTextEditor();
field.OpenTextEditor();
}
}

144
com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs


PreviewRenderData m_PreviewRenderHandle;
Image m_PreviewTextureView;
public Image previewTextureView
{
get { return m_PreviewTextureView; }
}
Vector2 m_PreviewScrollPosition;
ObjectField m_PreviewMeshPicker;

bool m_Expanded = true;
public bool expanded
{
get { return m_Expanded;}
}
bool m_RecalculateLayout;
Vector2 m_ExpandedPreviewSize;
VisualElement m_CollapsePreviewContainer;
VisualElement m_CollapsePreviewButton;
ResizeBorderFrame m_PreviewResizeBorderFrame;
public ResizeBorderFrame previewResizeBorderFrame
{
get { return m_PreviewResizeBorderFrame; }
}
VisualElement m_Preview;
public VisualElement preview
{
get { return m_Preview; }
}
List<string> m_DoNotShowPrimitives = new List<string>( new string[] {PrimitiveType.Plane.ToString()});
static Type s_ContextualMenuManipulator = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypesOrNothing()).FirstOrDefault(t => t.FullName == "UnityEngine.Experimental.UIElements.ContextualMenuManipulator");

var topContainer = new VisualElement() { name = "top" };
{
var title = new Label(assetName.Split('/').Last()) { name = "title" };
// Add preview collapse button on top of preview
m_CollapsePreviewContainer = new VisualElement { name = "collapse-container" };
m_CollapsePreviewContainer.AddToClassList("collapse-container");
m_CollapsePreviewButton = new VisualElement { name = "icon" };
m_CollapsePreviewButton.AddToClassList("icon");
m_CollapsePreviewContainer.Add(m_CollapsePreviewButton);
m_CollapsePreviewContainer.AddManipulator(new Clickable(() =>
{
m_Graph.owner.RegisterCompleteObjectUndo("Collapse Preview");
m_Expanded ^= true;
UpdateExpandedButtonState();
UpdatePreviewVisibility();
}));
topContainer.Add(m_CollapsePreviewContainer);
var middleContainer = new VisualElement {name = "middle"};
m_Preview = new VisualElement {name = "middle"};
middleContainer.Add(m_PreviewTextureView);
middleContainer.AddManipulator(new Scrollable(OnScroll));
preview.Add(m_PreviewTextureView);
preview.AddManipulator(new Scrollable(OnScroll));
Add(middleContainer);
Add(preview);
m_PreviewResizeBorderFrame = new ResizeBorderFrame(previewTextureView, this) { name = "resizeBorderFrame" };
m_PreviewResizeBorderFrame.maintainAspectRatio = true;
Add(m_PreviewResizeBorderFrame);
m_ExpandedPreviewSize = new Vector2(256f, 256f);
m_RecalculateLayout = false;
previewTextureView.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
}
void UpdateExpandedButtonState()
{
m_CollapsePreviewButton.RemoveFromClassList(!m_Expanded ? "expanded" : "collapsed");
m_CollapsePreviewButton.AddToClassList(!m_Expanded ? "collapsed" : "expanded");
}
void UpdatePreviewVisibility()
{
if (m_Expanded)
{
RemoveFromClassList("collapsed");
AddToClassList("expanded");
m_PreviewResizeBorderFrame.visible = true;
style.positionLeft = StyleValue<float>.Create(float.NaN);
style.positionBottom = StyleValue<float>.Create(float.NaN);
style.positionRight = StyleValue<float>.Create(parent.layout.width - layout.xMax);
style.positionTop = StyleValue<float>.Create(layout.yMin);
previewTextureView.style.width = StyleValue<float>.Create(m_ExpandedPreviewSize.x);
previewTextureView.style.height = StyleValue<float>.Create(m_ExpandedPreviewSize.y);
}
else
{
m_ExpandedPreviewSize = previewTextureView.layout.size;
m_PreviewResizeBorderFrame.visible = false;
style.positionLeft = StyleValue<float>.Create(float.NaN);
style.positionBottom = StyleValue<float>.Create(float.NaN);
style.positionRight = StyleValue<float>.Create(parent.layout.width - layout.xMax);
style.positionTop = StyleValue<float>.Create(layout.yMin);
previewTextureView.style.width = StyleValue<float>.Create(0f);
previewTextureView.style.height = StyleValue<float>.Create(0f);
RemoveFromClassList("expanded");
AddToClassList("collapsed");
}
m_RecalculateLayout = true;
}
Image CreatePreview(Texture texture)

var amn = masterNode as AbstractMaterialNode;
if (amn != null)
amn.Dirty(scope);
// If currently editing a subgraph, dirty the output node rather than master node.
if (m_Graph is SubGraph)
{
var subgraph = m_Graph as SubGraph;
if (subgraph != null && subgraph.outputNode != null)
subgraph.outputNode.Dirty(scope);
}
}
void OnPreviewChanged()

ShowMethod.Invoke(Get(), new object[] { null, typeof(Mesh), null, false, null, (Action<Object>)OnMeshChanged, (Action<Object>)OnMeshChanged });
}
public void RefreshRenderTextureSize()
void OnGeometryChanged(GeometryChangedEvent evt)
if (m_RecalculateLayout)
{
WindowDockingLayout dockingLayout = new WindowDockingLayout();
dockingLayout.CalculateDockingCornerAndOffset(layout, parent.layout);
dockingLayout.ClampToParentWindow();
dockingLayout.ApplyPosition(this);
m_RecalculateLayout = false;
}
if (!expanded)
return;
var targetWidth = m_PreviewTextureView.contentRect.width;
var targetHeight = m_PreviewTextureView.contentRect.height;
var targetWidth = Mathf.Max(1f, m_PreviewTextureView.contentRect.width);
var targetHeight = Mathf.Max(1f, m_PreviewTextureView.contentRect.height);
m_PreviewManager.ResizeMasterPreview(m_PreviewTextureView.contentRect.size);
}
public void UpdateRenderTextureOnNextLayoutChange()
{
RegisterCallback<GeometryChangedEvent>(AdaptRenderTextureOnLayoutChange);
}
void AdaptRenderTextureOnLayoutChange(GeometryChangedEvent evt)
{
UnregisterCallback<GeometryChangedEvent>(AdaptRenderTextureOnLayoutChange);
RefreshRenderTextureSize();
m_PreviewManager.ResizeMasterPreview(new Vector2(targetWidth, targetHeight));
}
void OnScroll(float scrollValue)

39
com.unity.shadergraph/Editor/Drawing/Inspector/WindowDockingLayout.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleSheets;
namespace UnityEditor.ShaderGraph.Drawing
{

}
m_Size = layout.size;
}
public void ClampToParentWindow()
{
m_HorizontalOffset = Mathf.Max(0f, m_HorizontalOffset);
m_VerticalOffset = Mathf.Max(0f, m_VerticalOffset);
}
public void ApplyPosition(VisualElement target)
{
if (dockingLeft)
{
target.style.positionRight = StyleValue<float>.Create(float.NaN);
target.style.positionLeft = StyleValue<float>.Create(horizontalOffset);
}
else
{
target.style.positionLeft = StyleValue<float>.Create(float.NaN);
target.style.positionRight = StyleValue<float>.Create(horizontalOffset);
}
if (dockingTop)
{
target.style.positionBottom = StyleValue<float>.Create(float.NaN);
target.style.positionTop = StyleValue<float>.Create(verticalOffset);
}
else
{
target.style.positionTop = StyleValue<float>.Create(float.NaN);
target.style.positionBottom = StyleValue<float>.Create(verticalOffset);
}
}
public void ApplySize(VisualElement target)
{
target.style.width = StyleValue<float>.Create(size.x);
target.style.height = StyleValue<float>.Create(size.y);
}
public Rect GetLayout(Rect parentLayout)

46
com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeBorderFrame.cs


using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEditor.ShaderGraph.Drawing;
using UnityEngine.Networking;
bool m_StayWithinParentBounds;
public bool stayWithinParentBounds
{
get { return m_StayWithinParentBounds; }
set
{
m_StayWithinParentBounds = value;
foreach (ResizeSideHandle resizeHandle in m_ResizeSideHandles)
{
resizeHandle.stayWithinParentBounds = value;
}
}
}
bool m_MaintainApsectRatio;

public ResizeBorderFrame(VisualElement target)
{
InitializeResizeBorderFrame(target, target);
}
public ResizeBorderFrame(VisualElement target, VisualElement container)
{
InitializeResizeBorderFrame(target, container);
}
void InitializeResizeBorderFrame(VisualElement target, VisualElement container)
{
AddToClassList("reszieBorderFrame");
AddToClassList("resizeBorderFrame");
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.TopLeft));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.Top));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.TopRight));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.Right));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.BottomRight));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.Bottom));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.BottomLeft));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.Left));
// Add resize handles along the border
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.TopLeft));
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Top));
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.TopRight));
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Right));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.BottomRight));
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Bottom));
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.BottomLeft));
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Left));
foreach (ResizeSideHandle resizeHandle in m_ResizeSideHandles)
{

412
com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleSheets;
#if UNITY_2018_1
using GeometryChangedEvent = UnityEngine.Experimental.UIElements.PostLayoutEvent;
#endif

public class ResizeSideHandle : VisualElement
{
VisualElement m_ResizeTarget;
VisualElement m_Container;
bool m_StayWithinParentBounds;
public bool stayWithinParentBounds
{
get { return m_StayWithinParentBounds; }
set { m_StayWithinParentBounds = value; }
}
WindowDockingLayout m_WindowDockingLayout;
bool m_MaintainAspectRatio;

public Action OnResizeFinished;
bool m_DockingLeft;
bool m_DockingTop;
float m_InitialAspectRatio;
public ResizeSideHandle(VisualElement resizeTarget, ResizeHandleAnchor anchor)
private GUIStyle m_StyleWidget;
private GUIStyle m_StyleLabel;
private Texture image { get; set; }
public ResizeSideHandle(VisualElement resizeTarget, VisualElement container, ResizeHandleAnchor anchor)
m_WindowDockingLayout = new WindowDockingLayout();
m_Container = container;
AddToClassList("resize");

void InitialLayoutSetup(GeometryChangedEvent evt)
{
m_ResizeTarget.UnregisterCallback<GeometryChangedEvent>(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 (maintainAspectRatio)
{
if (!m_DockingTop)
{
maxHorizontalExpansion = Mathf.Min(maxHorizontalExpansion, m_ResizeBeginLayout.y);
}
else
{
maxHorizontalExpansion = Mathf.Min(maxHorizontalExpansion, m_ResizeTarget.parent.layout.height - m_ResizeBeginLayout.yMax);
}
}
return maxHorizontalExpansion;
}
float GetMaxVerticalExpansion(bool expandingUp)
{
float maxVerticalExpansion;
if (expandingUp)
{
maxVerticalExpansion = m_ResizeBeginLayout.y;
}
else
{
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;
{
}
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 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
// Set anchor points for positioning
m_Container.style.positionTop = StyleValue<float>.Create(float.NaN);
m_Container.style.positionBottom = StyleValue<float>.Create(m_Container.parent.layout.height - m_Container.layout.yMax);
Rect newLayout = m_ResizeBeginLayout;
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y);
newLayout.yMin = m_ResizeBeginLayout.yMin + delta.y;
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight);
{
if (m_DockingLeft)
{
newLayout.width = newLayout.height * m_InitialAspectRatio;
}
else
{
newLayout.xMin = newLayout.xMax - (newLayout.height * m_InitialAspectRatio);
}
}
m_ResizeTarget.layout = newLayout;
m_ResizeTarget.style.width = StyleValue<float>.Create(newHeight);
mouseMoveEvent.StopPropagation();
mouseMoveEvent.StopImmediatePropagation();
{
}
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 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
// Set anchor points for positioning
m_Container.style.positionTop = StyleValue<float>.Create(float.NaN);
m_Container.style.positionBottom = StyleValue<float>.Create(m_Container.parent.layout.height - m_Container.layout.yMax);
m_Container.style.positionLeft = StyleValue<float>.Create(m_Container.layout.xMin);
m_Container.style.positionRight = StyleValue<float>.Create(float.NaN);
Rect newLayout = m_ResizeBeginLayout;
newLayout.width += delta.x;
newLayout.yMin += delta.y;
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x);
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y);
{
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;
}
}
newWidth = newHeight = Mathf.Min(newWidth, newHeight);
m_ResizeTarget.layout = newLayout;
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth);
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight);
mouseMoveEvent.StopPropagation();
}

if (!m_Dragging)
{
}
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, m_ResizeBeginLayout.xMin + GetMinSize().x);
// Set anchor points for positioning
m_Container.style.positionLeft = StyleValue<float>.Create(m_Container.layout.xMin);
m_Container.style.positionRight = StyleValue<float>.Create(float.NaN);
if (stayWithinParentBounds)
{
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginMousePosition.x + GetMaxHorizontalExpansion(false));
}
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x);
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.xMax = m_ResizeBeginLayout.xMax + delta.x;
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth);
if (m_DockingTop)
{
newLayout.height = newLayout.width / m_InitialAspectRatio;
}
else
{
newLayout.yMin = newLayout.yMax - (newLayout.width / m_InitialAspectRatio);
}
m_ResizeTarget.style.height = StyleValue<float>.Create(newWidth);
m_ResizeTarget.layout = newLayout;
mouseMoveEvent.StopPropagation();
}

if (!m_Dragging)
{
}
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);
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
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;
// Set anchor points for positioning
m_Container.style.positionTop = StyleValue<float>.Create(m_Container.layout.yMin);
m_Container.style.positionBottom = StyleValue<float>.Create(float.NaN);
m_Container.style.positionLeft = StyleValue<float>.Create(m_Container.layout.xMin);
m_Container.style.positionRight = StyleValue<float>.Create(float.NaN);
newLayout.size += delta;
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x);
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y);
{
if (newLayout.width < newLayout.height * m_InitialAspectRatio)
{
newLayout.height = newLayout.width / m_InitialAspectRatio;
}
else
{
newLayout.width = newLayout.height * m_InitialAspectRatio;
}
}
newWidth = newHeight = Mathf.Min(newWidth, newHeight);
m_ResizeTarget.layout = newLayout;
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth);
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight);
mouseMoveEvent.StopPropagation();
}

if (!m_Dragging)
{
}
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, m_ResizeBeginLayout.yMin + GetMinSize().y);
if (stayWithinParentBounds)
{
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginMousePosition.y + GetMaxVerticalExpansion(false));
}
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
// Set anchor points for positioning
m_Container.style.positionTop = StyleValue<float>.Create(m_Container.layout.yMin);
m_Container.style.positionBottom = StyleValue<float>.Create(float.NaN);
Rect newLayout = m_ResizeBeginLayout;
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y);
newLayout.yMax = m_ResizeBeginLayout.yMax + delta.y;
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight);
{
if (m_DockingLeft)
{
newLayout.width = newLayout.height * m_InitialAspectRatio;
}
else
{
newLayout.xMin = newLayout.xMax - (newLayout.height * m_InitialAspectRatio);
}
}
m_ResizeTarget.layout = newLayout;
m_ResizeTarget.style.width = StyleValue<float>.Create(newHeight);
mouseMoveEvent.StopPropagation();
}

if (!m_Dragging)
{
}
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginLayout.xMax - GetMinSize().x);
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, m_ResizeBeginLayout.yMin + GetMinSize().y);
// Set anchor points for positioning
m_Container.style.positionTop = StyleValue<float>.Create(m_Container.layout.yMin);
m_Container.style.positionBottom = StyleValue<float>.Create(float.NaN);
m_Container.style.positionLeft = StyleValue<float>.Create(float.NaN);
m_Container.style.positionRight = StyleValue<float>.Create(m_Container.parent.layout.width - m_Container.layout.xMax);
if (stayWithinParentBounds)
{
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, 0f);
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginMousePosition.y + GetMaxVerticalExpansion(false));
}
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.xMin += delta.x;
newLayout.height += delta.y;
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x);
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y);
{
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);
}
}
newWidth = newHeight = Mathf.Min(newWidth, newHeight);
m_ResizeTarget.layout = newLayout;
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth);
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight);
mouseMoveEvent.StopPropagation();
}

if (!m_Dragging)
{
}
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition);
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
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;
// Set anchor points for positioning
m_Container.style.positionLeft = StyleValue<float>.Create(float.NaN);
m_Container.style.positionRight = StyleValue<float>.Create(m_Container.parent.layout.width - m_Container.layout.xMax);
Rect newLayout = m_ResizeBeginLayout;
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x);
newLayout.xMin = m_ResizeBeginLayout.xMin + delta.x;
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth);
{
if (m_DockingTop)
{
newLayout.height = newLayout.width / m_InitialAspectRatio;
}
else
{
newLayout.yMin = newLayout.yMax - (newLayout.width / m_InitialAspectRatio);
}
}
m_ResizeTarget.layout = newLayout;
m_ResizeTarget.style.height = StyleValue<float>.Create(newWidth);
mouseMoveEvent.StopPropagation();
}

if (!m_Dragging)
{
}
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);
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
if (stayWithinParentBounds)
{
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, 0f);
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, 0f);
}
// Set anchor points for positioning
m_Container.style.positionTop = StyleValue<float>.Create(float.NaN);
m_Container.style.positionBottom = StyleValue<float>.Create(m_Container.parent.layout.height - m_Container.layout.yMax);
m_Container.style.positionLeft = StyleValue<float>.Create(float.NaN);
m_Container.style.positionRight = StyleValue<float>.Create(m_Container.parent.layout.width - m_Container.layout.xMax);
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition;
Rect newLayout = m_ResizeBeginLayout;
newLayout.xMin += delta.x;
newLayout.yMin += delta.y;
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x);
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y);
{
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);
}
}
newWidth = newHeight = Mathf.Min(newWidth, newHeight);
m_ResizeTarget.layout = newLayout;
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth);
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight);
mouseMoveEvent.StopPropagation();
}

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;
// Get the docking settings for the window, as well as the
// layout and mouse position when resize begins.
m_WindowDockingLayout.CalculateDockingCornerAndOffset(m_Container.layout, m_Container.parent.layout);
m_WindowDockingLayout.ApplyPosition(m_Container);
m_ResizeBeginMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseDownEvent.mousePosition);
m_ResizeBeginMousePosition = mouseDownEvent.mousePosition;
m_Dragging = true;
this.TakeMouseCapture();

m_Dragging = false;
if (this.HasMouseCapture())
this.ReleaseMouseCapture();
if (OnResizeFinished != null)
OnResizeFinished();
m_WindowDockingLayout.CalculateDockingCornerAndOffset(m_Container.layout, m_Container.parent.layout);
m_WindowDockingLayout.ApplyPosition(m_Container);
}
public override void DoRepaint()
{
if (m_StyleWidget == null)
this.ReleaseMouseCapture();
m_StyleWidget = new GUIStyle("WindowBottomResize") { fixedHeight = 0 };
image = m_StyleWidget.normal.background;
if (OnResizeFinished != null)
if (image == null)
OnResizeFinished();
Debug.LogWarning("null texture passed to GUI.DrawTexture");
return;
GUI.DrawTexture(contentRect, image, ScaleMode.ScaleAndCrop, true, 0, GUI.color, 0, 0);
}
}
}

147
com.unity.shadergraph/Editor/Drawing/Manipulators/WindowDraggable.cs


using System;
using System;
using UnityEngine.Experimental.UIElements.StyleSheets;
#if UNITY_2018_1
using GeometryChangedEvent = UnityEngine.Experimental.UIElements.PostLayoutEvent;
#endif

WindowDockingLayout m_WindowDockingLayout;
Vector2 m_LocalMosueOffset;
Rect m_PreviousParentRect;
VisualElement m_Handle;
GraphView m_GraphView;

public WindowDraggable(VisualElement handle = null)
public WindowDraggable(VisualElement handle = null, VisualElement container = null)
m_PreviousParentRect = new Rect(0f, 0f, 0f, 0f);
if (container != null)
container.RegisterCallback<GeometryChangedEvent>(OnParentGeometryChanged);
}
protected override void RegisterCallbacksOnTarget()

m_Handle.RegisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), Capture.NoCapture);
m_Handle.RegisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), Capture.NoCapture);
m_Handle.RegisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), Capture.NoCapture);
target.RegisterCallback<GeometryChangedEvent>(InitialLayoutSetup);
target.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
}
protected override void UnregisterCallbacksFromTarget()

m_Handle.UnregisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), Capture.NoCapture);
target.UnregisterCallback<GeometryChangedEvent>(InitialLayoutSetup);
target.UnregisterCallback<GeometryChangedEvent>(OnGeometryChanged);
if (m_GraphView != null)
m_GraphView.UnregisterCallback<GeometryChangedEvent>(OnGeometryChanged);

{
m_Active = true;
VisualElement parent = target.parent;
while (parent != null && !(parent is GraphView))
parent = parent.parent;
m_GraphView = parent as GraphView;
if (m_GraphView != null)
m_GraphView.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
// m_LocalMouseOffset is offset from the target element's (0, 0) to the
// to the mouse position.
m_LocalMosueOffset = m_Handle.WorldToLocal(evt.mousePosition);
m_Handle.TakeMouseCapture();

{
if (m_Active)
{
Rect layout = target.layout;
layout.position = target.parent.WorldToLocal(evt.mousePosition - m_LocalMosueOffset);
target.layout = layout;
// The mouse position of is corrected according to the offset within the target
// element (m_LocalWorldOffset) to set the position relative to the mouse position
// when the dragging started.
Vector2 position = target.parent.WorldToLocal(evt.mousePosition) - m_LocalMosueOffset;
// Make sure that the object remains in the parent window
position.x = Mathf.Clamp(position.x, 0f, target.parent.layout.width - target.layout.width);
position.y = Mathf.Clamp(position.y, 0f, target.parent.layout.height - target.layout.height);
// While moving, use only the left and top position properties,
// while keeping the others NaN to not affect layout.
target.style.positionLeft = StyleValue<float>.Create(position.x);
target.style.positionTop = StyleValue<float>.Create(position.y);
target.style.positionRight = StyleValue<float>.Create(float.NaN);
target.style.positionBottom = StyleValue<float>.Create(float.NaN);
}
}

evt.StopImmediatePropagation();
// Recalculate which corner to dock to
m_WindowDockingLayout.ClampToParentWindow();
// Use the docking results to figure which of left/right and top/bottom needs to be set.
m_WindowDockingLayout.ApplyPosition(target);
// Signal that the dragging has finished.
{
}
void InitialLayoutSetup(GeometryChangedEvent GeometryChangedEvent)
void OnGeometryChanged(GeometryChangedEvent geometryChangedEvent)
m_PreviousParentRect = target.parent.layout;
target.UnregisterCallback<GeometryChangedEvent>(InitialLayoutSetup);
target.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
// Make the target clamp to the border of the window if the
// parent window becomes too small to contain it.
if (target.parent.layout.width < target.layout.width)
{
if (m_WindowDockingLayout.dockingLeft)
{
target.style.positionLeft = StyleValue<float>.Create(0f);
target.style.positionRight = StyleValue<float>.Create(float.NaN);
}
else
{
target.style.positionLeft = StyleValue<float>.Create(float.NaN);
target.style.positionRight = StyleValue<float>.Create(0f);
}
}
VisualElement parent = target.parent;
while (parent != null && !(parent is GraphView))
parent = parent.parent;
m_GraphView = parent as GraphView;
if (m_GraphView != null)
m_GraphView.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
m_WindowDockingLayout.CalculateDockingCornerAndOffset(target.layout, target.parent.layout);
if (target.parent.layout.height < target.layout.height)
{
if (m_WindowDockingLayout.dockingTop)
{
target.style.positionTop = StyleValue<float>.Create(0f);
target.style.positionBottom = StyleValue<float>.Create(float.NaN);
}
else
{
target.style.positionTop = StyleValue<float>.Create(float.NaN);
target.style.positionBottom = StyleValue<float>.Create(0f);
}
}
void OnGeometryChanged(GeometryChangedEvent GeometryChangedEvent)
void OnParentGeometryChanged(GeometryChangedEvent geometryChangedEvent)
Rect windowRect = target.layout;
Vector2 minSize = new Vector2(60f, 60f);
if (!Mathf.Approximately(target.style.minWidth, 0f))
// Check if the parent window can no longer contain the target window.
// If the window is out of bounds, make one edge clamp to the border of the
// parent window.
if (target.layout.xMin < 0f)
minSize.x = target.style.minWidth;
target.style.positionLeft = StyleValue<float>.Create(0f);
target.style.positionRight = StyleValue<float>.Create(float.NaN);
if (!Mathf.Approximately(target.style.minHeight, 0f))
if (target.layout.xMax > geometryChangedEvent.newRect.width)
minSize.y = target.style.minHeight;
target.style.positionLeft = StyleValue<float>.Create(float.NaN);
target.style.positionRight = StyleValue<float>.Create(0f);
Vector2 distanceFromParentEdge = Vector2.zero;
distanceFromParentEdge.x = m_WindowDockingLayout.dockingLeft ? target.layout.x : (m_PreviousParentRect.width - target.layout.x - target.layout.width);
distanceFromParentEdge.y = m_WindowDockingLayout.dockingTop ? target.layout.y : (m_PreviousParentRect.height - target.layout.y - target.layout.height);
Vector2 normalizedDistanceFromEdge = distanceFromParentEdge / target.parent.layout.size;
if (m_WindowDockingLayout.dockingLeft)
if (target.layout.yMax > geometryChangedEvent.newRect.height)
windowRect.x = normalizedDistanceFromEdge.x * target.parent.layout.width;
}
else
{
windowRect.x = (1f - normalizedDistanceFromEdge.x) * target.parent.layout.width - windowRect.width;
target.style.positionTop = StyleValue<float>.Create(float.NaN);
target.style.positionBottom = StyleValue<float>.Create(0f);
if (m_WindowDockingLayout.dockingTop)
{
windowRect.y = normalizedDistanceFromEdge.y * target.parent.layout.height;
}
else
if (target.layout.yMin < 0f)
windowRect.y = (1f - normalizedDistanceFromEdge.y) * target.parent.layout.height - windowRect.height;
target.style.positionTop = StyleValue<float>.Create(0f);
target.style.positionBottom = StyleValue<float>.Create(float.NaN);
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);
windowRect.x = Mathf.Clamp(windowRect.x, 0f, maximumXPosition);
windowRect.y = Mathf.Clamp(windowRect.y, 0f, maximumYPosition);
m_PreviousParentRect = target.parent.layout;
target.layout = windowRect;
}
}
}

5
com.unity.shadergraph/Editor/Drawing/PreviewManager.cs


if (masterRenderData.shaderData == null && masterNode != null)
masterRenderData.shaderData = shaderData;
var subGraphOutputNode = node as SubGraphOutputNode;
if (masterRenderData.shaderData == null && subGraphOutputNode != null)
masterRenderData.shaderData = shaderData;
}
void OnNodeModified(INode node, ModificationScope scope)

69
com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs


using UnityEngine.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Inspector;
using UnityEngine.Experimental.UIElements.StyleEnums;
using UnityEngine.Experimental.UIElements.StyleSheets;
using UnityEngine.Rendering;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
using Object = UnityEngine.Object;
#if UNITY_2018_1

AddStyleSheetPath("Styles/GraphEditorView");
m_EditorWindow = editorWindow;
previewManager = new PreviewManager(graph);
string serializedWindowLayout = EditorUserSettings.GetConfigValue(k_FloatingWindowsLayoutKey);
if (!string.IsNullOrEmpty(serializedWindowLayout))
{

}
previewManager.RenderPreviews();
var toolbar = new IMGUIContainer(() =>

content.Add(m_GraphView);
// Uncomment to enable pixel caching profiler
// m_ProfilerView = new PixelCacheProfilerView(this);
// m_GraphView.Add(m_ProfilerView);
// m_ProfilerView = new PixelCacheProfilerView(this);
// m_GraphView.Add(m_ProfilerView);
m_BlackboardProvider.blackboard.layout = new Rect(new Vector2(10f, 10f), m_BlackboardProvider.blackboard.layout.size);
Rect blackboardLayout = m_BlackboardProvider.blackboard.layout;
blackboardLayout.x = 10f;
blackboardLayout.y = 10f;
m_BlackboardProvider.blackboard.layout = blackboardLayout;
WindowDraggable masterPreviewViewDraggable = new WindowDraggable();
WindowDraggable masterPreviewViewDraggable = new WindowDraggable(null, this);
ResizeBorderFrame masterPreviewResizeBorderFrame = new ResizeBorderFrame(m_MasterPreviewView) { name = "resizeBorderFrame" };
masterPreviewResizeBorderFrame.stayWithinParentBounds = true;
masterPreviewResizeBorderFrame.maintainAspectRatio = true;
masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.Add(masterPreviewResizeBorderFrame);
m_BlackboardProvider.onDragFinished += UpdateSerializedWindowLayout;
m_BlackboardProvider.onResizeFinished += UpdateSerializedWindowLayout;
//m_BlackboardProvider.onDragFinished += UpdateSerializedWindowLayout;
//m_BlackboardProvider.onResizeFinished += UpdateSerializedWindowLayout;
masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.previewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;
m_GraphView.graphViewChanged = GraphViewChanged;

}
}
void HandleEditorViewChanged(GeometryChangedEvent evt)
{
m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout.GetLayout(m_GraphView.layout);
}
void StoreBlackboardLayoutOnGeometryChanged(GeometryChangedEvent evt)
{
UpdateSerializedWindowLayout();
}
void ApplySerializewindowLayouts(GeometryChangedEvent evt)
{
UnregisterCallback<GeometryChangedEvent>(ApplySerializewindowLayouts);

m_MasterPreviewView.layout = m_FloatingWindowsLayout.previewLayout.GetLayout(layout);
m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout.GetLayout(layout);
// Restore master preview layout
m_FloatingWindowsLayout.previewLayout.ApplyPosition(m_MasterPreviewView);
m_MasterPreviewView.previewTextureView.style.width = StyleValue<float>.Create(m_FloatingWindowsLayout.masterPreviewSize.x);
m_MasterPreviewView.previewTextureView.style.height = StyleValue<float>.Create(m_FloatingWindowsLayout.masterPreviewSize.y);
// Restore blackboard layout
m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout.GetLayout(this.layout);
previewManager.ResizeMasterPreview(m_FloatingWindowsLayout.masterPreviewSize);
}

}
// After the layout is restored from the previous session, start tracking layout changes in the blackboard.
m_BlackboardProvider.blackboard.RegisterCallback<GeometryChangedEvent>(StoreBlackboardLayoutOnGeometryChanged);
// After the layout is restored, track changes in layout and make the blackboard have the same behavior as the preview w.r.t. docking.
RegisterCallback<GeometryChangedEvent>(HandleEditorViewChanged);
}
void UpdateSerializedWindowLayout()

m_FloatingWindowsLayout.previewLayout.CalculateDockingCornerAndOffset(m_MasterPreviewView.layout, layout);
m_FloatingWindowsLayout.blackboardLayout.CalculateDockingCornerAndOffset(m_BlackboardProvider.blackboard.layout, layout);
m_FloatingWindowsLayout.masterPreviewSize = m_MasterPreviewView.Q("preview").layout.size;
m_FloatingWindowsLayout.previewLayout.CalculateDockingCornerAndOffset(m_MasterPreviewView.layout, m_GraphView.layout);
m_FloatingWindowsLayout.previewLayout.ClampToParentWindow();
m_FloatingWindowsLayout.blackboardLayout.CalculateDockingCornerAndOffset(m_BlackboardProvider.blackboard.layout, m_GraphView.layout);
m_FloatingWindowsLayout.blackboardLayout.ClampToParentWindow();
if (m_MasterPreviewView.expanded)
{
m_FloatingWindowsLayout.masterPreviewSize = m_MasterPreviewView.previewTextureView.layout.size;
}
m_MasterPreviewView.RefreshRenderTextureSize();
}
public void Dispose()

1
com.unity.shadergraph/Editor/Resources/Styles/Blackboard.uss


.sgblackboard {
position-type:absolute;
border-left-width: 1;
border-top-width: 1;
border-right-width: 1;

2
com.unity.shadergraph/Editor/Resources/Styles/Controls/EnumControlView.uss


}
EnumControlView > EnumField {
width: 80;
flex: 1;
margin-left: 0;
margin-right: 8;

EnumControlView > Label {
width: 100;
padding-left: 0;
padding-right: 0;
padding-top: 0;

4
com.unity.shadergraph/Editor/Resources/Styles/GraphEditorView.uss


#resizeBorderFrame > .resize.diagonal {
width: 10;
height: 10;
height: 6;
}
#resizeBorderFrame > .resize.diagonal.top-left {

position-right: 0;
}
.reszieBorderFrame {
.resizeBorderFrame {
position-type: absolute;
position-top: 0;
position-right: 0;

47
com.unity.shadergraph/Editor/Resources/Styles/MasterPreviewView.uss


MasterPreviewView {
flex-direction: column;
position-type: absolute;
position-right: 0;
position-bottom: 0;
position-right: 10;
position-bottom: 10;
min-width: 200;
min-height: 200;
border-radius: 6;
border-top-width: 1;
border-bottom-width: 1;

flex-direction: row;
justify-content: space-between;
background-color: rgb(64, 64, 64);
padding-top: 8;
padding-bottom: 8;

padding-right: 2;
}
MasterPreviewView > #top > #collapse-container {
align-self : center;
width : 12;
}
MasterPreviewView > #top > #collapse-container > #icon{
align-self: center;
background-image : resource("GraphView/Nodes/NodeChevronDown");
width: 12;
height: 12;
margin-right: 10;
margin-left: 10;
}
MasterPreviewView > #top > #collapse-container > #icon.collapsed {
align-self: center;
background-image : resource("GraphView/Nodes/NodeChevronLeft");
width: 12;
height: 12;
}
MasterPreviewView > #top > #collapse-container > #icon.expanded {
align-self: center;
background-image : resource("GraphView/Nodes/NodeChevronDown");
width: 12;
height: 12;
}
MasterPreviewView > #middle {
flex-grow: 1;
border-width: 10;

flex-grow: 1;
border-width: 10;
border-color: rgb(200,10,190);
width: 200;
height: 200;
MasterPreviewView.collapsed{
background-color: rgb(206, 53, 185);
}
MasterPreviewView.expanded{
background-color: rgb(206, 53, 185);
}
正在加载...
取消
保存