浏览代码

upgrading ui

/main
Tim Cooper 8 年前
当前提交
3093c701
共有 106 个文件被更改,包括 1653 次插入812 次删除
  1. 68
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs
  2. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs
  3. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs
  4. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs
  5. 3
      MaterialGraphProject/Assets/NewUI/Editor/Capabilities.cs
  6. 73
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Decorators/GridBackground.cs
  7. 3
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Circle.cs
  8. 6
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/CircleData.cs
  9. 8
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/MiniMapData.cs
  10. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/SimpleElementData.cs
  11. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/CustomEdge.cs
  12. 81
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Data/NodeAnchorData.cs
  13. 25
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Data/NodeData.cs
  14. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Node.cs
  15. 149
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/NodeAnchor.cs
  16. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/VerticalNode.cs
  17. 13
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/IMGUIElement.cs
  18. 30
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/InvisibleBorderContainer.cs
  19. 5
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/MiniMap.cs
  20. 10
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/SimpleElement.cs
  21. 10
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/WWWImage.cs
  22. 32
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/IMGUISampleViewData.cs
  23. 10
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/NodesContentViewData.cs
  24. 6
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/SimpleContentViewData.cs
  25. 91
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.uss
  26. 190
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.cs
  27. 48
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss
  28. 3
      MaterialGraphProject/Assets/NewUI/Editor/Direction.cs
  29. 41
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Data/EdgeData.cs
  30. 18
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Data/GraphElementData.cs
  31. 106
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Edge.cs
  32. 17
      MaterialGraphProject/Assets/NewUI/Editor/Elements/GraphElement.cs
  33. 8
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/ClickSelector.cs
  34. 19
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/ContentDragger.cs
  35. 16
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/Dragger.cs
  36. 86
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/EdgeConnector.cs
  37. 27
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/RectangleSelector.cs
  38. 36
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/Resizer.cs
  39. 34
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/SelectionDragger.cs
  40. 4
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/Zoomer.cs
  41. 2
      MaterialGraphProject/Assets/NewUI/Editor/Utils/PainterExtensions.cs
  42. 12
      MaterialGraphProject/Assets/NewUI/Editor/Utils/RectUtils.cs
  43. 4
      MaterialGraphProject/Assets/NewUI/Editor/Utils/UIHelpers.cs
  44. 42
      MaterialGraphProject/Assets/NewUI/Editor/Views/Data/GraphViewDataSource.cs
  45. 213
      MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.cs
  46. 13
      MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss
  47. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/NodePreviewDrawer.cs
  48. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs
  49. 2
      MaterialGraphProject/MaterialGraphProject.sln.DotSettings.user
  50. 4
      MaterialGraphProject/Assets/NewUI/Editor/Demo/IMGUISampleViewWindow.cs
  51. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators.meta
  52. 21
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.imported.asset
  53. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.imported.asset.meta
  54. 9
      MaterialGraphProject/Assets/NewUI/Editor/Demo/GraphElements.meta
  55. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/IMGUISampleViewWindow.cs.meta
  56. 30
      MaterialGraphProject/Assets/NewUI/Editor/Demo/NodalViewWindow.cs
  57. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/NodalViewWindow.cs.meta
  58. 30
      MaterialGraphProject/Assets/NewUI/Editor/Demo/SimpleGraphViewWindow.cs
  59. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/SimpleGraphViewWindow.cs.meta
  60. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/NodesContentViewData.cs.meta
  61. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/SimpleContentViewData.cs.meta
  62. 21
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.uss.imported.asset
  63. 8
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.uss.imported.asset.meta
  64. 45
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodesContentView.cs
  65. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodesContentView.cs.meta
  66. 21
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss.imported.asset
  67. 8
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss.imported.asset.meta
  68. 9
      MaterialGraphProject/Assets/NewUI/Editor/Graph.meta
  69. 9
      MaterialGraphProject/Assets/NewUI/Editor/GraphElements.meta
  70. 9
      MaterialGraphProject/Assets/NewUI/Editor/GraphElementsData.meta
  71. 8
      MaterialGraphProject/Assets/NewUI/Editor/IConnection.cs
  72. 12
      MaterialGraphProject/Assets/NewUI/Editor/IConnection.cs.meta
  73. 28
      MaterialGraphProject/Assets/NewUI/Editor/IConnector.cs
  74. 10
      MaterialGraphProject/Assets/NewUI/Editor/IConnectorCollection.cs
  75. 12
      MaterialGraphProject/Assets/NewUI/Editor/IConnectorCollection.cs.meta
  76. 15
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/KeyModifiers.cs
  77. 12
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/KeyModifiers.cs.meta
  78. 50
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/MouseManipulator.cs
  79. 12
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/MouseManipulator.cs.meta
  80. 21
      MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss.imported.asset
  81. 8
      MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss.imported.asset.meta
  82. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/PropertyNodeDrawData.cs.meta
  83. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss.imported.asset
  84. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss.imported.asset.meta
  85. 150
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/EdgeConnector.cs
  86. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/EdgeConnector.cs.meta
  87. 9
      MaterialGraphProject/Assets/NewUI/Editor/Demo/GraphElements/Graph.meta
  88. 9
      MaterialGraphProject/Assets/NewUI/Editor/Demo/GraphElements/Nodes.meta
  89. 9
      MaterialGraphProject/Assets/NewUI/Editor/Graph/GraphElements.meta
  90. 9
      MaterialGraphProject/Assets/NewUI/Editor/GraphElements/Graph.meta
  91. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/NodalViewData.cs.meta
  92. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/SimpleGraphViewData.cs.meta
  93. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/IMGUISampleView.cs.meta
  94. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.cs.meta
  95. 31
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleGraphView.cs
  96. 12
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleGraphView.cs.meta

68
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs


[SerializeField]
private List<GraphElementData> m_Elements = new List<GraphElementData>();
[SerializeField]
private List<GraphElementData> m_TempElements = new List<GraphElementData>();
private readonly Dictionary<Type, Type> m_DataMapper = new Dictionary<Type, Type>();
public IGraphAsset graphAsset { get; private set; }

var deletedElements = m_Elements
.OfType<NodeDrawData>()
.Where(nd => !graphAsset.graph.GetNodes<INode>().Contains(nd.node))
.Cast<GraphElementData>()
.OfType<GraphElementData>()
.ToList();
var deletedEdges = m_Elements.OfType<EdgeDrawData>()

foreach (var edgeData in deletedEdges)
{
// Make sure to disconnect the node, otherwise new connections won't be allowed for the used slots
edgeData.left.connected = false;
edgeData.right.connected = false;
edgeData.output.Disconnect(edgeData);
edgeData.input.Disconnect(edgeData);
var toNodeGuid = edgeData.edge.inputSlot.nodeGuid;
var toNode = m_Elements.OfType<NodeDrawData>().FirstOrDefault(nd => nd.node.guid == toNodeGuid);

var targetAnchors = targetNode.elements.OfType<AnchorDrawData>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
var edgeData = ScriptableObject.CreateInstance<EdgeDrawData>();
var edgeData = CreateInstance<EdgeDrawData>();
edgeData.left = sourceAnchor;
edgeData.right = targetAnchor;
edgeData.output = sourceAnchor;
edgeData.output.Connect(edgeData);
edgeData.input = targetAnchor;
edgeData.input.Connect(edgeData);
drawableEdges.Add(edgeData);
}
}

OnNodeChanged(targetNode.node, ModificationScope.Graph);
var edgeData = ScriptableObject.CreateInstance<EdgeDrawData>();
var edgeData = CreateInstance<EdgeDrawData>();
edgeData.left = sourceAnchor;
edgeData.right = targetAnchor;
edgeData.output = sourceAnchor;
edgeData.output.Connect(edgeData);
edgeData.input = targetAnchor;
edgeData.input.Connect(edgeData);
drawableEdges.Add(edgeData);
}
}

UpdateData();
}
protected AbstractGraphDataSource()
{ }
public void AddNode(INode node)
{
graphAsset.graph.AddNode(node);

public IEnumerable<GraphElementData> elements
{
get { return m_Elements; }
get { return m_Elements.Union(m_TempElements); }
}
public void AddTempElement(GraphElementData element)
{
m_TempElements.Add(element);
public void AddElement(GraphElementData element)
public void RemoveTempElement(GraphElementData element)
{
m_TempElements.Remove(element);
}
public void ClearTempElements()
{
m_TempElements.Clear();
}
public void Connect(AnchorDrawData left, AnchorDrawData right)
var edge = element as EdgeData;
if (edge != null && edge.candidate == false)
if (left && right)
var left = edge.left as AnchorDrawData;
var right = edge.right as AnchorDrawData;
if (left && right)
{
graphAsset.graph.Connect(left.slot.slotReference, right.slot.slotReference);
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
}
graphAsset.graph.Connect(left.slot.slotReference, right.slot.slotReference);
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
return;
}
m_Elements.Add(element);
public void AddElement(GraphElementData element)
{
throw new ArgumentException("Not supported on Serializable Graph, data comes from data store");
m_Elements.RemoveAll(x => x == element);
UpdateData();
throw new ArgumentException("Not supported on Serializable Graph, data comes from data store");
}
}
}

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs


protected List<GraphElementData> m_Children = new List<GraphElementData>();
public override IEnumerable<GraphElementData> elements
public IEnumerable<GraphElementData> elements
{
get { return m_Children; }
}

public override void CommitChanges()
public void CommitChanges()
base.CommitChanges();
var drawData = node.drawState;
drawData.position = position;
node.drawState = drawData;

foreach (var input in node.GetSlots<ISlot>())
{
var data = CreateInstance<AnchorDrawData>();
data.Initialize(input);
data.Initialize(input);
m_Children.Add(data);
}

//position
}
}
}
}

4
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs


AddToClassList("NodeDrawer");
}
public override void DoRepaint(PaintContext painter)
public override void DoRepaint(IStylePainter painter)
painter.DrawRectangleOutline(transform, position, Color.yellow);
painter.DrawRect(position, backgroundColor, 0.0f, borderRadius);
}
}

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs


nodalViewData.RemoveElements(
selection.OfType<NodeDrawer>().Select(x => x.dataProvider as NodeDrawData),
selection.OfType<RMGUI.GraphView.Edge>().Select(x => x.dataProvider as EdgeDrawData)
selection.OfType<Edge>().Select(x => x.dataProvider as EdgeDrawData)
);
return EventPropagation.Stop;

3
MaterialGraphProject/Assets/NewUI/Editor/Capabilities.cs


DoesNotCollapse = 1 << 2,
Floating = 1 << 3,
Resizable = 1 << 4,
Movable = 1 << 5
Movable = 1 << 5,
Deletable = 1 << 6
}
}

73
MaterialGraphProject/Assets/NewUI/Editor/Demo/Decorators/GridBackground.cs


namespace RMGUI.GraphView.Demo
{
public class GridBackground : IDecorator
public class GridBackground : IDecorator, IStyleTarget
// Most likely will be a built-in style property soon
const string BackgroundColorProperty = "background-color";
const string GridBackgroundColorProperty = "grid-background-color";
StyleProperty<float> m_Spacing;
return m_Container.GetStyleFloat(SpacingProperty, 50.0f);
return m_Spacing.GetOrDefault(50.0f);
StyleProperty<int> m_ThickLines;
return m_Container.GetStyleInt(ThickLinesProperty, 10);
return m_ThickLines.GetOrDefault(10);
StyleProperty<Color> m_LineColor;
return m_Container.GetStyleColor(LineColorProperty, new Color(0f, 0f, 0f, 0.18f));
return m_LineColor.GetOrDefault(new Color(0f, 0f, 0f, 0.18f));
StyleProperty<Color> m_ThickLineColor;
return m_Container.GetStyleColor(ThickLineColorProperty, new Color(0f, 0f, 0f, 0.38f));
return m_ThickLineColor.GetOrDefault(new Color(0f, 0f, 0f, 0.38f));
StyleProperty<Color> m_BackgroundColor;
return m_Container.GetStyleColor(BackgroundColorProperty, new Color(0.17f, 0.17f, 0.17f, 1.0f));
return m_BackgroundColor.GetOrDefault(new Color(0.17f, 0.17f, 0.17f, 1.0f));
}
}

return _in;
}
public void PrePaint(VisualElement target, PaintContext pc)
// Notes: styles are read from this manipulator's target,
// note its m_Container member
public void OnStylesResolved(VisualElementStyles styles)
{
styles.ApplyCustomProperty(SpacingProperty, ref m_Spacing);
styles.ApplyCustomProperty(ThickLinesProperty, ref m_ThickLines);
styles.ApplyCustomProperty(ThickLineColorProperty, ref m_ThickLineColor);
styles.ApplyCustomProperty(LineColorProperty, ref m_LineColor);
styles.ApplyCustomProperty(GridBackgroundColorProperty, ref m_BackgroundColor);
}
public void PrePaint(VisualElement target, IStylePainter pc)
{
var graphView = target as GraphView;
if (graphView == null)

Rect clientRect = graphView.position;
var containerScale = new Vector3(m_Container.transform.GetColumn(0).magnitude,
m_Container.transform.GetColumn(1).magnitude,
m_Container.transform.GetColumn(2).magnitude);
m_Container.transform.GetColumn(1).magnitude,
m_Container.transform.GetColumn(2).magnitude);
var containerTranslation = m_Container.transform.GetColumn(3);
var containerPosition = m_Container.position;

GL.Begin(GL.QUADS);
GL.Color(backgroundColor);
GL.Vertex(new Vector3(clientRect.x, clientRect.y));
GL.Vertex(new Vector3(clientRect.xMax, clientRect.y));
GL.Vertex(new Vector3(clientRect.xMax, clientRect.yMax));
GL.Vertex(new Vector3(clientRect.x, clientRect.yMax));
GL.Color(backgroundColor);
GL.Vertex(new Vector3(clientRect.x, clientRect.y));
GL.Vertex(new Vector3(clientRect.xMax, clientRect.y));
GL.Vertex(new Vector3(clientRect.xMax, clientRect.yMax));
GL.Vertex(new Vector3(clientRect.x, clientRect.yMax));
GL.End();
// vertical lines

to.x += spacing * containerScale.x;
GL.Begin(GL.LINES);
GL.Color(lineColor);
GL.Vertex(Clip(clientRect, from));
GL.Vertex(Clip(clientRect, to));
GL.Color(lineColor);
GL.Vertex(Clip(clientRect, from));
GL.Vertex(Clip(clientRect, to));
GL.End();
}

while (from.x < clientRect.width + thickLineSpacing)
{
GL.Begin(GL.LINES);
GL.Color(thickLineColor);
GL.Vertex(Clip(clientRect, from));
GL.Vertex(Clip(clientRect, to));
GL.Color(thickLineColor);
GL.Vertex(Clip(clientRect, from));
GL.Vertex(Clip(clientRect, to));
GL.End();
from.x += (spacing * containerScale.x * thickLines);

to.y += spacing * containerScale.y;
GL.Begin(GL.LINES);
GL.Color(lineColor);
GL.Vertex(Clip(clientRect, from));
GL.Vertex(Clip(clientRect, to));
GL.Color(lineColor);
GL.Vertex(Clip(clientRect, from));
GL.Vertex(Clip(clientRect, to));
GL.End();
}

while (from.y < clientRect.height + thickLineSpacing)
{
GL.Begin(GL.LINES);
GL.Color(thickLineColor);
GL.Vertex(Clip(clientRect, from));
GL.Vertex(Clip(clientRect, to));
GL.Color(thickLineColor);
GL.Vertex(Clip(clientRect, from));
GL.Vertex(Clip(clientRect, to));
GL.End();
from.y += spacing * containerScale.y * thickLines;

public void PostPaint(VisualElement target, PaintContext pc)
public void PostPaint(VisualElement element, IStylePainter pc)
{
}
}

3
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Circle.cs


{
public class Circle : GraphElement
{
public override void DoRepaint(PaintContext args)
public override void DoRepaint(IStylePainter painter)
base.DoRepaint(args);
Handles.DrawSolidDisc(new Vector3(position.x + position.width/2, position.y + position.height/2, 0.0f),
new Vector3(0.0f, 0.0f, -1.0f),
position.width / 2.0f);

6
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/CircleData.cs


}
}
protected new void OnEnable()
{
base.OnEnable();
capabilities |= Capabilities.Deletable;
}
protected CircleData() {}
}
}

8
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/MiniMapData.cs


public float maxWidth;
[SerializeField]
public bool anchored;
private bool m_Anchored;
public bool anchored
{
get { return m_Anchored; }
set { m_Anchored = value; }
}
protected new void OnEnable()
{

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/SimpleElementData.cs


using System;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{

public string title;
[SerializeField]
private string m_Title;
public string title
{
get { return m_Title; }
set { m_Title = value; }
}
title = "simpleElement";
title = string.Empty;
}
protected SimpleElementData() {}

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/CustomEdge.cs


{
class CustomEdge : Edge
{
protected override void DrawEdge(PaintContext args)
protected override void DrawEdge(IStylePainter painter)
{
var edgeData = GetData<EdgeData>();
if (edgeData == null)

IConnectable leftData = edgeData.left;
if (leftData == null)
IConnector outputData = edgeData.output;
IConnector inputData = edgeData.input;
if (outputData == null && inputData == null)
return;
Vector2 from = Vector2.zero;

else
{
Vector3[] points, tangents;
Orientation orientation = leftData.orientation;
GetTangents(leftData.direction, orientation, from, to, out points, out tangents);
Orientation orientation = outputData != null ? outputData.orientation : inputData.orientation;
GetTangents(orientation, from, to, out points, out tangents);
Color edgeColor = (GetData<EdgeData>() != null && GetData<EdgeData>().selected) ? Color.yellow : Color.white;
Handles.DrawBezier(points[0], points[1], tangents[0], tangents[1], edgeColor, null, 5f);

81
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Data/NodeAnchorData.cs


using System;
using System.Collections.Generic;
using System.Linq;
public class NodeAnchorData : GraphElementData, IConnectable
public class NodeAnchorData : GraphElementData, IConnector
{
protected object m_Source;
public object source

[SerializeField]
private Direction m_Direction;
public Direction direction
public virtual Direction direction
// TODO We should not be able to change direction of an existing anchor
get { return m_Direction; }
set { m_Direction = value; }
}

public Orientation orientation
public virtual Orientation orientation
{
get { return m_Orientation; } set { m_Orientation = value; }
}

public Type type
public virtual Type type
{
get { return m_Type; }
set { m_Type = value; }

private bool m_Highlight;
public bool highlight
public virtual bool highlight
public virtual bool connected
{
get
{
return (m_Direction == Direction.Output ? m_OutputConnections : m_InputConnections).Count != 0;
}
}
public virtual IEnumerable<IConnection> connections
{
get
{
return (m_Direction == Direction.Output ? m_OutputConnections : m_InputConnections).Cast<IConnection>();
}
}
// TODO we'll probably want to distinguish between InputAnchorData and OutputAnchorData so as to
// not burden ourselves with extra data we don't need.
private bool m_Connected;
public bool connected
private List<GraphElementData> m_InputConnections;
[SerializeField]
private List<GraphElementData> m_OutputConnections;
public void Connect(IConnection connection)
{
var ged = connection as GraphElementData;
if (connection != null && ged == null)
{
throw new ArgumentException("The value passed to NodeAnchorData.Connect is not a GraphElementData");
}
if (m_Direction == Direction.Input)
{
if (!m_InputConnections.Contains(ged))
{
m_InputConnections.Add(ged);
}
}
else
{
if (!m_OutputConnections.Contains(ged))
{
m_OutputConnections.Add(ged);
}
}
}
public void Disconnect(IConnection connection)
get { return m_Connected; }
set { m_Connected = value; }
var ged = connection as GraphElementData;
if (connection != null && ged == null)
{
throw new ArgumentException("The value passed to NodeAnchorData.Disconnect is not a GraphElementData");
}
if (m_Direction == Direction.Input)
{
m_InputConnections.Remove(ged);
}
else
{
m_OutputConnections.Remove(ged);
}
}
protected new void OnEnable()

m_OutputConnections = new List<GraphElementData>();
m_InputConnections = new List<GraphElementData>();
}
protected NodeAnchorData() {}

25
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Data/NodeData.cs


using System;
using System.Collections.Generic;
using System.Linq;
class NodeData : SimpleElementData
class NodeData : SimpleElementData, IConnectorCollection
{
[SerializeField]
protected List<NodeAnchorData> m_Anchors;

// NOTE: This is a demo node. We could have any number of output anchors if we wanted.
public NodeAnchorData outputAnchor;
public IEnumerable<IConnector> inputConnectors
{
get { return m_Anchors.Cast<IConnector>(); }
}
public IEnumerable<IConnector> outputConnectors
{
get
{
if (outputAnchor != null)
{
yield return outputAnchor;
}
}
}
// TODO make a simple creation function
protected new void OnEnable()
{

outputAnchor = CreateInstance<NodeAnchorData>();
outputAnchor.type = typeof(int);
outputAnchor.direction = Direction.Output; // get rid of direction use styles
capabilities |= Capabilities.Deletable;
}
public override void OnRemoveFromGraph()
{
}
protected NodeData() {}

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Node.cs


}
m_OutputContainer.AddChild(new NodeAnchor(nodeData.outputAnchor));
}
if (!classList.Contains("vertical") && !classList.Contains("horizontal"))
{
if (nodeData is VerticalNodeData)
{
AddToClassList("vertical");
}
else
{
AddToClassList("horizontal");
}
}
}
public Node()

149
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/NodeAnchor.cs


using UnityEditor;
using UnityEngine;
using UnityEngine.RMGUI;
using UnityEngine.RMGUI.StyleEnums.Values;
using UnityEngine.RMGUI.StyleSheets;
using UnityEngine.RMGUI.StyleEnums;
namespace RMGUI.GraphView.Demo
{

private IManipulator m_CurrentConnector;
VisualElement m_ConnectorBox;
VisualElement m_ConnectorText;
// currently we don't want to be styled as .graphElement since we're contained in a Node
classList = ClassList.empty;
m_ConnectorBox = new VisualElement() { name = "connector", width = k_NodeSize, height = k_NodeSize };
m_ConnectorBox.pickingMode = PickingMode.Ignore;
AddChild(m_ConnectorBox);
m_ConnectorText = new VisualElement() { name = "type" };
m_ConnectorText.content = new GUIContent();
m_ConnectorText.pickingMode = PickingMode.Ignore;
AddChild(m_ConnectorText);
dataProvider = data;
}

}
}
private Rect GetAnchorRect(NodeAnchorData nodeAnchorData)
{
Rect rect = new Rect();
if (nodeAnchorData.orientation == Orientation.Horizontal)
{
// TODO: placement could be better handled using better CSS properties to place the node anchor itself.
if (nodeAnchorData.direction == Direction.Input)
{
rect = new Rect(position.x + 2, position.y + 2, k_NodeSize, k_NodeSize);
}
else if (nodeAnchorData.direction == Direction.Output)
{
rect = new Rect(position.x + position.width - (7 + k_NodeSize), position.y + 2, k_NodeSize, k_NodeSize);
}
}
else
{
if (nodeAnchorData.direction == Direction.Input)
{
rect = new Rect(position.x + (position.width - k_NodeSize)/2, position.y + 4, k_NodeSize, k_NodeSize);
}
else if (nodeAnchorData.direction == Direction.Output)
{
rect = new Rect(position.x + (position.width - k_NodeSize)/2, position.y + position.height - k_NodeSize - 8, k_NodeSize, k_NodeSize);
}
}
return rect;
}
protected virtual void DrawConnector()
{
var nodeAnchorData = GetData<NodeAnchorData>();
if (nodeAnchorData == null)
return;
var anchorColor = Color.yellow;
anchorColor.a = 0.7f;
Rect rect = GetAnchorRect(nodeAnchorData);
Handles.DrawSolidRectangleWithOutline(rect, anchorColor, anchorColor);
if (nodeAnchorData.highlight)
{
var highlightColor = Color.blue;
Rect highlighRect = rect;
highlighRect.x += 4;
highlighRect.y += 4;
highlighRect.width -= 8;
highlighRect.height -= 8;
Handles.DrawSolidRectangleWithOutline(highlighRect, highlightColor, highlightColor);
}
}
public override void DoRepaint(PaintContext args)
{
base.DoRepaint(args);
DrawConnector();
}
ClearChildren();
var nodeAnchorData = GetData<NodeAnchorData>();
if (nodeAnchorData == null)

Type constructedClass = genericClass.MakeGenericType(type);
nodeAnchorData.source = Activator.CreateInstance(constructedClass);
Label label;
// TODO: I figure this placement could be more generic with a better use of CSS placement
if (nodeAnchorData.orientation == Orientation.Horizontal)
if (nodeAnchorData.highlight)
string anchorName = string.IsNullOrEmpty(nodeAnchorData.name) ? type.Name : nodeAnchorData.name;
label = new Label(new GUIContent(anchorName))
{
positionType = PositionType.Absolute,
positionTop = 0,
positionLeft = 20,
positionRight = 0,
positionBottom = 0
};
if (nodeAnchorData.direction == Direction.Output)
{
label.textAlignment = TextAnchor.UpperRight;
label.positionLeft = 0;
label.positionRight = 25;
}
m_ConnectorBox.AddToClassList("anchorHighlight");
label = new Label(new GUIContent(type.Name))
{
positionType = PositionType.Absolute,
positionTop = 20,
positionLeft = 0,
positionRight = 0,
positionBottom = 0
};
if (nodeAnchorData.direction == Direction.Output)
{
label.textAlignment = TextAnchor.LowerCenter;
label.positionTop = 0;
label.positionBottom = 25;
}
else
{
label.textAlignment = TextAnchor.UpperCenter;
}
m_ConnectorBox.RemoveFromClassList("anchorHighlight");
string anchorName = string.IsNullOrEmpty(nodeAnchorData.name) ? type.Name : nodeAnchorData.name;
m_ConnectorText.content.text = anchorName;
label.pickingMode = PickingMode.Ignore;
AddChild(label);
}
public Rect GetSelectionRect()
{
var nodeAnchorData = GetData<NodeAnchorData>();
if (nodeAnchorData == null)
return new Rect();
return GetAnchorRect(nodeAnchorData);
var center = GetSelectionRect().center;
var globalCenter = new Vector3(center.x + parent.position.x, center.y + parent.position.y);
return parent.globalTransform.MultiplyPoint3x4(globalCenter);
}
public override bool Overlaps(Rect rect)
{
return GetSelectionRect().Overlaps(rect);
var center = m_ConnectorBox.position.center;
center = m_ConnectorBox.transform.MultiplyPoint3x4(center);
return this.LocalToGlobal(center);
return GetSelectionRect().Contains(localPoint);
// Here local point comes without position offset...
localPoint -= position.position;
return m_ConnectorBox.ContainsPoint(m_ConnectorBox.transform.MultiplyPoint3x4(localPoint));
}
}
}

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/VerticalNode.cs


namespace RMGUI.GraphView.Demo
{
[GUISkinStyle("box")]
class VerticalNode : GraphElement
class VerticalNode : SimpleElement
{
readonly VisualContainer m_ContainerTop;
readonly VisualContainer m_ContainerBottom;

AddChild(m_ContainerTop);
AddChild(m_ContainerBottom);
}
public override void DoRepaint(PaintContext painter)
{
base.DoRepaint(painter);
if (GetData<VerticalNodeData>() != null && GetData<VerticalNodeData>().selected)
{
painter.DrawRectangleOutline(transform, position, Color.yellow);
}
}
public override void OnDataChanged()

13
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/IMGUIElement.cs


using UnityEngine.RMGUI;
using UnityEngine.RMGUI.StyleEnums.Values;
using UnityEngine.RMGUI.StyleEnums;
private IMGUIContainer m_Container;
var imgui = new IMGUIContainer()
m_Container = new IMGUIContainer()
{
positionType = PositionType.Absolute,
positionLeft = 0,

OnGUIHandler = OnGUIHandler
};
AddChild(imgui);
AddChild(m_Container);
}
public virtual void OnGUIHandler()

{
imguiData.OnGUIHandler();
}
}
public override void OnDataChanged()
{
base.OnDataChanged();
m_Container.executionContext = dataProvider.GetInstanceID();
}
}
}

30
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/InvisibleBorderContainer.cs


{
public class InvisibleBorderContainer : GraphElement
{
private readonly Color m_OutlineColor = new Color(0.0f, 0.0f, 0.0f, 0.5f);
private Rect selectRect
{
get
{
return new Rect(position.width * 0.1f, position.height * 0.1f, position.width * 0.8f, position.height * 0.8f);
}
}
Rect GetRectWithOutline()
{
return new Rect(position.x + selectRect.x, position.y+selectRect.y, selectRect.width, selectRect.height);
}
return GetRectWithOutline().Overlaps(rectangle);
return paddingRect.Overlaps(rectangle);
return GetRectWithOutline().Contains(localPoint);
}
public override void DoRepaint(PaintContext args)
{
Color color = m_OutlineColor;
if (GetData<InvisibleBorderContainerData>() != null && GetData<InvisibleBorderContainerData>().selected)
color = Color.blue;
Handles.DrawSolidRectangleWithOutline(position, color, color);
Rect zone = GetRectWithOutline();
Handles.DrawSolidRectangleWithOutline(zone, Color.green, Color.green);
return paddingRect.Contains(localPoint);
}
}
}

5
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/MiniMap.cs


namespace RMGUI.GraphView.Demo
{
[GUISkinStyle("box")]
public class MiniMap : GraphElement
{
private float m_PreviousContainerWidth = -1;

}
}
public override void DoRepaint(PaintContext args)
public override void DoRepaint(IStylePainter painter)
{
var gView = this.GetFirstAncestorOfType<GraphView>();
VisualContainer container = gView.contentViewContainer;

String.Format("{0:0}", containerTranslation.x) + "," + String.Format("{0:0}", containerTranslation.y) + " s: " +
String.Format("{0:N2}", containerScale.x)/* + "," + String.Format("{0:N2}", containerScale.y)*/);
base.DoRepaint(args);
base.DoRepaint(painter);
foreach (var child in container.children)
{

10
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/SimpleElement.cs


namespace RMGUI.GraphView.Demo
{
[GUISkinStyle("window")]
}
public override void DoRepaint(PaintContext painter)
{
base.DoRepaint(painter);
if (GetData<SimpleElementData>() != null && GetData<SimpleElementData>().selected)
{
painter.DrawRectangleOutline(transform, position, Color.yellow);
}
}
public override void OnDataChanged()

10
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/WWWImage.cs


WWW m_Www;
bool m_IsScheduled;
VisualElement m_ImageHolder;
public WWWImage()
{
m_Www = new WWW("http://lorempixel.com/200/200");

m_ImageHolder = new VisualElement();
m_ImageHolder.content = new GUIContent("Loading ...");
AddChild(m_ImageHolder);
}
private void SchedulePolling()

if (m_WwwTexture == null)
{
m_WwwTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
AddChild(new Image {image = m_WwwTexture});
m_ImageHolder.content.text = string.Empty;
m_ImageHolder.backgroundImage = m_WwwTexture;
m_Www = new WWW("http://lorempixel.com/200/200");
this.Touch(ChangeType.Repaint);

32
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/IMGUISampleViewData.cs


protected IMGUISampleElementData() {}
}
public class EditorGUISampleElementData : IMGUIData
{
private Color cc;
private Color cc2;
public override void OnGUIHandler()
{
cc = EditorGUILayout.ColorField("Color", cc);
cc2 = EditorGUILayout.ColorField("Color2", cc2);
}
}
public class IMGUISampleViewData : GraphViewDataSource
{
protected new void OnEnable()

imguiSample.position = new Rect(100, 200, 230, 300);
imguiSample.position = new Rect(100, 225, 230, 300);
var imguiSample2 = CreateInstance<IMGUISampleElementData>();
imguiSample2.position = new Rect(400, 225, 230, 300);
imguiSample2.title = "IMGUIControls: modal";
imguiSample2.capabilities |= Capabilities.Resizable;
AddElement(imguiSample2);
var imguiEd = CreateInstance<EditorGUISampleElementData>();
imguiEd.position = new Rect(100, 25, 230, 75);
imguiEd.title = "IMGUIControls: editor stuff";
imguiEd.capabilities |= Capabilities.Resizable;
AddElement(imguiEd);
var imguiEd2 = CreateInstance<EditorGUISampleElementData>();
imguiEd2.position = new Rect(100, 125, 230, 75);
imguiEd2.title = "IMGUIControls: editor stuff 2";
imguiEd2.capabilities |= Capabilities.Resizable;
AddElement(imguiEd2);
}
protected IMGUISampleViewData() {}

10
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/NodesContentViewData.cs


namespace RMGUI.GraphView.Demo
{
class NodalViewData : GraphViewDataSource
class NodesContentViewData : GraphViewDataSource
{
protected new void OnEnable()
{

AddElement(nodeData);
}
protected NodalViewData() {}
protected NodesContentViewData() {}
}
internal static class MyNodeAdapters

internal static bool Adapt(this NodeAdapter value, PortSource<Vector3> a, PortSource<Vector3> b)
{
// run adapt code for vec3 to vec3 connections
return true;
}
internal static bool Adapt(this NodeAdapter value, PortSource<Vector4> a, PortSource<Vector4> b)
{
// run adapt code for vec4 to vec4 connections
return true;
}

6
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/SimpleContentViewData.cs


protected TestIMGUIElementData() {}
}
public class SimpleGraphViewData : GraphViewDataSource
public class SimpleContentViewData : GraphViewDataSource
{
protected new void OnEnable()
{

var wwwImageData = CreateInstance<WWWImageData>();
wwwImageData.title = "WWW Image";
wwwImageData.position = new Rect(300, 300, 200, 200);
wwwImageData.position = new Rect(300, 300, 204, 219);
AddElement(wwwImageData);
var invisibleBorderContainerData = CreateInstance<InvisibleBorderContainerData>();

protected SimpleGraphViewData() {}
protected SimpleContentViewData() {}
}
}

91
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.uss


VerticalNode #top {
flex: 1;
align-items: flex-start;
Node #input {
flex:1;
}
Node #output {
flex:1;
justify-content: flex-end;
}
NodeAnchor {
margin-top:5;
margin-bottom:5;
}
NodeAnchor #connector {
background-color:#FF0;
border-color:#FF0;
/* width is currently hard-coded */
border-width: 4;
}
NodeAnchor #connector.anchorHighlight {
background-color:#00F;
}
NodeAnchor #type {
text-color:#FFF;
flex:1;
}
Node.horizontal #output NodeAnchor #type {
text-alignment:middle-right;
}
Node.horizontal NodeAnchor #connector {
margin-left: 5;
margin-right: 5;
}
Node.horizontal {
VerticalNode #bottom {
flex: 1;
align-items: flex-start;
Node.horizontal #input, Node.horizontal #output {
margin-top: 15;
background-color:#444;
}
Node.horizontal #input NodeAnchor {
VerticalNode NodeAnchor {
height: 50;
flex:1;
Node.horizontal #output NodeAnchor {
flex-direction: row-reverse;
Node {
Node.vertical #input, Node.vertical #output {
flex: 1;
justify-content: center;
Node #input {
flex:1;
Node.vertical NodeAnchor {
align-items: center;
}
/* there is currently an issue with text size evaluation
which causes layout to "shake", so this is a just to avoid the visual glitch */
Node.vertical NodeAnchor #type {
text-alignment:middle-center;
Node #output {
flex:1;
justify-content: flex-end;
Node.vertical #input NodeAnchor {
flex-direction: column;
NodeAnchor {
height: 26;
Node.vertical #output NodeAnchor {
flex-direction: column-reverse;
Node.vertical {
border-width: 1;
border-color:#CCC;
background-color:rgba(100, 100, 100, 0.5);
}
#contentViewContainer {
background-color:#404749;
NodesContentView {
grid-background-color:#404749;
spacing:50.0;
spacing:75.0;
thick-lines:10;
}

190
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.cs


using System;
using System.Linq;
[StyleSheet("Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss")]
[StyleSheet("Assets/Editor/Demo/Views/SimpleContentView.uss")]
public class SimpleContentView : GraphView
{
public SimpleContentView()

{
{Event.KeyboardEvent("a"), FrameAll},
{Event.KeyboardEvent("f"), FrameSelection},
{Event.KeyboardEvent("o"), FrameOrigin}
{Event.KeyboardEvent("o"), FrameOrigin},
{Event.KeyboardEvent("delete"), DeleteSelection}
}));
AddDecorator(new GridBackground());

dataMapper[typeof(SimpleElementData)] = typeof(SimpleElement);
dataMapper[typeof(WWWImageData)] = typeof(WWWImage);
dataMapper[typeof(IMGUIData)] = typeof(IMGUIElement);
}
bool m_FrameAnimate = false;
public enum FrameType
{
All = 0,
Selection = 1,
Origin = 2
}
private Rect m_LastSelectionRect;
public override void DoRepaint(PaintContext painter)
{
base.DoRepaint(painter);
painter.DrawRectangleOutline(transform, m_LastSelectionRect, Color.red);
}
// TODO: Move elsewhere
static Rect Encompass(Rect a, Rect b)
{
return new Rect
{
xMin = Math.Min(a.xMin, b.xMin),
yMin = Math.Min(a.yMin, b.yMin),
xMax = Math.Max(a.xMax, b.xMax),
yMax = Math.Max(a.yMax, b.yMax)
};
}
void CalculateFrameTransform(Rect rectToFit, out Vector3 frameTranslation, out Vector3 frameScaling)
{
// Give it full width/height
Rect clientRect = position;
// bring slightly smaller screen rect into GUI space
var screenRect = new Rect
{
xMin = 30,
xMax = clientRect.width - 30,
yMin = 30,
yMax = clientRect.height - 30
};
Matrix4x4 m = GUI.matrix;
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);
Rect identity = GUIUtility.ScreenToGUIRect(screenRect);
// measure zoom level necessary to fit the canvas rect into the screen rect
float zoomLevel = Math.Min(identity.width / rectToFit.width, identity.height / rectToFit.height);
// clamp
zoomLevel = Mathf.Clamp(zoomLevel, 0.08f, 1.0f);
var cachedScale = new Vector3(transform.GetColumn(0).magnitude,
transform.GetColumn(1).magnitude,
transform.GetColumn(2).magnitude);
Vector4 cachedTranslation = transform.GetColumn(3);
transform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(zoomLevel, zoomLevel, 1.0f));
var edge = new Vector2(clientRect.width, clientRect.height);
var origin = new Vector2(0, 0);
var r = new Rect
{
min = origin,
max = edge
};
var parentScale = new Vector3(transform.GetColumn(0).magnitude,
transform.GetColumn(1).magnitude,
transform.GetColumn(2).magnitude);
Vector2 offset = r.center - (rectToFit.center * parentScale.x);
// Update output values before leaving
frameTranslation = new Vector3(offset.x, offset.y, 0.0f);
frameScaling = parentScale;
transform = Matrix4x4.TRS(cachedTranslation, Quaternion.identity, cachedScale);
GUI.matrix = m;
}
EventPropagation FrameAll()
{
return Frame(FrameType.All);
}
EventPropagation FrameSelection()
{
return Frame(FrameType.Selection);
}
EventPropagation FrameOrigin()
{
return Frame(FrameType.Origin);
}
EventPropagation Frame(FrameType frameType)
{
// Reset container translation, scale and position
contentViewContainer.transform *= contentViewContainer.transform.inverse;
Rect p = contentViewContainer.position;
p.x = 0;
p.y = 0;
contentViewContainer.position = p;
if (frameType == FrameType.Origin)
{
return EventPropagation.Stop;
}
Rect rectToFit = contentViewContainer.position;
if (frameType == FrameType.Selection)
{
// Now calculate rectangle to fit all selected elements
if (selection.Count == 0)
{
return EventPropagation.Continue;
}
var graphElement = selection[0] as GraphElement;
if (graphElement != null)
{
rectToFit = graphElement.localBound;
}
rectToFit = selection.OfType<GraphElement>()
.Aggregate(rectToFit, (current, e) => Encompass(current, e.localBound));
}
else /*if (frameType == FrameType.All)*/
{
bool reachedFirstChild = false;
foreach (VisualElement child in contentViewContainer.children)
{
var graphElement = child as GraphElement;
if (graphElement == null ||
(graphElement.dataProvider.capabilities & Capabilities.Floating) != 0 ||
(graphElement.dataProvider is EdgeData))
{
continue;
}
if (!reachedFirstChild)
{
rectToFit = graphElement.localBound;
reachedFirstChild = true;
}
else
{
rectToFit = Encompass(rectToFit, graphElement.localBound);
}
}
}
Vector3 frameTranslation;
Vector3 frameScaling;
m_LastSelectionRect = rectToFit;
CalculateFrameTransform(rectToFit, out frameTranslation, out frameScaling);
if (m_FrameAnimate)
{
// TODO
// RMAnimation animation = new RMAnimation();
// parent.Animate(parent)
// .Lerp(new string[] {"m_Scale", "m_Translation"},
// new object[] {parent.scale, parent.translation},
// new object[] {frameScaling, frameTranslation}, 0.08f);
}
else
{
Matrix4x4 t = Matrix4x4.identity;
t *= Matrix4x4.TRS(frameTranslation, Quaternion.identity, frameScaling);
contentViewContainer.transform = t;
}
contentViewContainer.Touch(ChangeType.Repaint);
return EventPropagation.Stop;
}
}
}

48
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss


WWWImage {
/* TODO refactor with two containers.
Here reseting the padding-top will offset the text content as well*/
/*padding-top: 0;*/
padding-left: 0;
padding-right: 0;
padding-bottom: 0;
}
WWWImage > Image {
flex:1;
WWWImage > * {
margin-top: 15;
width: 200;
height: 200;
/* will display while the image is loading */
background-color: #CCC;
border-radius: 25;
text-alignment:middle-center;
}
MiniMap Label {

height: 16;
}
MiniMap {
MiniMap.graphElement {
border-color:#CCC;
background-color:rgba(100, 100, 100, 0.5);
MiniMap Label {
text-clipping:overflow;
}
MiniMap.anchored {
position-left:20;
position-bottom:20;

color:#aaaa00
text-color:#aaaa00
}
InvisibleBorderContainer.graphElement {
background-color:#0F0;
/* currently border-XXX is only used for layout
where border-width is used to paint text and border.
They must keep in sync until we support variable border
thickness per edge */
border-color:#000;
border-left:20;
border-top:20;
border-right:20;
border-bottom:20;
border-width:20;
border-radius: 0;
}
InvisibleBorderContainer.graphElement.selected {
border-color:#00F;
}

3
MaterialGraphProject/Assets/NewUI/Editor/Direction.cs


public enum Direction
{
Input = 0,
Output = 1,
Bidirectional = 2
Output = 1
}
}

41
MaterialGraphProject/Assets/NewUI/Editor/Elements/Data/EdgeData.cs


namespace RMGUI.GraphView
{
[Serializable]
public class EdgeData : GraphElementData
public class EdgeData : GraphElementData, IConnection
public IConnectable left;
public IConnectable right;
public Vector2 candidatePosition;
public bool candidate;
[SerializeField]
private GraphElementData m_OutputData;
[SerializeField]
private GraphElementData m_InputData;
public virtual IConnector output
{
get { return (IConnector)m_OutputData; }
set
{
var ged = value as GraphElementData;
if (value != null && ged == null)
throw new ArgumentException("The value passed to EgdeData.output is not a GraphElementData");
m_OutputData = ged;
}
}
public virtual IConnector input
{
get { return (IConnector)m_InputData; }
set
{
var ged = value as GraphElementData;
if (value != null && ged == null)
throw new ArgumentException("The value passed to EgdeData.input is not a GraphElementData");
m_InputData = ged;
}
}
public Vector2 candidatePosition { get; set; }
public bool candidate { get; set; }
capabilities = Capabilities.Selectable;
base.OnEnable();
capabilities = Capabilities.Deletable;
}
protected EdgeData() {}

18
MaterialGraphProject/Assets/NewUI/Editor/Elements/Data/GraphElementData.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace RMGUI.GraphView

set { m_Position = value; }
}
public Capabilities capabilities
{
get { return m_Capabilities; }
set { m_Capabilities = value; }
}
public bool selected
{
get { return m_Selected; }

capabilities = Capabilities.Normal | Capabilities.Movable | Capabilities.Selectable;
}
public virtual IEnumerable<GraphElementData> elements
{
get { return new GraphElementData[0]; }
}
public Capabilities capabilities
public virtual void OnRemoveFromGraph()
get { return m_Capabilities; }
set { m_Capabilities = value; }
public virtual void CommitChanges()
{}
}
}

106
MaterialGraphProject/Assets/NewUI/Editor/Elements/Edge.cs


this.Touch(ChangeType.Repaint);
}
protected static void GetTangents(Direction direction, Orientation orientation, Vector2 start, Vector2 end, out Vector3[] points, out Vector3[] tangents)
{
if (direction == Direction.Output)
{
Vector2 t = end;
end = start;
start = t;
}
// TODO lots of redundant code in here that could be factorized
// TODO The tangents are calculated way to often. We should compute them on repaint only.
protected static void GetTangents(Orientation orientation, Vector2 from, Vector2 to, out Vector3[] points, out Vector3[] tangents)
{
if (end.x < start.x)
if (from.x < to.x)
Vector3 t = start;
start = end;
end = t;
Vector3 t = to;
to = from;
from = t;
points = new Vector3[] {start, end};
points = new Vector3[] {to, from};
tangents = new Vector3[2];
const float minTangent = 30;

float y = 0;
float cleverness = Mathf.Clamp01(((start - end).magnitude - 10) / 50);
float cleverness = Mathf.Clamp01(((to - from).magnitude - 10) / 50);
tangents[0] = start + new Vector2((end.x - start.x) * weight + minTangent, y) * cleverness;
tangents[1] = end + new Vector2((end.x - start.x) * -weight2 - minTangent, -y) * cleverness;
tangents[0] = to + new Vector2((from.x - to.x) * weight + minTangent, y) * cleverness;
tangents[1] = from + new Vector2((from.x - to.x) * -weight2 - minTangent, -y) * cleverness;
tangents[0] = start + new Vector2(y, inverse * ((end.x - start.x) * weight + minTangent)) * cleverness;
tangents[1] = end + new Vector2(-y, inverse * ((end.x - start.x) * -weight2 - minTangent)) * cleverness;
tangents[0] = to + new Vector2(y, inverse * ((from.x - to.x) * weight + minTangent)) * cleverness;
tangents[1] = from + new Vector2(-y, inverse * ((from.x - to.x) * -weight2 - minTangent)) * cleverness;
}
}

if (edgeData == null)
return false;
IConnectable leftData = edgeData.left;
IConnectable rightData = edgeData.right ?? leftData;
if (leftData == null || rightData == null)
IConnector outputData = edgeData.output;
IConnector inputData = edgeData.input;
if (outputData == null && inputData == null)
return false;
Vector2 from = Vector2.zero;

Orientation orientation = leftData.orientation;
Orientation orientation = outputData != null ? outputData.orientation : inputData.orientation;
GetTangents(leftData.direction, orientation, from, to, out points, out tangents);
GetTangents(orientation, from, to, out points, out tangents);
Vector3[] allPoints = Handles.MakeBezierPoints(points[0], points[1], tangents[0], tangents[1], 20);
for (int a = 0; a < allPoints.Length; a++)

if (edgeData == null)
return false;
IConnectable leftData = edgeData.left;
IConnectable rightData = edgeData.right ?? leftData;
if (leftData == null || rightData == null)
IConnector outputData = edgeData.output;
IConnector inputData = edgeData.input;
if (outputData == null && inputData == null)
return false;
Vector2 from = Vector2.zero;

return false;
}
Orientation orientation = leftData.orientation;
Orientation orientation = outputData != null ? outputData.orientation : inputData.orientation;
GetTangents(leftData.direction, orientation, from, to, out points, out tangents);
GetTangents(orientation, from, to, out points, out tangents);
Vector3[] allPoints = Handles.MakeBezierPoints(points[0], points[1], tangents[0], tangents[1], 20);
float minDistance = Mathf.Infinity;

return false;
}
public override void DoRepaint(PaintContext args)
public override void DoRepaint(IStylePainter painter)
base.DoRepaint(args);
DrawEdge(args);
base.DoRepaint(painter);
DrawEdge(painter);
}
protected void GetFromToPoints(ref Vector2 from, ref Vector2 to)

return;
IConnectable leftData = edgeData.left;
IConnectable rightData = edgeData.right ?? leftData;
if (leftData == null)
IConnector outputData = edgeData.output;
IConnector inputData = edgeData.input;
if (outputData == null && inputData == null)
GraphElement leftAnchor = parent.allElements.OfType<GraphElement>().First(e => e.dataProvider as IConnectable == leftData);
if (leftAnchor != null)
if (outputData != null)
from = leftAnchor.GetGlobalCenter();
from = globalTransform.inverse.MultiplyPoint3x4(from);
GraphElement leftAnchor = parent.allElements.OfType<GraphElement>().First(e => e.dataProvider as IConnector == outputData);
if (leftAnchor != null)
{
from = leftAnchor.GetGlobalCenter();
from = globalTransform.inverse.MultiplyPoint3x4(from);
}
if (edgeData.candidate)
else if (edgeData.candidate)
to = globalTransform.inverse.MultiplyPoint3x4(new Vector3(edgeData.candidatePosition.x, edgeData.candidatePosition.y));
from = globalTransform.inverse.MultiplyPoint3x4(new Vector3(edgeData.candidatePosition.x, edgeData.candidatePosition.y));
else
if (inputData != null)
GraphElement rightAnchor = parent.allElements.OfType<GraphElement>().First(e => e.dataProvider as IConnectable == rightData);
GraphElement rightAnchor = parent.allElements.OfType<GraphElement>().First(e => e.dataProvider as IConnector == inputData);
if (rightAnchor != null)
{
to = rightAnchor.GetGlobalCenter();

else if (edgeData.candidate)
{
to = globalTransform.inverse.MultiplyPoint3x4(new Vector3(edgeData.candidatePosition.x, edgeData.candidatePosition.y));
}
protected virtual void DrawEdge(PaintContext args)
protected virtual void DrawEdge(IStylePainter painter)
IConnectable leftData = edgeData.left;
if (leftData == null)
IConnector outputData = edgeData.output;
IConnector inputData = edgeData.input;
if (outputData == null && inputData == null)
return;
Vector2 from = Vector2.zero;

Color edgeColor = (GetData<EdgeData>() != null && GetData<EdgeData>().selected) ? Color.yellow : Color.white;
Orientation orientation = leftData.orientation;
Orientation orientation = outputData != null ? outputData.orientation : inputData.orientation;
GetTangents(leftData.direction, orientation, from, to, out points, out tangents);
GetTangents(orientation, from, to, out points, out tangents);
Handles.DrawBezier(points[0], points[1], tangents[0], tangents[1], edgeColor, null, 5f);
// little widget on the middle of the edge

Handles.DrawWireDisc(allPoints[10], new Vector3(0.0f, 0.0f, -1.0f), 6f);
Handles.DrawWireDisc(allPoints[10], new Vector3(0.0f, 0.0f, -1.0f), 5f);
// TODO need to fix color of unconnected ends now that we've changed how the connection being built work (i.e. left is not always guaranteed to be the connected end... in fact, left doesn't exist anymore)
if (edgeData.right == null)
if (edgeData.input == null)
Handles.color = oldColor;
Handles.DrawSolidDisc(to, new Vector3(0.0f, 0.0f, -1.0f), k_EndPointRadius);
Handles.color = oldColor;

17
MaterialGraphProject/Assets/NewUI/Editor/Elements/GraphElement.cs


using UnityEngine;
using UnityEngine.RMGUI;
using UnityEngine.RMGUI.StyleSheets;
namespace RMGUI.GraphView
{

readonly static ClassList s_ElementsClassList = new ClassList("graphElement");
public GraphElement()
{
classList = s_ElementsClassList;
}
public T GetData<T>() where T : GraphElementData
{

childData.selected = data.selected;
}
}
}
if (data.selected)
{
AddToClassList("selected");
}
else
{
RemoveFromClassList("selected");
}
SetPosition(data.position);

8
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/ClickSelector.cs


namespace RMGUI.GraphView
{
public class ClickSelector : Manipulator
public class ClickSelector : MouseManipulator
public MouseButton activateButton { get; set; }
public ClickSelector()
{
// snoop events before children

public override EventPropagation HandleEvent(Event evt, VisualElement finalTarget)
{
var selectable = finalTarget.GetFirstOfType<ISelectable>();
if ( selectable==null || !selectable.IsSelectable())
if (selectable == null || !selectable.IsSelectable())
{
return EventPropagation.Continue;
}

switch (evt.type)
{
case EventType.MouseDown:
if (evt.button == (int)activateButton)
if (CanStartManipulation(evt))
{
if (graphView.selection.Contains(selectable))
{

19
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/ContentDragger.cs


using System;
using System;
using UnityEngine.RMGUI.StyleEnums.Values;
using UnityEngine.RMGUI.StyleEnums;
public class ContentDragger : Manipulator
public class ContentDragger : MouseManipulator
{
private Vector2 m_Start;
public Vector2 panSpeed { get; set; }

public ContentDragger()
{
activateButton = MouseButton.LeftMouse;
activateModifiers = KeyModifiers.Alt;
panSpeed = new Vector2(1, 1);
clampToParentEdges = false;
}

switch (evt.type)
{
case EventType.MouseDown:
if (evt.button == (int) MouseButton.MiddleMouse
|| evt.button == (int) MouseButton.LeftMouse && evt.modifiers == EventModifiers.Alt)
if (CanStartManipulation(evt))
{
this.TakeCapture();

case EventType.MouseDrag:
if (this.HasCapture() && graphView.contentViewContainer.positionType == PositionType.Absolute)
{
var diff = graphView.ChangeCoordinatesTo(graphView.contentViewContainer, evt.mousePosition) - m_Start;
var t = graphView.contentViewContainer.transform;
Vector2 diff = graphView.ChangeCoordinatesTo(graphView.contentViewContainer, evt.mousePosition) - m_Start;
Matrix4x4 t = graphView.contentViewContainer.transform;
graphView.contentViewContainer.transform = t*Matrix4x4.Translate(new Vector3(diff.x, diff.y, 0));
return EventPropagation.Stop;

case EventType.MouseUp:
if (this.HasCapture()
&& (evt.button == (int) MouseButton.MiddleMouse
|| evt.button == (int) MouseButton.MiddleMouse))
if (CanStopManipulation(evt))
{
this.ReleaseCapture();
return EventPropagation.Stop;

16
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/Dragger.cs


using UnityEngine;
using UnityEngine.RMGUI;
using UnityEngine.RMGUI.StyleEnums.Values;
using UnityEngine.RMGUI.StyleEnums;
public class Dragger : Manipulator
public class Dragger : MouseManipulator
{
private Vector2 m_Start;

public GraphElementData m_data { get; set; }
public MouseButton activateButton { get; set; }
activateButton = MouseButton.MiddleMouse;
activateButton = MouseButton.LeftMouse;
panSpeed = new Vector2(1, 1);
clampToParentEdges = false;
}

GraphElement ce = finalTarget as GraphElement;
if (ce != null)
{
var data = ce.dataProvider;
GraphElementData data = ce.dataProvider;
if (data != null && ((data.capabilities & Capabilities.Movable) != Capabilities.Movable))
{
return EventPropagation.Continue;

switch (evt.type)
{
case EventType.MouseDown:
if (evt.button == (int)activateButton)
if (CanStartManipulation(evt))
{
this.TakeCapture();

case EventType.MouseDrag:
if (this.HasCapture() && target.positionType == PositionType.Absolute)
{
var diff = evt.mousePosition - m_Start;
Vector2 diff = evt.mousePosition - m_Start;
if (m_data != null)
{

break;
case EventType.MouseUp:
if (this.HasCapture() && evt.button == (int)activateButton)
if (CanStopManipulation(evt))
{
m_data = null;
this.ReleaseCapture();

86
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/EdgeConnector.cs


namespace RMGUI.GraphView
{
internal class EdgeConnector<TEdgeData> : Manipulator where TEdgeData : EdgeData
internal class EdgeConnector<TEdgeData> : MouseManipulator where TEdgeData : EdgeData
private readonly List<IConnectable> m_CompatibleAnchors = new List<IConnectable>();
private readonly List<IConnector> m_CompatibleAnchors = new List<IConnector>();
public MouseButton activateButton { get; set; }
public EdgeConnector()
{

switch (evt.type)
{
case EventType.MouseDown:
if (evt.button != (int)activateButton)
if (!CanStartManipulation(evt))
IConnectable cnx = null;
IConnector cnx = null;
cnx = (IConnectable)data;
cnx = (IConnector)data;
m_GraphView = graphElement.GetFirstAncestorOfType<GraphView>();
}

var nodeAdapter = new NodeAdapter();
// get all available connectors
IEnumerable<IConnectable> visibleAnchors = m_GraphView.allChildren.OfType<GraphElement>()
.Select(e => e.dataProvider)
.OfType<IConnectable>()
.Where(a => a.IsConnectable());
foreach (var toCnx in visibleAnchors)
foreach (var toCnx in m_GraphView.allChildren.OfType<GraphElement>()
.Select(e => e.dataProvider)
.OfType<IConnector>()
.Where(c => c.IsConnectable() &&
c.orientation == cnx.orientation &&
c.direction != cnx.direction &&
nodeAdapter.GetAdapter(c.source, cnx.source) != null))
if (cnx.orientation != toCnx.orientation)
continue;
bool isBidirectional = ((cnx.direction == Direction.Bidirectional) ||
(toCnx.direction == Direction.Bidirectional));
if (cnx.direction != toCnx.direction || isBidirectional)
{
if (nodeAdapter.GetAdapter(cnx.source, toCnx.source) != null)
{
toCnx.highlight = true;
m_CompatibleAnchors.Add(toCnx);
}
}
toCnx.highlight = true;
m_CompatibleAnchors.Add(toCnx);
m_EdgeDataCandidate.left = graphElement.dataProvider as IConnectable;
m_EdgeDataCandidate.right = null;
bool startFromOutput = (cnx.direction == Direction.Output);
if (startFromOutput)
{
m_EdgeDataCandidate.output = graphElement.dataProvider as IConnector;
m_EdgeDataCandidate.input = null;
}
else
{
m_EdgeDataCandidate.output = null;
m_EdgeDataCandidate.input = graphElement.dataProvider as IConnector;
}
m_EdgeDataCandidate.candidate = true;
m_EdgeDataCandidate.candidatePosition = target.LocalToGlobal(evt.mousePosition);

break;
case EventType.MouseUp:
if (this.HasCapture() && evt.button == (int)activateButton)
if (CanStopManipulation(evt))
IConnector endConnector = null;
foreach (var compatibleAnchor in m_CompatibleAnchors)
{

{
if (anchorElement.globalBound.Contains(target.LocalToGlobal(evt.mousePosition)))
{
m_EdgeDataCandidate.right = compatibleAnchor;
endConnector = compatibleAnchor;
}
}
}

if (m_EdgeDataCandidate != null && m_DataSource != null)
{
// Not a candidate anymore, let's see if we're actually going to add it to parent
m_EdgeDataCandidate.candidate = false;
m_DataSource.RemoveElement(m_EdgeDataCandidate);
if (m_EdgeDataCandidate.right != null)
if (endConnector == null)
{
m_DataSource.RemoveElement(m_EdgeDataCandidate);
}
else
m_DataSource.AddElement(m_EdgeDataCandidate);
m_EdgeDataCandidate.left.connected = true;
m_EdgeDataCandidate.right.connected = true;
if (m_EdgeDataCandidate.output == null)
{
m_EdgeDataCandidate.output = endConnector;
}
else
{
m_EdgeDataCandidate.input = endConnector;
}
m_EdgeDataCandidate.output.Connect(m_EdgeDataCandidate);
m_EdgeDataCandidate.input.Connect(m_EdgeDataCandidate);
m_EdgeDataCandidate.candidate = false;
}
m_EdgeDataCandidate = null;

27
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/RectangleSelector.cs


namespace RMGUI.GraphView
{
public class RectangleSelector : Manipulator, IDecorator
public class RectangleSelector : MouseManipulator, IDecorator
public MouseButton activateButton { get; set; }
public RectangleSelector()
{

// get the AA aligned bound
public Rect ComputeAAAlignedBound(Rect position, Matrix4x4 transform)
{
var min = transform.MultiplyPoint3x4(position.min);
var max = transform.MultiplyPoint3x4(position.max);
Vector3 min = transform.MultiplyPoint3x4(position.min);
Vector3 max = transform.MultiplyPoint3x4(position.max);
return Rect.MinMaxRect(Math.Min(min.x, max.x), Math.Min(min.y, max.y), Math.Max(min.x, max.x), Math.Max(min.y, max.y));
}

switch (evt.type)
{
case EventType.MouseDown:
if (evt.button == (int)activateButton)
if (CanStartManipulation(evt))
{
if (!evt.control)
{

break;
case EventType.MouseUp:
if (this.HasCapture() && evt.button == (int)activateButton)
if (CanStopManipulation(evt))
{
this.ReleaseCapture();
target.RemoveDecorator(this);

Rect selectionRect = new Rect();
var selectionRect = new Rect();
selectionRect.min = new Vector2(Math.Min(m_Start.x, m_End.x), Math.Min(m_Start.y, m_End.y));
selectionRect.max = new Vector2(Math.Max(m_Start.x, m_End.x), Math.Max(m_Start.y, m_End.y));

List<ISelectable> selection = graphView.selection;
var children = graphView.contentViewContainer.GetChildren();
List<VisualElement>.Enumerator children = graphView.contentViewContainer.GetChildren();
var child = children.Current;
VisualElement child = children.Current;
var selectableTransform = child.transform.inverse;
Matrix4x4 selectableTransform = child.transform.inverse;
var localSelRect = new Rect(selectableTransform.MultiplyPoint3x4(selectionRect.position), selectableTransform.MultiplyPoint3x4(selectionRect.size));
if (selectable != null && selectable.IsSelectable() && selectable.Overlaps(localSelRect))
{

target.RemoveDecorator(this);
}
public void PrePaint(VisualElement t, PaintContext pc)
public void PrePaint(VisualElement t, IStylePainter painter)
public void PostPaint(VisualElement t, PaintContext pc)
public void PostPaint(VisualElement t, IStylePainter painter)
var screenStart = m_Start;
var screenEnd = m_End;
Vector2 screenStart = m_Start;
Vector2 screenEnd = m_End;
// Avoid drawing useless information
if (m_Start == m_End)

36
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/Resizer.cs


using System;
using UnityEngine;
using UnityEngine.RMGUI;
using UnityEngine.RMGUI.StyleEnums.Values;
using UnityEngine.RMGUI.StyleEnums;
public class Resizer : Manipulator, IDecorator
public class Resizer : MouseManipulator, IDecorator
public MouseButton activateButton { get; set; }
// When applyInvTransform is true, Resizer will apply target's inverse transform before drawing/picking
// (has the effect of being zoom factor independent)
public bool applyInvTransform { get; set; }

public override EventPropagation HandleEvent(Event evt, VisualElement finalTarget)
{
var ce = target as GraphElement;
if (ce==null)
if (ce == null)
var data = ce.dataProvider;
if (data==null)
GraphElementData data = ce.dataProvider;
if (data == null)
if ( (data.capabilities & Capabilities.Resizable) != Capabilities.Resizable)
if ((data.capabilities & Capabilities.Resizable) != Capabilities.Resizable)
if (evt.button == (int) activateButton)
if (CanStartManipulation(evt))
var adjustedWidget = k_WidgetPickRect;
Rect adjustedWidget = k_WidgetPickRect;
if (applyInvTransform)
{
var inv = target.globalTransform.inverse;

var widget = m_StartPos;
Rect widget = m_StartPos;
widget.x = widget.width - adjustedWidget.width;
widget.y = widget.height - adjustedWidget.height;

case EventType.MouseDrag:
if (this.HasCapture() && target.positionType == PositionType.Absolute)
{
var diff = evt.mousePosition - m_Start;
Vector2 diff = evt.mousePosition - m_Start;
var newSize = new Vector2(m_StartPos.width + diff.x, m_StartPos.height + diff.y);
if (newSize.x < m_MinimumSize.x)

return EventPropagation.Continue;
case EventType.MouseUp:
if (this.HasCapture() && evt.button == (int)activateButton)
if (CanStopManipulation(evt))
{
this.ReleaseCapture();
return EventPropagation.Stop;

return EventPropagation.Continue;
}
public void PrePaint(VisualElement t, PaintContext pc)
public void PrePaint(VisualElement t, IStylePainter painter)
public void PostPaint(VisualElement t, PaintContext pc)
public void PostPaint(VisualElement t, IStylePainter painter)
{
// TODO: I would like to listen for skin change and create GUIStyle then and only then
if (m_StyleWidget == null)

}
// Draw resize widget
var widget = k_WidgetRect;
Rect widget = k_WidgetRect;
var inv = pc.worldXForm.inverse;
Matrix4x4 inv = painter.worldXForm.inverse;
widget.width *= inv.m00;
widget.height *= inv.m11;
}

if (this.HasCapture())
{
// Get adjusted text offset
var adjustedWidget = k_WidgetTextOffset;
Rect adjustedWidget = k_WidgetTextOffset;
var inv = pc.worldXForm.inverse;
Matrix4x4 inv = painter.worldXForm.inverse;
adjustedWidget.width *= inv.m00; // Apply scale
adjustedWidget.height *= inv.m11;
}

34
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/SelectionDragger.cs


using System;
using System.Linq;
using UnityEngine;
using UnityEngine.RMGUI;

public SelectionDragger()
{
activateButton = MouseButton.LeftMouse;
activateModifiers = KeyModifiers.None;
panSpeed = new Vector2(1, 1);
clampToParentEdges = false;
}

switch (evt.type)
{
case EventType.MouseDown:
if (evt.button == (int)activateButton)
if (CanStartManipulation(evt))
{
// avoid starting a manipulation on a non movable object
var ce = finalTarget as GraphElement;

return EventPropagation.Continue;
}
var data = ce.dataProvider;
GraphElementData data = ce.dataProvider;
if (data != null && ((ce.dataProvider.capabilities & Capabilities.Movable) != Capabilities.Movable))
return EventPropagation.Continue;

if (ce == null || ce.dataProvider == null)
continue;
var data = ce.dataProvider;
GraphElementData data = ce.dataProvider;
var g = ce.globalTransform;
Matrix4x4 g = ce.globalTransform;
if (data != null)
{
data.position = CalculatePosition(data.position.x + evt.delta.x * panSpeed.x / scale.x,
data.position.y + evt.delta.y * panSpeed.y / scale.y,
data.position.width, data.position.height);
}
else
{
throw new Exception("Graph Element should have valid data");
}
data.position = CalculatePosition(data.position.x + evt.delta.x * panSpeed.x / scale.x,
data.position.y + evt.delta.y * panSpeed.y / scale.y,
data.position.width, data.position.height);
}
return EventPropagation.Stop;

case EventType.MouseUp:
if (this.HasCapture() && evt.button == (int)activateButton)
if (CanStopManipulation(evt))
foreach (var s in graphView.selection.OfType<GraphElement>())
{
if (s.dataProvider == null)
continue;
s.dataProvider.CommitChanges();
}
this.ReleaseCapture();
this.ReleaseCapture();
return EventPropagation.Stop;
}
break;

4
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/Zoomer.cs


{
case EventType.ScrollWheel:
{
var transform = graphView.contentViewContainer.transform;
Matrix4x4 transform = graphView.contentViewContainer.transform;
var zoomCenter = target.ChangeCoordinatesTo(graphView.contentViewContainer, evt.mousePosition);
Vector2 zoomCenter = target.ChangeCoordinatesTo(graphView.contentViewContainer, evt.mousePosition);
float x = zoomCenter.x + graphView.contentViewContainer.position.x;
float y = zoomCenter.y + graphView.contentViewContainer.position.y;

2
MaterialGraphProject/Assets/NewUI/Editor/Utils/PainterExtensions.cs


static class PainterExtensions
{
// todo arguably the transform should be on context already
public static void DrawRectangleOutline(this PaintContext pc, Matrix4x4 transform, Rect rectangle, Color outlineColor)
public static void DrawRectangleOutline(this IStylePainter painter, Matrix4x4 transform, Rect rectangle, Color outlineColor)
{
Vector3[] verts =
{

12
MaterialGraphProject/Assets/NewUI/Editor/Utils/RectUtils.cs


using System;
using UnityEngine;
namespace RMGUI.GraphView

}
return true;
}
public static Rect Encompass(Rect a, Rect b)
{
return new Rect
{
xMin = Math.Min(a.xMin, b.xMin),
yMin = Math.Min(a.yMin, b.yMin),
xMax = Math.Max(a.xMax, b.xMax),
yMax = Math.Max(a.yMax, b.yMax)
};
}
}
}

4
MaterialGraphProject/Assets/NewUI/Editor/Utils/UIHelpers.cs


using System.Reflection;
using UnityEditor;
using System.Linq;
namespace RMGUI.GraphView
{

{
if (s_ApplyWireMaterialMi == null)
{
var methods = typeof(HandleUtility).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
s_ApplyWireMaterialMi = methods.First(o => o.Name == "ApplyWireMaterial" && o.GetGenericArguments().Count() == 0);
s_ApplyWireMaterialMi = typeof(HandleUtility).GetMethod("ApplyWireMaterial", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
}
if (s_ApplyWireMaterialMi != null)

42
MaterialGraphProject/Assets/NewUI/Editor/Views/Data/GraphViewDataSource.cs


namespace RMGUI.GraphView
{
[Serializable]
public abstract class GraphViewDataSource : ScriptableObject, IGraphElementDataSource
{
[SerializeField]
private List<GraphElementData> m_Elements = new List<GraphElementData>();
[Serializable]
public abstract class GraphViewDataSource : ScriptableObject, IGraphElementDataSource
{
[SerializeField]
private List<GraphElementData> m_Elements = new List<GraphElementData>();
public IEnumerable<GraphElementData> elements
{
get { return m_Elements; }
}
public IEnumerable<GraphElementData> elements
{
get { return m_Elements; }
}
public void AddElement(GraphElementData element)
{
m_Elements.Add(element);
}
public void AddElement(GraphElementData element)
{
m_Elements.Add(element);
}
public void RemoveElement(GraphElementData element)
{
m_Elements.RemoveAll(x => x == element);
}
public void RemoveElement(GraphElementData element)
{
m_Elements.RemoveAll(x => x == element);
}
protected void OnEnable()
{
}
}
protected void OnEnable()
{
}
}
}

213
MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace RMGUI.GraphView
{
[StyleSheet("Assets/NewUI/Editor/Views/GraphView.uss")]
[StyleSheet("Assets/Editor/Views/GraphView.uss")]
public abstract class GraphView : DataWatchContainer, ISelection
{
private IGraphElementDataSource m_DataSource;

get { return this; }
}
readonly ClassList m_ElementsClassList = new ClassList("graphElement");
bool m_FrameAnimate = false;
public enum FrameType
{
All = 0,
Selection = 1,
Origin = 2
}
protected GraphView()
{

}
newElem.SetPosition(elementData.position);
newElem.classList = m_ElementsClassList;
newElem.dataProvider = elementData;
if ((elementData.capabilities & Capabilities.Resizable) != 0)

contentViewContainer.AddChild(newElem);
else
AddChild(newElem);
}
protected EventPropagation DeleteSelection()
{
// and DeleteSelection would call that method.
var nodesContentViewData = dataSource as GraphViewDataSource;
if (nodesContentViewData == null)
return EventPropagation.Stop;
var elementsToRemove = new HashSet<GraphElementData>();
foreach (var selectedElement in selection.Cast<GraphElement>()
.Where(e => e != null && e.dataProvider != null))
{
if ((selectedElement.dataProvider.capabilities & Capabilities.Deletable) == 0)
continue;
elementsToRemove.Add(selectedElement.dataProvider);
var connectorColl = selectedElement.dataProvider as IConnectorCollection;
if (connectorColl == null)
continue;
elementsToRemove.UnionWith(connectorColl.inputConnectors.SelectMany(c => c.connections)
.Cast<GraphElementData>()
.Where(d => (d.capabilities & Capabilities.Deletable) != 0));
elementsToRemove.UnionWith(connectorColl.outputConnectors.SelectMany(c => c.connections)
.Cast<GraphElementData>()
.Where(d => (d.capabilities & Capabilities.Deletable) != 0));
}
// Notify the ends of connections that the connection is going way.
foreach (var connection in elementsToRemove.OfType<IConnection>())
{
if (connection.output != null)
{
connection.output.Disconnect(connection);
}
if (connection.input != null)
{
connection.input.Disconnect(connection);
}
}
foreach (var b in elementsToRemove)
nodesContentViewData.RemoveElement(b);
return EventPropagation.Stop;
}
protected EventPropagation FrameAll()
{
return Frame(FrameType.All);
}
protected EventPropagation FrameSelection()
{
return Frame(FrameType.Selection);
}
protected EventPropagation FrameOrigin()
{
return Frame(FrameType.Origin);
}
EventPropagation Frame(FrameType frameType)
{
// Reset container translation, scale and position
contentViewContainer.transform *= contentViewContainer.transform.inverse;
Rect p = contentViewContainer.position;
p.x = 0;
p.y = 0;
contentViewContainer.position = p;
if (frameType == FrameType.Origin)
{
return EventPropagation.Stop;
}
Rect rectToFit = contentViewContainer.position;
if (frameType == FrameType.Selection)
{
// Now calculate rectangle to fit all selected elements
if (selection.Count == 0)
{
return EventPropagation.Continue;
}
var graphElement = selection[0] as GraphElement;
if (graphElement != null)
{
rectToFit = graphElement.localBound;
}
rectToFit = selection.OfType<GraphElement>()
.Aggregate(rectToFit, (current, e) => RectUtils.Encompass(current, e.localBound));
}
else /*if (frameType == FrameType.All)*/
{
bool reachedFirstChild = false;
foreach (VisualElement child in contentViewContainer.children)
{
var graphElement = child as GraphElement;
if (graphElement == null ||
(graphElement.dataProvider.capabilities & Capabilities.Floating) != 0 ||
(graphElement.dataProvider is EdgeData))
{
continue;
}
if (!reachedFirstChild)
{
rectToFit = graphElement.localBound;
reachedFirstChild = true;
}
else
{
rectToFit = RectUtils.Encompass(rectToFit, graphElement.localBound);
}
}
}
Vector3 frameTranslation;
Vector3 frameScaling;
CalculateFrameTransform(rectToFit, out frameTranslation, out frameScaling);
if (m_FrameAnimate)
{
// TODO Animate framing
// RMAnimation animation = new RMAnimation();
// parent.Animate(parent)
// .Lerp(new string[] {"m_Scale", "m_Translation"},
// new object[] {parent.scale, parent.translation},
// new object[] {frameScaling, frameTranslation}, 0.08f);
}
else
{
Matrix4x4 t = Matrix4x4.identity;
t *= Matrix4x4.TRS(frameTranslation, Quaternion.identity, frameScaling);
contentViewContainer.transform = t;
}
contentViewContainer.Touch(ChangeType.Repaint);
return EventPropagation.Stop;
}
void CalculateFrameTransform(Rect rectToFit, out Vector3 frameTranslation, out Vector3 frameScaling)
{
// Give it full width/height
Rect clientRect = position;
// bring slightly smaller screen rect into GUI space
var screenRect = new Rect
{
xMin = 30,
xMax = clientRect.width - 30,
yMin = 30,
yMax = clientRect.height - 30
};
Matrix4x4 m = GUI.matrix;
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);
Rect identity = GUIUtility.ScreenToGUIRect(screenRect);
// measure zoom level necessary to fit the canvas rect into the screen rect
float zoomLevel = Math.Min(identity.width / rectToFit.width, identity.height / rectToFit.height);
// clamp
zoomLevel = Mathf.Clamp(zoomLevel, 0.08f, 1.0f);
var cachedScale = new Vector3(transform.GetColumn(0).magnitude,
transform.GetColumn(1).magnitude,
transform.GetColumn(2).magnitude);
Vector4 cachedTranslation = transform.GetColumn(3);
transform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(zoomLevel, zoomLevel, 1.0f));
var edge = new Vector2(clientRect.width, clientRect.height);
var origin = new Vector2(0, 0);
var r = new Rect
{
min = origin,
max = edge
};
var parentScale = new Vector3(transform.GetColumn(0).magnitude,
transform.GetColumn(1).magnitude,
transform.GetColumn(2).magnitude);
Vector2 offset = r.center - (rectToFit.center * parentScale.x);
// Update output values before leaving
frameTranslation = new Vector3(offset.x, offset.y, 0.0f);
frameScaling = parentScale;
transform = Matrix4x4.TRS(cachedTranslation, Quaternion.identity, cachedScale);
GUI.matrix = m;
}
}
}

13
MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss


/* this class is added to all graphElement instances*/
.graphElement {
text-alignment:upper-center;
text-color:#FFF;
/* currently border-XXX is only used for layout
where border-width is used to paint text and border.
They must keep in sync until we support variable border
thickness per edge */
border-width: 2;
border-radius: 5;
background-color: #333;
.graphElement.selected {
border-color: #FF0;
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/NodePreviewDrawer.cs


public NodePreviewDrawer() {}
public override void DoRepaint(PaintContext args)
public override void DoRepaint(IStylePainter args)
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs


using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using UnityEngine.RMGUI;
using Edge = RMGUI.GraphView.Edge;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph.Drawing

dataMapper[typeof(MaterialNodeDrawData)] = typeof(MaterialNodeDrawer);
dataMapper[typeof(NodeAnchorData)] = typeof(NodeAnchor);
dataMapper[typeof(EdgeData)] = typeof(RMGUI.GraphView.Edge);
dataMapper[typeof(EdgeData)] = typeof(Edge);
var dictionary = new Dictionary<Event, ShortcutDelegate>();
dictionary[Event.KeyboardEvent("^F1")] = Export;

2
MaterialGraphProject/MaterialGraphProject.sln.DotSettings.user


<s:String x:Key="/Default/Environment/ContinuousTesting/PersistentDataLocation/@EntryValue">C:\Users\Tim\AppData\Local\Temp\JetBrains\ContinuousTesting\7e95cb10-f230-442a-ba1f-a26bdb4193cb</s:String>
<s:String x:Key="/Default/Environment/ContinuousTesting/ScopeCriterion/@EntryValue">9b0nIQIAAACJbLoh9b0nIQIAAADP4jFoJAAAADwATQBhAHQAZQByAGkAYQBsAEcAcgBhAHAAaABQAHIAbwBqAGUAYwB0AC4AQwBTAGgAYQByAHAALgBFAGQAaQB0AG8AcgA+AC0AAABDADoAXABjAG8AZABlAFwATQBhAHQAZQByAGkAYQBsAEcAcgBhAHAAaABHAGkAdABcAE0AYQB0AGUAcgBpAGEAbABHAHIAYQBwAGgAUAByAG8AagBlAGMAdAA4rDtD+4tkDSUAAABVAG4AaQB0AHkARQBkAGkAdABvAHIALgBHAHIAYQBwAGgAaQBuAGcALgBJAG4AdABlAGcAcgBhAHQAaQBvAG4AVABlAHMAdABzAA==</s:String>
<s:String x:Key="/Default/Environment/ContinuousTesting/SnapshotLocation/@EntryValue">C:\Users\Tim\AppData\Local\Temp\ssm.Gazizer.tmp</s:String>
<s:String x:Key="/Default/Environment/ContinuousTesting/SnapshotLocation/@EntryValue">C:\Users\Tim\AppData\Local\Temp\ssm.Cuvulyq.tmp</s:String>
<s:String x:Key="/Default/Environment/ContinuousTesting/Strategy/@EntryValue">RunTests</s:String>
<s:String x:Key="/Default/Environment/ContinuousTesting/TriggerMode/@EntryValue">OnBuild</s:String></wpf:ResourceDictionary>

4
MaterialGraphProject/Assets/NewUI/Editor/Demo/IMGUISampleViewWindow.cs


namespace RMGUI.GraphView.Demo
{
public class IMGUISampleView : EditorWindow
public class IMGUISampleViewWindow : EditorWindow
GetWindow<IMGUISampleView>();
GetWindow<IMGUISampleViewWindow>();
}
void OnEnable()

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators.meta


fileFormatVersion: 2
guid: 49d342e281c5c0842a37adc523aca716
folderAsset: yes
timeCreated: 1477989669
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

21
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.imported.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 11997, guid: 0000000000000000e000000000000000, type: 0}
m_Name: SerializableGraph.uss.imported
m_EditorClassIdentifier:
matchers: []
rules: []
floats: []
ints:
bools:
colors: []
strings: []
assets: []

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.imported.asset.meta


fileFormatVersion: 2
guid: 710b4b6fb4db58f47aeb6fec7fd76bb4
timeCreated: 1477986144
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewUI/Editor/Demo/GraphElements.meta


fileFormatVersion: 2
guid: 0cabc6d3555773b46ac210aaf8eefae6
folderAsset: yes
timeCreated: 1475167728
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/IMGUISampleViewWindow.cs.meta


fileFormatVersion: 2
guid: 5e9dcbce78a4af54c9c6fcf17f7df043
timeCreated: 1476306591
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

30
MaterialGraphProject/Assets/NewUI/Editor/Demo/NodalViewWindow.cs


using UnityEditor;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
class NodalViewWindow : EditorWindow
{
[MenuItem("Window/GraphView Demo/Nodal UI")]
public static void ShowWindow()
{
GetWindow<NodalViewWindow>();
}
void OnEnable()
{
var view = new NodesContentView
{
name = "theView",
dataSource = CreateInstance<NodesContentViewData>()
};
view.StretchToParentSize();
windowRoot.AddChild(view);
}
void OnDisable()
{
windowRoot.ClearChildren();
}
}
}

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/NodalViewWindow.cs.meta


fileFormatVersion: 2
guid: c8ac803e6ded75a4da20fc93645785fe
timeCreated: 1476306235
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

30
MaterialGraphProject/Assets/NewUI/Editor/Demo/SimpleGraphViewWindow.cs


using UnityEditor;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
public class SimpleGraphViewWindow : EditorWindow
{
[MenuItem("Window/GraphView Demo/SimpleGraphView")]
public static void ShowWindow()
{
GetWindow<SimpleGraphViewWindow>();
}
void OnEnable()
{
var view = new SimpleContentView
{
name = "theView",
dataSource = CreateInstance<SimpleContentViewData>()
};
view.StretchToParentSize();
windowRoot.AddChild(view);
}
void OnDisable()
{
windowRoot.ClearChildren();
}
}
}

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/SimpleGraphViewWindow.cs.meta


fileFormatVersion: 2
guid: 379573e86758eed46a980eb015c1170a
timeCreated: 1476305948
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/NodesContentViewData.cs.meta


fileFormatVersion: 2
guid: eb4c913a7ca37cc4789fb8d87a1eee96
timeCreated: 1476306362
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/SimpleContentViewData.cs.meta


fileFormatVersion: 2
guid: 7e0d569658b0b934d9cd393bd4a1dfcb
timeCreated: 1476306071
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

21
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.uss.imported.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 11997, guid: 0000000000000000e000000000000000, type: 0}
m_Name: NodalView.uss.imported
m_EditorClassIdentifier:
matchers: []
rules: []
floats: []
ints:
bools:
colors: []
strings: []
assets: []

8
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.uss.imported.asset.meta


fileFormatVersion: 2
guid: ae904e6b00e321143b960221024f7fc3
timeCreated: 1477985626
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

45
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodesContentView.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[StyleSheet("Assets/Editor/Demo/Views/NodalView.uss")]
class NodesContentView : SimpleContentView
{
private readonly System.Random rnd = new System.Random();
public NodesContentView()
{
// Contextual menu to create new nodes
AddManipulator(new ContextualMenu((evt, customData) =>
{
var menu = new GenericMenu();
menu.AddItem(new GUIContent("Create Operator"), false,
contentView => CreateOperator(),
this);
menu.ShowAsContext();
return EventPropagation.Continue;
}));
dataMapper[typeof(CustomEdgeData)] = typeof(CustomEdge);
dataMapper[typeof(NodeAnchorData)] = typeof(NodeAnchor);
dataMapper[typeof(NodeData)] = typeof(Node);
dataMapper[typeof(VerticalNodeData)] = typeof(Node);
}
public void CreateOperator()
{
var nodalViewData = dataSource as NodesContentViewData;
if (nodalViewData != null)
{
var x = rnd.Next(0, 600);
var y = rnd.Next(0, 300);
nodalViewData.CreateOperator(typeof(Vector3), new Rect(x, y, 200, 176), "Shiny New Operator");
}
}
}
}

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodesContentView.cs.meta


fileFormatVersion: 2
guid: 1a2310fa1650dda408c99ce9fbc96823
timeCreated: 1476306442
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

21
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss.imported.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 11997, guid: 0000000000000000e000000000000000, type: 0}
m_Name: SimpleContentView.uss.imported
m_EditorClassIdentifier:
matchers: []
rules: []
floats: []
ints:
bools:
colors: []
strings: []
assets: []

8
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss.imported.asset.meta


fileFormatVersion: 2
guid: fbe164d03ec59254eafe10baa5a9c5ba
timeCreated: 1477985626
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewUI/Editor/Graph.meta


fileFormatVersion: 2
guid: b72798efa4aa8574ca0cbdfa63df0b7a
folderAsset: yes
timeCreated: 1475177616
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewUI/Editor/GraphElements.meta


fileFormatVersion: 2
guid: ebb7c69d632722145a1f9d838e7fe6ef
folderAsset: yes
timeCreated: 1475161005
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewUI/Editor/GraphElementsData.meta


fileFormatVersion: 2
guid: 3b224150c99d250429c73b1eefe3dd83
folderAsset: yes
timeCreated: 1475161005
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

8
MaterialGraphProject/Assets/NewUI/Editor/IConnection.cs


namespace RMGUI.GraphView
{
public interface IConnection
{
IConnector output { get; set; }
IConnector input { get; set; }
}
}

12
MaterialGraphProject/Assets/NewUI/Editor/IConnection.cs.meta


fileFormatVersion: 2
guid: 04174a63fbb784b41b463d460c7f6646
timeCreated: 1476901947
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

28
MaterialGraphProject/Assets/NewUI/Editor/IConnector.cs


using System.Collections.Generic;
namespace RMGUI.GraphView
{
public interface IConnector
{
Direction direction { get; }
Orientation orientation { get; }
bool highlight { get; set; }
object source { get; }
bool connected { get; }
IEnumerable<IConnection> connections { get; }
void Connect(IConnection connection);
void Disconnect(IConnection connection);
// TODO YAGNI?
// void DisconnectAll();
}
public static class ConnectableExtensions
{
public static bool IsConnectable(this IConnector connector)
{
return connector.direction == Direction.Output || !connector.connected;
}
}
}

10
MaterialGraphProject/Assets/NewUI/Editor/IConnectorCollection.cs


using System.Collections.Generic;
namespace RMGUI.GraphView
{
interface IConnectorCollection
{
IEnumerable<IConnector> inputConnectors { get; }
IEnumerable<IConnector> outputConnectors { get; }
}
}

12
MaterialGraphProject/Assets/NewUI/Editor/IConnectorCollection.cs.meta


fileFormatVersion: 2
guid: b6d217dbc1a50fb42acaf0953390d89b
timeCreated: 1477331007
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/KeyModifiers.cs


using System;
namespace RMGUI.GraphView
{
// TODO We could move that higher in RMGUI.
[Flags]
public enum KeyModifiers
{
None = 0,
Alt = 1 << 0,
Ctrl = 1 << 1,
Shift = 1 << 2,
Command = 1 << 3
}
}

12
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/KeyModifiers.cs.meta


fileFormatVersion: 2
guid: 393dfbb2f04c7a743b1ca4214b60bda4
timeCreated: 1476929682
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

50
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/MouseManipulator.cs


using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView
{
public class MouseManipulator : Manipulator
{
public MouseButton activateButton { get; set; }
public KeyModifiers activateModifiers { get; set; }
public bool CanStartManipulation(Event evt)
{
if (evt.button != (int) activateButton)
{
return false;
}
if (((activateModifiers & KeyModifiers.Alt) != 0 && !evt.alt) ||
((activateModifiers & KeyModifiers.Alt) == 0 && evt.alt))
{
return false;
}
if (((activateModifiers & KeyModifiers.Ctrl) != 0 && !evt.control) ||
((activateModifiers & KeyModifiers.Ctrl) == 0 && evt.control))
{
return false;
}
if (((activateModifiers & KeyModifiers.Shift) != 0 && !evt.shift) ||
((activateModifiers & KeyModifiers.Shift) == 0 && evt.shift))
{
return false;
}
if (((activateModifiers & KeyModifiers.Command) != 0 && !evt.command) ||
((activateModifiers & KeyModifiers.Command) == 0 && evt.command))
{
return false;
}
return true;
}
public bool CanStopManipulation(Event evt)
{
return (evt.button == (int)activateButton && this.HasCapture());
}
}
}

12
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/MouseManipulator.cs.meta


fileFormatVersion: 2
guid: 33e273b33871e6e4180c7a94739c79e2
timeCreated: 1476901948
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

21
MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss.imported.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 11997, guid: 0000000000000000e000000000000000, type: 0}
m_Name: GraphView.uss.imported
m_EditorClassIdentifier:
matchers: []
rules: []
floats: []
ints:
bools:
colors: []
strings: []
assets: []

8
MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss.imported.asset.meta


fileFormatVersion: 2
guid: 1655c36f61ec5a5499f7dc1f3abea03c
timeCreated: 1477985626
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/PropertyNodeDrawData.cs.meta


fileFormatVersion: 2
guid: eaa1f14b82a26aa49b8a51ce08653c87
timeCreated: 1477985625
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

21
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss.imported.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 11997, guid: 0000000000000000e000000000000000, type: 0}
m_Name: MaterialGraph.uss.imported
m_EditorClassIdentifier:
matchers: []
rules: []
floats: []
ints:
bools:
colors: []
strings: []
assets: []

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss.imported.asset.meta


fileFormatVersion: 2
guid: 13814e9314253674e8d4966bba14d963
timeCreated: 1477986144
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

150
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/EdgeConnector.cs


using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using RMGUI.GraphView;
using UnityEngine.RMGUI;
namespace UnityEditor.Graphing.Drawing
{
public class EdgeConnector<TEdgeData> : MouseManipulator where TEdgeData : EdgeData
{
private readonly List<IConnector> m_CompatibleAnchors = new List<IConnector>();
private TEdgeData m_EdgeDataCandidate;
private AbstractGraphDataSource m_DataSource;
private SerializableGraphView m_GraphView;
public EdgeConnector()
{
activateButton = MouseButton.LeftMouse;
}
public override EventPropagation HandleEvent(Event evt, VisualElement finalTarget)
{
switch (evt.type)
{
case EventType.MouseDown:
{
if (!CanStartManipulation(evt))
break;
IConnector cnx = null;
var graphElement = finalTarget as GraphElement;
if (graphElement != null && graphElement.dataProvider != null)
{
GraphElementData data = graphElement.dataProvider;
cnx = (IConnector) data;
m_GraphView = graphElement.GetFirstAncestorOfType<SerializableGraphView>();
}
if (cnx == null || m_GraphView == null)
break;
m_DataSource = m_GraphView.dataSource as AbstractGraphDataSource;
if (m_DataSource == null)
break;
this.TakeCapture();
m_CompatibleAnchors.Clear();
var nodeAdapter = new NodeAdapter();
// get all available connectors
foreach (var toCnx in m_GraphView.allChildren.OfType<GraphElement>()
.Select(e => e.dataProvider)
.OfType<IConnector>()
.Where(c => c.IsConnectable() &&
c.orientation == cnx.orientation &&
c.direction != cnx.direction &&
nodeAdapter.GetAdapter(c.source, cnx.source) != null))
{
toCnx.highlight = true;
m_CompatibleAnchors.Add(toCnx);
}
m_EdgeDataCandidate = ScriptableObject.CreateInstance<TEdgeData>();
m_EdgeDataCandidate.position = new Rect(0, 0, 1, 1);
bool startFromOutput = (cnx.direction == Direction.Output);
if (startFromOutput)
{
m_EdgeDataCandidate.output = graphElement.dataProvider as IConnector;
m_EdgeDataCandidate.input = null;
}
else
{
m_EdgeDataCandidate.output = null;
m_EdgeDataCandidate.input = graphElement.dataProvider as IConnector;
}
m_EdgeDataCandidate.candidate = true;
m_EdgeDataCandidate.candidatePosition = target.LocalToGlobal(evt.mousePosition);
m_DataSource.AddTempElement(m_EdgeDataCandidate);
return EventPropagation.Stop;
}
case EventType.MouseDrag:
{
if (this.HasCapture())
{
m_EdgeDataCandidate.candidatePosition = target.LocalToGlobal(evt.mousePosition);
return EventPropagation.Stop;
}
break;
}
case EventType.MouseUp:
{
if (CanStopManipulation(evt))
{
this.ReleaseCapture();
IConnector endConnector = null;
foreach (var compatibleAnchor in m_CompatibleAnchors)
{
compatibleAnchor.highlight = false;
if (m_GraphView != null)
{
GraphElement anchorElement = m_GraphView.allElements.OfType<GraphElement>().First(e => e.dataProvider == (Object) compatibleAnchor);
if (anchorElement != null)
{
if (anchorElement.globalBound.Contains(target.LocalToGlobal(evt.mousePosition)))
endConnector = compatibleAnchor;
}
}
}
m_CompatibleAnchors.Clear();
m_DataSource.RemoveElement(m_EdgeDataCandidate);
if (m_EdgeDataCandidate != null && m_DataSource != null && endConnector != null)
{
if (m_EdgeDataCandidate.output == null)
m_EdgeDataCandidate.output = endConnector;
else
m_EdgeDataCandidate.input = endConnector;
m_EdgeDataCandidate.output.Connect(m_EdgeDataCandidate);
m_EdgeDataCandidate.input.Connect(m_EdgeDataCandidate);
m_EdgeDataCandidate.candidate = false;
m_DataSource.Connect(m_EdgeDataCandidate.output as AnchorDrawData, m_EdgeDataCandidate.input as AnchorDrawData);
}
m_EdgeDataCandidate = null;
m_DataSource = null;
return EventPropagation.Stop;
}
break;
}
}
return this.HasCapture() ? EventPropagation.Stop : EventPropagation.Continue;
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/EdgeConnector.cs.meta


fileFormatVersion: 2
guid: 83cddc79cb2953340bedd94abe783859
timeCreated: 1477989690
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewUI/Editor/Demo/GraphElements/Graph.meta


fileFormatVersion: 2
guid: f22bdd0720b76fb49a1a7d2461de982b
folderAsset: yes
timeCreated: 1475171334
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewUI/Editor/Demo/GraphElements/Nodes.meta


fileFormatVersion: 2
guid: 6f374239aa4eb8e46a84b48479605054
folderAsset: yes
timeCreated: 1475168121
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewUI/Editor/Graph/GraphElements.meta


fileFormatVersion: 2
guid: ea648af0e8d33db40905fd11df263507
folderAsset: yes
timeCreated: 1475177616
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewUI/Editor/GraphElements/Graph.meta


fileFormatVersion: 2
guid: 0fc31b1e188fa674d9c15b26b2598692
folderAsset: yes
timeCreated: 1475161005
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/NodalViewData.cs.meta


fileFormatVersion: 2
guid: 6c7c91c667833a44d9d99a3c770415a5
timeCreated: 1475574874
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/SimpleGraphViewData.cs.meta


fileFormatVersion: 2
guid: b612cdd5d670cb04584099036d9a406d
timeCreated: 1476281662
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/IMGUISampleView.cs.meta


fileFormatVersion: 2
guid: c02b6a0dca1c1944f88627c5f42a7224
timeCreated: 1475574875
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.cs.meta


fileFormatVersion: 2
guid: d9a9a164bccdbe24590cfb3ae713eb7f
timeCreated: 1475574876
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

31
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleGraphView.cs


using UnityEditor;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
public class SimpleGraphView : EditorWindow
{
[MenuItem("Window/GraphView Demo/SimpleGraphView")]
public static void ShowWindow()
{
GetWindow<SimpleGraphView>();
}
void OnEnable()
{
var view = new SimpleContentView
{
name = "theView",
dataSource = CreateInstance<SimpleGraphViewData>()
};
view.StretchToParentSize();
windowRoot.AddChild(view);
}
void OnDisable()
{
windowRoot.ClearChildren();
}
}
}

12
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleGraphView.cs.meta


fileFormatVersion: 2
guid: fd46fb73aba17cf4984eec066df288e2
timeCreated: 1475574876
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存