浏览代码

Fix drawers.

/main
Tim Cooper 8 年前
当前提交
a9948aa0
共有 29 个文件被更改,包括 1123 次插入1122 次删除
  1. 5
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs
  2. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphNode.cs
  3. 10
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeData.cs
  4. 6
      MaterialGraphProject/Assets/NewUI/Editor/CustomDataView.cs
  5. 81
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Circle.cs
  6. 55
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/CircleData.cs
  7. 35
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/IMGUIData.cs
  8. 19
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/InvisibleBorderContainerData.cs
  9. 47
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/MiniMapData.cs
  10. 33
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/SimpleElementData.cs
  11. 27
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/WWWImageData.cs
  12. 79
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/CustomEdge.cs
  13. 19
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Data/CustomEdgeData.cs
  14. 131
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Data/NodeAnchorData.cs
  15. 117
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Data/NodeData.cs
  16. 55
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Data/VerticalNodeData.cs
  17. 93
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Node.cs
  18. 1
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/NodeAnchor.cs
  19. 113
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/VerticalNode.cs
  20. 70
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/IMGUIElement.cs
  21. 1
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/InvisibleBorderContainer.cs
  22. 405
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/MiniMap.cs
  23. 61
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/SimpleElement.cs
  24. 131
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/WWWImage.cs
  25. 3
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/IMGUISampleViewData.cs
  26. 157
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/SimpleGraphView.cs
  27. 39
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Data/EdgeData.cs
  28. 449
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Edge.cs
  29. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Styles/NodalView.uss

5
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs


var targetAnchors = targetNode.elements.OfType<MaterialNodeAnchorData>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
drawableEdges.Add(new EdgeData {left = sourceAnchor, right = targetAnchor});
var edgeData = ScriptableObject.CreateInstance<EdgeData>();
edgeData.left = sourceAnchor;
edgeData.right = targetAnchor;
drawableEdges.Add(edgeData);
}
}
}

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


}
[GUISkinStyle("window")]
[CustomDataView(typeof(MaterialNodeData))]
[CustomDataView(typeof(ColorNodeData))]
public class MaterialGraphNode : GraphElement
{
VisualContainer m_SlotContainer;

10
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeData.cs


namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public class ColorNodeData : MaterialNodeData
[CustomDataView(typeof(MaterialGraphNode))]
public class ColorNodeData : MaterialNodeData
{
class ColorNodeContolData : NodeControlData
{

protected override IEnumerable<NodeControlData> GetControlData()
{
return new List<NodeControlData> {new ColorNodeContolData()};
return new List<NodeControlData> { CreateInstance<ColorNodeContolData>() };
public class MaterialNodeData : GraphElementData
[CustomDataView(typeof(MaterialGraphNode))]
public class MaterialNodeData : GraphElementData
public IEnumerable<GraphElementData> elements
public override IEnumerable<GraphElementData> elements
{
get { return m_Children; }
}

6
MaterialGraphProject/Assets/NewUI/Editor/CustomDataView.cs


// map of [datType, viewType]
private static Dictionary<Type, Type> s_TypeMap;
public static DataContainer<GraphElementData> Create(GraphElementData data)
public static GraphElement Create(GraphElementData data)
{
if (s_TypeMap == null)
{

var attributes = type.GetCustomAttributes(typeof(CustomDataView), false);
foreach (CustomDataView att in attributes)
{
s_TypeMap[att.dataType] = type;
s_TypeMap[type] = att.dataType;
}
}
}

if (s_TypeMap.TryGetValue(data.GetType(), out viewType))
{
var dataContainer = (DataContainer<GraphElementData>)Activator.CreateInstance(viewType);
var dataContainer = (GraphElement)Activator.CreateInstance(viewType);
dataContainer.dataProvider = data;
return dataContainer;
}

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


using UnityEditor;
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[CustomDataView(typeof(CircleData))]
public class Circle : GraphElement
{
public override void DoRepaint(PaintContext args)
{
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);
if (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected)
{
Color oldColor = Handles.color;
Handles.color = Color.yellow;
Handles.DrawWireDisc(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+2.0f);
Handles.color = oldColor;
}
}
public override bool ContainsPoint(Vector2 localPoint)
{
return Vector2.Distance(new Vector2(position.width/2, position.height/2), localPoint-position.position) <= position.width / 2.0f;
}
public override bool Overlaps(Rect rectangle)
{
rectangle.position -= position.position;
var radius = position.width / 2.0f;
var p = new Vector2(Mathf.Max(rectangle.x, Mathf.Min(radius, rectangle.xMax)), Mathf.Max(rectangle.y, Mathf.Min(radius, rectangle.yMax)));
return Vector2.Distance(new Vector2(radius, radius), p) <= radius;
}
}
}
using UnityEditor;
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
public class Circle : GraphElement
{
public override void DoRepaint(PaintContext args)
{
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);
if (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected)
{
Color oldColor = Handles.color;
Handles.color = Color.yellow;
Handles.DrawWireDisc(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+2.0f);
Handles.color = oldColor;
}
}
public override bool ContainsPoint(Vector2 localPoint)
{
return Vector2.Distance(new Vector2(position.width/2, position.height/2), localPoint-position.position) <= position.width / 2.0f;
}
public override bool Overlaps(Rect rectangle)
{
rectangle.position -= position.position;
var radius = position.width / 2.0f;
var p = new Vector2(Mathf.Max(rectangle.x, Mathf.Min(radius, rectangle.xMax)), Mathf.Max(rectangle.y, Mathf.Min(radius, rectangle.yMax)));
return Vector2.Distance(new Vector2(radius, radius), p) <= radius;
}
}
}

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


using System;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{
[Serializable]
public class CircleData : GraphElementData
{
[SerializeField]
private float m_Radius;
public float radius
{
get { return m_Radius; }
set
{
if (m_Radius == value) return;
m_Radius = value;
// Now update the position
Rect newPos = position;
newPos.width = m_Radius;
newPos.height = m_Radius;
position = newPos;
}
}
}
}
using System;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{
[Serializable]
[CustomDataView(typeof(Circle))]
public class CircleData : GraphElementData
{
[SerializeField]
private float m_Radius;
public float radius
{
get { return m_Radius; }
set
{
if (m_Radius == value) return;
m_Radius = value;
// Now update the position
Rect newPos = position;
newPos.width = m_Radius;
newPos.height = m_Radius;
position = newPos;
}
}
}
}

35
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/IMGUIData.cs


using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
public class IMGUIData : SimpleElementData
{
public IMGUIData()
{
title = "BaseIMGUI";
}
public virtual void OnGUIHandler()
{
}
}
}
using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
[CustomDataView(typeof(IMGUIElement))]
public class IMGUIData : SimpleElementData
{
public IMGUIData()
{
title = "BaseIMGUI";
}
public virtual void OnGUIHandler()
{
}
}
}

19
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/InvisibleBorderContainerData.cs


using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
public class InvisibleBorderContainerData : GraphElementData
{
}
}
using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
[CustomDataView(typeof(InvisibleBorderContainer))]
public class InvisibleBorderContainerData : GraphElementData
{
}
}

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


using System;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{
[Serializable]
public class MiniMapData : GraphElementData
{
protected new void OnEnable()
{
base.OnEnable();
capabilities = Capabilities.Floating | Capabilities.Movable;
maxWidth = 200;
maxHeight = 200;
}
public float maxHeight;
public float maxWidth;
[SerializeField]
public bool anchored;
}
}
using System;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{
[Serializable]
[CustomDataView(typeof(MiniMap))]
public class MiniMapData : GraphElementData
{
protected new void OnEnable()
{
base.OnEnable();
capabilities = Capabilities.Floating | Capabilities.Movable;
maxWidth = 200;
maxHeight = 200;
}
public float maxHeight;
public float maxWidth;
[SerializeField]
public bool anchored;
}
}

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


using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
public class SimpleElementData : GraphElementData
{
public string title;
protected new void OnEnable()
{
base.OnEnable();
title = "simpleElement";
}
}
}
using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
[CustomDataView(typeof(SimpleElement))]
public class SimpleElementData : GraphElementData
{
public string title;
protected new void OnEnable()
{
base.OnEnable();
title = "simpleElement";
}
}
}

27
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Data/WWWImageData.cs


using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
public class WWWImageData : SimpleElementData
{
public WWWImageData()
{
title = "WWWImage";
}
}
}
using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
[CustomDataView(typeof(WWWImage))]
public class WWWImageData : SimpleElementData
{
public WWWImageData()
{
title = "WWWImage";
}
}
}

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


using UnityEditor;
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[CustomDataView(typeof(CustomEdgeData))]
class CustomEdge : Edge
{
protected override void DrawEdge(PaintContext args)
{
var edgeData = GetData<CustomEdgeData>();
if (edgeData == null)
{
return;
}
IConnectable leftData = edgeData.left;
if (leftData == null)
return;
Vector2 from = Vector2.zero;
Vector2 to = Vector2.zero;
GetFromToPoints(ref from, ref to);
if (edgeData.candidate)
{
Handles.DrawAAPolyLine(15.0f, from, to);
}
else
{
Vector3[] points, tangents;
Orientation orientation = leftData.orientation;
GetTangents(leftData.direction, orientation, from, to, out points, out tangents);
Color edgeColor = (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected) ? Color.yellow : Color.white;
Handles.DrawBezier(points[0], points[1], tangents[0], tangents[1], edgeColor, null, 5f);
}
}
}
}
using UnityEditor;
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
class CustomEdge : Edge
{
protected override void DrawEdge(PaintContext args)
{
var edgeData = GetData<CustomEdgeData>();
if (edgeData == null)
{
return;
}
IConnectable leftData = edgeData.left;
if (leftData == null)
return;
Vector2 from = Vector2.zero;
Vector2 to = Vector2.zero;
GetFromToPoints(ref from, ref to);
if (edgeData.candidate)
{
Handles.DrawAAPolyLine(15.0f, from, to);
}
else
{
Vector3[] points, tangents;
Orientation orientation = leftData.orientation;
GetTangents(leftData.direction, orientation, from, to, out points, out tangents);
Color edgeColor = (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected) ? Color.yellow : Color.white;
Handles.DrawBezier(points[0], points[1], tangents[0], tangents[1], edgeColor, null, 5f);
}
}
}
}

19
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Data/CustomEdgeData.cs


using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
internal class CustomEdgeData : EdgeData
{
}
}
using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
[CustomDataView(typeof(CustomEdge))]
internal class CustomEdgeData : EdgeData
{
}
}

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


using System;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{
[Serializable]
public class NodeAnchorData : GraphElementData, IConnectable
{
protected object m_Source;
public object source
{
get { return m_Source;}
set
{
if (m_Source == value) return;
m_Source = value;
}
}
[SerializeField]
private Direction m_Direction;
public Direction direction
{
get { return m_Direction; }
set { m_Direction = value; }
}
[SerializeField]
private Orientation m_Orientation;
public Orientation orientation
{
get { return m_Orientation; } set { m_Orientation = value; }
}
[SerializeField]
private Type m_Type;
public Type type
{
get { return m_Type; }
set { m_Type = value; }
}
[SerializeField]
private bool m_Highlight;
public bool highlight
{
get { return m_Highlight; }
set { m_Highlight = value; }
}
[SerializeField]
private bool m_Connected;
public bool connected
{
get { return m_Connected; }
set { m_Connected = value; }
}
protected new void OnEnable()
{
base.OnEnable();
m_Type = typeof(object);
}
}
}
using System;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{
[Serializable]
[CustomDataView(typeof(NodeAnchor))]
public class NodeAnchorData : GraphElementData, IConnectable
{
protected object m_Source;
public object source
{
get { return m_Source;}
set
{
if (m_Source == value) return;
m_Source = value;
}
}
[SerializeField]
private Direction m_Direction;
public Direction direction
{
get { return m_Direction; }
set { m_Direction = value; }
}
[SerializeField]
private Orientation m_Orientation;
public Orientation orientation
{
get { return m_Orientation; } set { m_Orientation = value; }
}
[SerializeField]
private Type m_Type;
public Type type
{
get { return m_Type; }
set { m_Type = value; }
}
[SerializeField]
private bool m_Highlight;
public bool highlight
{
get { return m_Highlight; }
set { m_Highlight = value; }
}
[SerializeField]
private bool m_Connected;
public bool connected
{
get { return m_Connected; }
set { m_Connected = value; }
}
protected new void OnEnable()
{
base.OnEnable();
m_Type = typeof(object);
}
}
}

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


using System;
using System.Collections.Generic;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{
[Serializable]
class NodeData : SimpleElementData
{
[SerializeField]
protected List<NodeAnchorData> m_Anchors;
public List<NodeAnchorData> anchors
{
get { return m_Anchors ?? (m_Anchors = new List<NodeAnchorData>()); }
}
// NOTE: This is a demo node. We could have any number of output anchors if we wanted.
public NodeAnchorData outputAnchor;
// TODO make a simple creation function
protected new void OnEnable()
{
base.OnEnable();
if (m_Anchors==null)
m_Anchors = new List<NodeAnchorData>();
// This is a demo version. We could have a ctor that takes in input and output types, etc.
var nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.type = typeof (int);
nodeAnchorData.direction = Direction.Input;
m_Anchors.Add(nodeAnchorData);
nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.type = typeof (float);
nodeAnchorData.direction = Direction.Input;
m_Anchors.Add(nodeAnchorData);
nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.type = typeof (Vector3);
nodeAnchorData.direction = Direction.Input;
m_Anchors.Add(nodeAnchorData);
nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.type = typeof (Texture2D);
nodeAnchorData.direction = Direction.Input;
m_Anchors.Add(nodeAnchorData);
nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.type = typeof (Color);
nodeAnchorData.direction = Direction.Input;
m_Anchors.Add(nodeAnchorData);
outputAnchor = CreateInstance<NodeAnchorData>();
outputAnchor.type = typeof(int);
outputAnchor.direction = Direction.Output; // get rid of direction use styles
}
}
}
using System;
using System.Collections.Generic;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{
[Serializable]
[CustomDataView(typeof(Node))]
class NodeData : SimpleElementData
{
[SerializeField]
protected List<NodeAnchorData> m_Anchors;
public List<NodeAnchorData> anchors
{
get { return m_Anchors ?? (m_Anchors = new List<NodeAnchorData>()); }
}
// NOTE: This is a demo node. We could have any number of output anchors if we wanted.
public NodeAnchorData outputAnchor;
// TODO make a simple creation function
protected new void OnEnable()
{
base.OnEnable();
if (m_Anchors==null)
m_Anchors = new List<NodeAnchorData>();
// This is a demo version. We could have a ctor that takes in input and output types, etc.
var nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.type = typeof (int);
nodeAnchorData.direction = Direction.Input;
m_Anchors.Add(nodeAnchorData);
nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.type = typeof (float);
nodeAnchorData.direction = Direction.Input;
m_Anchors.Add(nodeAnchorData);
nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.type = typeof (Vector3);
nodeAnchorData.direction = Direction.Input;
m_Anchors.Add(nodeAnchorData);
nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.type = typeof (Texture2D);
nodeAnchorData.direction = Direction.Input;
m_Anchors.Add(nodeAnchorData);
nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.type = typeof (Color);
nodeAnchorData.direction = Direction.Input;
m_Anchors.Add(nodeAnchorData);
outputAnchor = CreateInstance<NodeAnchorData>();
outputAnchor.type = typeof(int);
outputAnchor.direction = Direction.Output; // get rid of direction use styles
}
}
}

55
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Graph/Data/VerticalNodeData.cs


using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
class VerticalNodeData : NodeData
{
// this class is useless, make a simple creation function
protected new void OnEnable()
{
base.OnEnable();
m_Anchors.Clear();
var nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.orientation = Orientation.Vertical;
nodeAnchorData.direction = Direction.Input;
nodeAnchorData.type = typeof(float);
m_Anchors.Add(nodeAnchorData);
outputAnchor = CreateInstance<NodeAnchorData>();
outputAnchor.type = typeof (float);
outputAnchor.orientation = Orientation.Vertical;
outputAnchor.direction = Direction.Output;
outputAnchor.type = typeof(float);
}
}
}
using System;
namespace RMGUI.GraphView.Demo
{
[Serializable]
[CustomDataView(typeof(VerticalNode))]
class VerticalNodeData : NodeData
{
// this class is useless, make a simple creation function
protected new void OnEnable()
{
base.OnEnable();
m_Anchors.Clear();
var nodeAnchorData = CreateInstance<NodeAnchorData>();
nodeAnchorData.orientation = Orientation.Vertical;
nodeAnchorData.direction = Direction.Input;
nodeAnchorData.type = typeof(float);
m_Anchors.Add(nodeAnchorData);
outputAnchor = CreateInstance<NodeAnchorData>();
outputAnchor.type = typeof (float);
outputAnchor.orientation = Orientation.Vertical;
outputAnchor.direction = Direction.Output;
outputAnchor.type = typeof(float);
}
}
}

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


using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[CustomDataView(typeof(NodeData))]
class Node : SimpleElement
{
VisualContainer m_InputContainer;
VisualContainer m_OutputContainer;
public override void OnDataChanged()
{
base.OnDataChanged();
m_OutputContainer.ClearChildren();
m_InputContainer.ClearChildren();
var nodeData = dataProvider as NodeData;
if (nodeData != null)
{
foreach (var anchorData in nodeData.anchors)
{
m_InputContainer.AddChild(new NodeAnchor(anchorData));
}
m_OutputContainer.AddChild(new NodeAnchor(nodeData.outputAnchor));
}
}
public Node()
{
m_InputContainer = new VisualContainer
{
name = "input", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_OutputContainer = new VisualContainer
{
name = "output", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
AddChild(m_InputContainer);
AddChild(m_OutputContainer);
}
}
}
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
class Node : SimpleElement
{
VisualContainer m_InputContainer;
VisualContainer m_OutputContainer;
public override void OnDataChanged()
{
base.OnDataChanged();
m_OutputContainer.ClearChildren();
m_InputContainer.ClearChildren();
var nodeData = dataProvider as NodeData;
if (nodeData != null)
{
foreach (var anchorData in nodeData.anchors)
{
m_InputContainer.AddChild(new NodeAnchor(anchorData));
}
m_OutputContainer.AddChild(new NodeAnchor(nodeData.outputAnchor));
}
}
public Node()
{
m_InputContainer = new VisualContainer
{
name = "input", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_OutputContainer = new VisualContainer
{
name = "output", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
AddChild(m_InputContainer);
AddChild(m_OutputContainer);
}
}
}

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


namespace RMGUI.GraphView.Demo
{
[CustomDataView(typeof(NodeAnchorData))]
internal class NodeAnchor : GraphElement
{
public const float k_NodeSize = 15.0f;

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


using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[GUISkinStyle("box")]
[CustomDataView(typeof(VerticalNodeData))]
class VerticalNode : GraphElement
{
readonly VisualContainer m_ContainerTop;
readonly VisualContainer m_ContainerBottom;
public VerticalNode()
{
m_ContainerTop = new VisualContainer
{
name = "top",
pickingMode = PickingMode.Ignore
};
m_ContainerBottom = new VisualContainer
{
name = "bottom",
pickingMode = PickingMode.Ignore
};
AddChild(m_ContainerTop);
AddChild(m_ContainerBottom);
}
public override void DoRepaint(PaintContext painter)
{
base.DoRepaint(painter);
if (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected)
{
painter.DrawRectangleOutline(transform, position, Color.yellow);
}
}
public override void OnDataChanged()
{
base.OnDataChanged();
m_ContainerTop.ClearChildren();
m_ContainerBottom.ClearChildren();
var nodeData = dataProvider as VerticalNodeData;
if (nodeData != null)
{
foreach (var anchorData in nodeData.anchors)
{
m_ContainerTop.AddChild(new NodeAnchor(anchorData));
}
m_ContainerBottom.AddChild(new NodeAnchor(nodeData.outputAnchor));
}
}
}
}
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[GUISkinStyle("box")]
class VerticalNode : GraphElement
{
readonly VisualContainer m_ContainerTop;
readonly VisualContainer m_ContainerBottom;
public VerticalNode()
{
m_ContainerTop = new VisualContainer
{
name = "top",
pickingMode = PickingMode.Ignore
};
m_ContainerBottom = new VisualContainer
{
name = "bottom",
pickingMode = PickingMode.Ignore
};
AddChild(m_ContainerTop);
AddChild(m_ContainerBottom);
}
public override void DoRepaint(PaintContext painter)
{
base.DoRepaint(painter);
if (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected)
{
painter.DrawRectangleOutline(transform, position, Color.yellow);
}
}
public override void OnDataChanged()
{
base.OnDataChanged();
m_ContainerTop.ClearChildren();
m_ContainerBottom.ClearChildren();
var nodeData = dataProvider as VerticalNodeData;
if (nodeData != null)
{
foreach (var anchorData in nodeData.anchors)
{
m_ContainerTop.AddChild(new NodeAnchor(anchorData));
}
m_ContainerBottom.AddChild(new NodeAnchor(nodeData.outputAnchor));
}
}
}
}

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


using UnityEngine.RMGUI;
using UnityEngine.RMGUI.StyleEnums.Values;
namespace RMGUI.GraphView.Demo
{
// TODO: shanti really there should be one data type on a delegate. ... seriously
[CustomDataView(typeof(IMGUIData))]
[CustomDataView(typeof(TestIMGUIElementData))]
[CustomDataView(typeof(IMGUISampleElementData))]
public class IMGUIElement : SimpleElement
{
public IMGUIElement()
{
var imgui = new IMGUIContainer()
{
positionType = PositionType.Absolute,
positionLeft = 0,
positionTop = 20,
positionRight = 0,
positionBottom = 0,
OnGUIHandler = OnGUIHandler
};
AddChild(imgui);
}
public virtual void OnGUIHandler()
{
// Hum... probably not ideal to have to cast and check all the time. Need to find something better.
var imguiData = dataProvider as IMGUIData;
if (imguiData != null)
{
imguiData.OnGUIHandler();
}
}
}
}
using UnityEngine.RMGUI;
using UnityEngine.RMGUI.StyleEnums.Values;
namespace RMGUI.GraphView.Demo
{
public class IMGUIElement : SimpleElement
{
public IMGUIElement()
{
var imgui = new IMGUIContainer()
{
positionType = PositionType.Absolute,
positionLeft = 0,
positionTop = 20,
positionRight = 0,
positionBottom = 0,
OnGUIHandler = OnGUIHandler
};
AddChild(imgui);
}
public virtual void OnGUIHandler()
{
// Hum... probably not ideal to have to cast and check all the time. Need to find something better.
var imguiData = dataProvider as IMGUIData;
if (imguiData != null)
{
imguiData.OnGUIHandler();
}
}
}
}

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


namespace RMGUI.GraphView.Demo
{
[CustomDataView(typeof(InvisibleBorderContainerData))]
public class InvisibleBorderContainer : GraphElement
{
private readonly Color m_OutlineColor = new Color(0.0f, 0.0f, 0.0f, 0.5f);

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


using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[GUISkinStyle("box")]
[CustomDataView(typeof(MiniMapData))]
public class MiniMap : GraphElement
{
private Label m_Label;
private float m_PreviousContainerWidth = -1;
private float m_PreviousContainerHeight = -1;
private Dragger m_Dragger;
public MiniMap()
{
zBias = 99;
clipChildren = false;
m_Label = new Label(new GUIContent("Floating Minimap"));
AddChild(m_Label);
m_Dragger = new Dragger {activateButton = MouseButton.LeftMouse, clampToParentEdges = true};
AddManipulator(new ContextualMenu((evt, customData) =>
{
var boxData = dataProvider as MiniMapData;
if (boxData != null)
{
var menu = new GenericMenu();
menu.AddItem(new GUIContent(boxData.anchored ? "Make floating" : "Anchor"), false,
contentView =>
{
var bData = dataProvider as MiniMapData;
if (bData != null)
bData.anchored = !bData.anchored;
},
this);
menu.ShowAsContext();
}
return EventPropagation.Continue;
}));
}
public override void OnDataChanged()
{
base.OnDataChanged();
AdjustAnchoring();
Resize();
}
private void AdjustAnchoring()
{
var miniMapData = dataProvider as MiniMapData;
if (miniMapData == null)
{
return;
}
// TODO we might want to update the movable capability...
if (miniMapData.anchored)
{
RemoveManipulator(m_Dragger);
ResetPositionProperties();
AddToClassList("anchored");
}
else
{
AddManipulator(m_Dragger);
RemoveFromClassList("anchored");
}
}
private void Resize()
{
var miniMapData = dataProvider as MiniMapData;
if (miniMapData == null || parent == null)
{
return;
}
if (parent.position.height > parent.position.width)
{
height = miniMapData.maxHeight;
width = parent.position.width * height / parent.position.height;
}
else
{
width = miniMapData.maxWidth;
height = parent.position.height * width / parent.position.width;
}
}
public override void DoRepaint(PaintContext args)
{
var gView = this.GetFirstAncestorOfType<GraphView>();
VisualContainer container = gView.contentViewContainer;
Matrix4x4 containerTransform = container.globalTransform;
Vector4 containerTranslation = containerTransform.GetColumn(3);
var containerScale = new Vector2(containerTransform.m00, containerTransform.m11);
Rect containerPosition = container.position;
float containerWidth = parent.position.width / containerScale.x;
float containerHeight = parent.position.height / containerScale.y;
if ( (containerWidth != m_PreviousContainerWidth || containerHeight != m_PreviousContainerHeight) && dataProvider != null)
{
m_PreviousContainerWidth = containerWidth;
m_PreviousContainerHeight = containerHeight;
Resize();
}
m_Label.content = new GUIContent("Minimap p:" +
String.Format("{0:0}", containerPosition.position.x) + "," + String.Format("{0:0}", containerPosition.position.y) + " t: " +
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);
foreach (var child in container.children)
{
// For some reason, I can't seem to be able to use Linq (IEnumerable.OfType() nor IEnumerable.Where appear to be working here. ??)
GraphElement elem = child as GraphElement;
// TODO: Should Edges be displayed at all?
// TODO: Maybe edges need their own capabilities flag.
if (elem == null || (elem.GetData<GraphElementData>().capabilities & Capabilities.Floating) != 0 || (elem.dataProvider is EdgeData))
{
continue;
}
int titleBarOffset = (int)paddingTop;
var rect = child.position;
rect.x /= containerWidth;
rect.width /= containerWidth;
rect.y /= containerHeight;
rect.height /= containerHeight;
rect.x *= position.width;
rect.y *= (position.height-titleBarOffset);
rect.width *= position.width;
rect.height *= (position.height-titleBarOffset);
rect.y += titleBarOffset;
rect.x += position.x;
rect.y += position.y;
rect.x += containerTranslation.x * position.width / parent.position.width;
rect.y += containerTranslation.y * (position.height-titleBarOffset) / parent.position.height;
rect.x += containerPosition.x * position.width / containerWidth;
rect.y += containerPosition.y * (position.height-titleBarOffset) / containerHeight;
if (rect.x < position.xMin)
{
if (rect.x < (position.xMin - rect.width))
{
continue;
}
rect.width -= (position.xMin - rect.x);
rect.x = position.xMin;
}
if (rect.x + rect.width >= position.xMax)
{
if (rect.x >= position.xMax)
{
continue;
}
rect.width -= (rect.x + rect.width) - position.xMax;
}
if (rect.y < (position.yMin+titleBarOffset))
{
if (rect.y < ((position.yMin+titleBarOffset) - rect.height))
{
continue;
}
rect.height -= ((position.yMin+titleBarOffset) - rect.y);
rect.y = (position.yMin+titleBarOffset);
}
if (rect.y + rect.height >= position.yMax)
{
if (rect.y >= position.yMax)
{
continue;
}
rect.height -= (rect.y + rect.height) - position.yMax;
}
Handles.DrawSolidRectangleWithOutline(rect, Color.grey, Color.grey);
}
}
}
}
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[GUISkinStyle("box")]
public class MiniMap : GraphElement
{
private Label m_Label;
private float m_PreviousContainerWidth = -1;
private float m_PreviousContainerHeight = -1;
private Dragger m_Dragger;
public MiniMap()
{
zBias = 99;
clipChildren = false;
m_Label = new Label(new GUIContent("Floating Minimap"));
AddChild(m_Label);
m_Dragger = new Dragger {activateButton = MouseButton.LeftMouse, clampToParentEdges = true};
AddManipulator(new ContextualMenu((evt, customData) =>
{
var boxData = dataProvider as MiniMapData;
if (boxData != null)
{
var menu = new GenericMenu();
menu.AddItem(new GUIContent(boxData.anchored ? "Make floating" : "Anchor"), false,
contentView =>
{
var bData = dataProvider as MiniMapData;
if (bData != null)
bData.anchored = !bData.anchored;
},
this);
menu.ShowAsContext();
}
return EventPropagation.Continue;
}));
}
public override void OnDataChanged()
{
base.OnDataChanged();
AdjustAnchoring();
Resize();
}
private void AdjustAnchoring()
{
var miniMapData = dataProvider as MiniMapData;
if (miniMapData == null)
{
return;
}
// TODO we might want to update the movable capability...
if (miniMapData.anchored)
{
RemoveManipulator(m_Dragger);
ResetPositionProperties();
AddToClassList("anchored");
}
else
{
AddManipulator(m_Dragger);
RemoveFromClassList("anchored");
}
}
private void Resize()
{
var miniMapData = dataProvider as MiniMapData;
if (miniMapData == null || parent == null)
{
return;
}
if (parent.position.height > parent.position.width)
{
height = miniMapData.maxHeight;
width = parent.position.width * height / parent.position.height;
}
else
{
width = miniMapData.maxWidth;
height = parent.position.height * width / parent.position.width;
}
}
public override void DoRepaint(PaintContext args)
{
var gView = this.GetFirstAncestorOfType<GraphView>();
VisualContainer container = gView.contentViewContainer;
Matrix4x4 containerTransform = container.globalTransform;
Vector4 containerTranslation = containerTransform.GetColumn(3);
var containerScale = new Vector2(containerTransform.m00, containerTransform.m11);
Rect containerPosition = container.position;
float containerWidth = parent.position.width / containerScale.x;
float containerHeight = parent.position.height / containerScale.y;
if ( (containerWidth != m_PreviousContainerWidth || containerHeight != m_PreviousContainerHeight) && dataProvider != null)
{
m_PreviousContainerWidth = containerWidth;
m_PreviousContainerHeight = containerHeight;
Resize();
}
m_Label.content = new GUIContent("Minimap p:" +
String.Format("{0:0}", containerPosition.position.x) + "," + String.Format("{0:0}", containerPosition.position.y) + " t: " +
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);
foreach (var child in container.children)
{
// For some reason, I can't seem to be able to use Linq (IEnumerable.OfType() nor IEnumerable.Where appear to be working here. ??)
GraphElement elem = child as GraphElement;
// TODO: Should Edges be displayed at all?
// TODO: Maybe edges need their own capabilities flag.
if (elem == null || (elem.GetData<GraphElementData>().capabilities & Capabilities.Floating) != 0 || (elem.dataProvider is EdgeData))
{
continue;
}
int titleBarOffset = (int)paddingTop;
var rect = child.position;
rect.x /= containerWidth;
rect.width /= containerWidth;
rect.y /= containerHeight;
rect.height /= containerHeight;
rect.x *= position.width;
rect.y *= (position.height-titleBarOffset);
rect.width *= position.width;
rect.height *= (position.height-titleBarOffset);
rect.y += titleBarOffset;
rect.x += position.x;
rect.y += position.y;
rect.x += containerTranslation.x * position.width / parent.position.width;
rect.y += containerTranslation.y * (position.height-titleBarOffset) / parent.position.height;
rect.x += containerPosition.x * position.width / containerWidth;
rect.y += containerPosition.y * (position.height-titleBarOffset) / containerHeight;
if (rect.x < position.xMin)
{
if (rect.x < (position.xMin - rect.width))
{
continue;
}
rect.width -= (position.xMin - rect.x);
rect.x = position.xMin;
}
if (rect.x + rect.width >= position.xMax)
{
if (rect.x >= position.xMax)
{
continue;
}
rect.width -= (rect.x + rect.width) - position.xMax;
}
if (rect.y < (position.yMin+titleBarOffset))
{
if (rect.y < ((position.yMin+titleBarOffset) - rect.height))
{
continue;
}
rect.height -= ((position.yMin+titleBarOffset) - rect.y);
rect.y = (position.yMin+titleBarOffset);
}
if (rect.y + rect.height >= position.yMax)
{
if (rect.y >= position.yMax)
{
continue;
}
rect.height -= (rect.y + rect.height) - position.yMax;
}
Handles.DrawSolidRectangleWithOutline(rect, Color.grey, Color.grey);
}
}
}
}

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


using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[GUISkinStyle("window")]
[CustomDataView(typeof(SimpleElementData))]
public class SimpleElement : GraphElement
{
public SimpleElement()
{
content = new GUIContent("");
}
public override void DoRepaint(PaintContext painter)
{
base.DoRepaint(painter);
if (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected)
{
painter.DrawRectangleOutline(transform, position, Color.yellow);
}
}
public override void OnDataChanged()
{
base.OnDataChanged();
var elementData = (SimpleElementData)dataProvider;
content.text = elementData.title;
}
}
}
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[GUISkinStyle("window")]
public class SimpleElement : GraphElement
{
public SimpleElement()
{
content = new GUIContent("");
}
public override void DoRepaint(PaintContext painter)
{
base.DoRepaint(painter);
if (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected)
{
painter.DrawRectangleOutline(transform, position, Color.yellow);
}
}
public override void OnDataChanged()
{
base.OnDataChanged();
var elementData = (SimpleElementData)dataProvider;
content.text = elementData.title;
}
}
}

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


using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
[CustomDataView(typeof(WWWImageData))]
public class WWWImage : SimpleElement
{
private Texture2D m_WwwTexture;
WWW m_Www;
bool m_IsScheduled;
public WWWImage()
{
m_Www = new WWW("http://lorempixel.com/200/200");
onEnter += SchedulePolling;
onLeave += UnschedulePolling;
pickingMode = PickingMode.Position;
}
private void SchedulePolling()
{
if (panel != null)
{
if (!m_IsScheduled)
{
this.Schedule(CheckForWWW).StartingIn(0).Every(1000);
m_IsScheduled = true;
}
}
else
{
m_IsScheduled = false;
}
}
private void UnschedulePolling()
{
if (m_IsScheduled && panel != null)
{
this.Unschedule(CheckForWWW);
}
m_IsScheduled = false;
}
private void CheckForWWW(TimerState timerState)
{
if (!m_Www.isDone)
{
return;
}
if (m_WwwTexture == null)
{
m_WwwTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
AddChild(new Image {image = m_WwwTexture});
}
m_Www.LoadImageIntoTexture(m_WwwTexture);
m_Www = new WWW("http://lorempixel.com/200/200");
this.Touch(ChangeType.Repaint);
}
}
}
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView.Demo
{
public class WWWImage : SimpleElement
{
private Texture2D m_WwwTexture;
WWW m_Www;
bool m_IsScheduled;
public WWWImage()
{
m_Www = new WWW("http://lorempixel.com/200/200");
onEnter += SchedulePolling;
onLeave += UnschedulePolling;
pickingMode = PickingMode.Position;
}
private void SchedulePolling()
{
if (panel != null)
{
if (!m_IsScheduled)
{
this.Schedule(CheckForWWW).StartingIn(0).Every(1000);
m_IsScheduled = true;
}
}
else
{
m_IsScheduled = false;
}
}
private void UnschedulePolling()
{
if (m_IsScheduled && panel != null)
{
this.Unschedule(CheckForWWW);
}
m_IsScheduled = false;
}
private void CheckForWWW(TimerState timerState)
{
if (!m_Www.isDone)
{
return;
}
if (m_WwwTexture == null)
{
m_WwwTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
AddChild(new Image {image = m_WwwTexture});
}
m_Www.LoadImageIntoTexture(m_WwwTexture);
m_Www = new WWW("http://lorempixel.com/200/200");
this.Touch(ChangeType.Repaint);
}
}
}

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


using UnityEditor;
using UnityEditor;
[CustomDataView(typeof(IMGUIElement))]
public class IMGUISampleElementData : IMGUIData
{
private int m_ControlInteger;

157
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/SimpleGraphView.cs


using System;
using UnityEditor;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{
[Serializable]
public class TestIMGUIElementData : IMGUIData
{
public string m_Text1 = "this is a text field";
public string m_Text2 = "this is a text field";
public bool m_Toggle = true;
public Texture2D m_Texture;
public override void OnGUIHandler()
{
int currentY = 22;
m_Text1 = GUI.TextField(new Rect(0, currentY, 80, 20), m_Text1);
currentY += 22;
m_Toggle = GUI.Toggle(new Rect(0, currentY, 10, 10), m_Toggle, GUIContent.none);
currentY += 22;
m_Text2 = GUI.TextField(new Rect(0, currentY, 80, 20), m_Text2);
currentY += 22;
m_Texture = EditorGUI.ObjectField(new Rect(0, currentY, 80, 100), m_Texture, typeof(Texture2D), false) as Texture2D;
}
}
public class SimpleGraphViewData : GraphViewDataSource
{
protected void OnEnable()
{
var simpleElementData = CreateInstance<SimpleElementData>();
simpleElementData.position = new Rect(0, 0, 200, 200);
simpleElementData.title = "Static element";
simpleElementData.capabilities &= ~Capabilities.Movable; // Make this simple element non-movable
AddElement(simpleElementData);
var resizableElementData = CreateInstance<SimpleElementData>();
resizableElementData.position = new Rect(400, 100, 100, 100);
resizableElementData.title = "Resizable element";
resizableElementData.capabilities |= Capabilities.Resizable;
AddElement(resizableElementData);
var imguiSampleData = CreateInstance<TestIMGUIElementData>();
imguiSampleData.position = new Rect(100, 200, 100, 100);
imguiSampleData.title = "IMGUI sample";
imguiSampleData.capabilities |= Capabilities.Resizable;
AddElement(imguiSampleData);
var movableElementData = CreateInstance<SimpleElementData>();
movableElementData.position = new Rect(400, 400, 200, 200);
movableElementData.title = "Movable element";
AddElement(movableElementData);
var miniMapData = CreateInstance<MiniMapData>();
miniMapData.position = new Rect(0, 500, 100, 100);
AddElement(miniMapData);
var circleData = CreateInstance<CircleData>();
circleData.position = new Rect(200, 500, 0, 0);
circleData.radius = 100;
AddElement(circleData);
var wwwImageData = CreateInstance<WWWImageData>();
wwwImageData.title = "WWW Image";
wwwImageData.position = new Rect(300, 300, 200, 200);
AddElement(wwwImageData);
var invisibleBorderContainerData = CreateInstance<InvisibleBorderContainerData>();
invisibleBorderContainerData.position = new Rect(400, 0, 100, 100);
AddElement(invisibleBorderContainerData);
}
}
}
using System;
using UnityEditor;
using UnityEngine;
namespace RMGUI.GraphView.Demo
{
[CustomDataView(typeof(IMGUIElement))]
[Serializable]
public class TestIMGUIElementData : IMGUIData
{
public string m_Text1 = "this is a text field";
public string m_Text2 = "this is a text field";
public bool m_Toggle = true;
public Texture2D m_Texture;
public override void OnGUIHandler()
{
int currentY = 22;
m_Text1 = GUI.TextField(new Rect(0, currentY, 80, 20), m_Text1);
currentY += 22;
m_Toggle = GUI.Toggle(new Rect(0, currentY, 10, 10), m_Toggle, GUIContent.none);
currentY += 22;
m_Text2 = GUI.TextField(new Rect(0, currentY, 80, 20), m_Text2);
currentY += 22;
m_Texture = EditorGUI.ObjectField(new Rect(0, currentY, 80, 100), m_Texture, typeof(Texture2D), false) as Texture2D;
}
}
public class SimpleGraphViewData : GraphViewDataSource
{
protected void OnEnable()
{
var simpleElementData = CreateInstance<SimpleElementData>();
simpleElementData.position = new Rect(0, 0, 200, 200);
simpleElementData.title = "Static element";
simpleElementData.capabilities &= ~Capabilities.Movable; // Make this simple element non-movable
AddElement(simpleElementData);
var resizableElementData = CreateInstance<SimpleElementData>();
resizableElementData.position = new Rect(400, 100, 100, 100);
resizableElementData.title = "Resizable element";
resizableElementData.capabilities |= Capabilities.Resizable;
AddElement(resizableElementData);
var imguiSampleData = CreateInstance<TestIMGUIElementData>();
imguiSampleData.position = new Rect(100, 200, 100, 100);
imguiSampleData.title = "IMGUI sample";
imguiSampleData.capabilities |= Capabilities.Resizable;
AddElement(imguiSampleData);
var movableElementData = CreateInstance<SimpleElementData>();
movableElementData.position = new Rect(400, 400, 200, 200);
movableElementData.title = "Movable element";
AddElement(movableElementData);
var miniMapData = CreateInstance<MiniMapData>();
miniMapData.position = new Rect(0, 500, 100, 100);
AddElement(miniMapData);
var circleData = CreateInstance<CircleData>();
circleData.position = new Rect(200, 500, 0, 0);
circleData.radius = 100;
AddElement(circleData);
var wwwImageData = CreateInstance<WWWImageData>();
wwwImageData.title = "WWW Image";
wwwImageData.position = new Rect(300, 300, 200, 200);
AddElement(wwwImageData);
var invisibleBorderContainerData = CreateInstance<InvisibleBorderContainerData>();
invisibleBorderContainerData.position = new Rect(400, 0, 100, 100);
AddElement(invisibleBorderContainerData);
}
}
}

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


using System;
using UnityEngine;
namespace RMGUI.GraphView
{
[Serializable]
internal class EdgeData : GraphElementData
{
public IConnectable left;
public IConnectable right;
public Vector2 candidatePosition;
public bool candidate;
protected new void OnEnable()
{
capabilities = Capabilities.Selectable;
}
}
}
using System;
using UnityEngine;
namespace RMGUI.GraphView
{
[Serializable]
[CustomDataView(typeof(Edge))]
internal class EdgeData : GraphElementData
{
public IConnectable left;
public IConnectable right;
public Vector2 candidatePosition;
public bool candidate;
protected new void OnEnable()
{
capabilities = Capabilities.Selectable;
}
}
}

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


using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView
{
[CustomDataView(typeof(EdgeData))]
class Edge : GraphElement
{
const float k_EndPointRadius = 4.0f;
const float k_InterceptWidth = 3.0f;
public override void OnDataChanged()
{
base.OnDataChanged();
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;
}
bool invert = false;
if (end.x < start.x)
{
Vector3 t = start;
start = end;
end = t;
invert = true;
}
points = new Vector3[] {start, end};
tangents = new Vector3[2];
const float minTangent = 30;
float weight = .5f;
float weight2 = 1 - weight;
float y = 0;
float cleverness = Mathf.Clamp01(((start - end).magnitude - 10) / 50);
if (orientation == Orientation.Horizontal)
{
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;
}
else
{
float inverse = (invert) ? 1.0f : -1.0f;
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;
}
}
public override bool Overlaps(Rect rect)
{
// bounding box check succeeded, do more fine grained check by checking intersection between the rectangles' diagonal
// and the line segments
var edgeData = GetData<EdgeData>();
if (edgeData == null)
return false;
IConnectable leftData = edgeData.left;
IConnectable rightData = edgeData.right ?? leftData;
if (leftData == null || rightData == null)
return false;
Vector2 from = Vector2.zero;
Vector2 to = Vector2.zero;
GetFromToPoints(ref from, ref to);
Orientation orientation = leftData.orientation;
Vector3[] points, tangents;
GetTangents(leftData.direction, 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 (a >= allPoints.Length - 1)
{
break;
}
Vector2 segmentA = new Vector2(allPoints[a].x, allPoints[a].y);
Vector2 segmentB = new Vector2(allPoints[a + 1].x, allPoints[a + 1].y);
if (RectUtils.IntersectsSegment(rect, segmentA, segmentB))
return true;
}
return false;
}
public override bool ContainsPoint(Vector2 localPoint)
{
// bounding box check succeeded, do more fine grained check by measuring distance to bezier points
var edgeData = GetData<EdgeData>();
if (edgeData == null)
return false;
IConnectable leftData = edgeData.left;
IConnectable rightData = edgeData.right ?? leftData;
if (leftData == null || rightData == null)
return false;
Vector2 from = Vector2.zero;
Vector2 to = Vector2.zero;
GetFromToPoints(ref from, ref to);
// exclude endpoints
if (Vector2.Distance(from, localPoint) <= 2*k_EndPointRadius ||
Vector2.Distance(to, localPoint) <= 2*k_EndPointRadius)
{
return false;
}
Orientation orientation = leftData.orientation;
Vector3[] points, tangents;
GetTangents(leftData.direction, orientation, from, to, out points, out tangents);
Vector3[] allPoints = Handles.MakeBezierPoints(points[0], points[1], tangents[0], tangents[1], 20);
float minDistance = Mathf.Infinity;
foreach (Vector3 currentPoint in allPoints)
{
float distance = Vector3.Distance(currentPoint, localPoint);
minDistance = Mathf.Min(minDistance, distance);
if (minDistance < k_InterceptWidth)
{
return true;
}
}
return false;
}
public override void DoRepaint(PaintContext args)
{
base.DoRepaint(args);
DrawEdge(args);
}
protected void GetFromToPoints(ref Vector2 from, ref Vector2 to)
{
var edgeData = GetData<EdgeData>();
if (edgeData == null)
return;
IConnectable leftData = edgeData.left;
IConnectable rightData = edgeData.right ?? leftData;
if (leftData == null)
return;
GraphElement leftAnchor = parent.allElements.OfType<GraphElement>().First(e => e.dataProvider as IConnectable == leftData);
if (leftAnchor != null)
{
from = leftAnchor.GetGlobalCenter();
from = globalTransform.inverse.MultiplyPoint3x4(from);
}
if (edgeData.candidate)
{
to = globalTransform.inverse.MultiplyPoint3x4(new Vector3(edgeData.candidatePosition.x, edgeData.candidatePosition.y));
}
else
{
GraphElement rightAnchor = parent.allElements.OfType<GraphElement>().First(e => e.dataProvider as IConnectable == rightData);
if (rightAnchor != null)
{
to = rightAnchor.GetGlobalCenter();
to = globalTransform.inverse.MultiplyPoint3x4(to);
}
}
}
protected virtual void DrawEdge(PaintContext args)
{
var edgeData = GetData<EdgeData>();
if (edgeData == null)
return;
IConnectable leftData = edgeData.left;
if (leftData == null)
return;
Vector2 from = Vector2.zero;
Vector2 to = Vector2.zero;
GetFromToPoints(ref from, ref to);
Color edgeColor = (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected) ? Color.yellow : Color.white;
Orientation orientation = leftData.orientation;
Vector3[] points, tangents;
GetTangents(leftData.direction, 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
Vector3[] allPoints = Handles.MakeBezierPoints(points[0], points[1], tangents[0], tangents[1], 20);
Color oldColor = Handles.color;
Handles.color = Color.blue;
Handles.DrawSolidDisc(allPoints[10], new Vector3(0.0f, 0.0f, -1.0f), 6f);
Handles.color = edgeColor;
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);
// dot on top of anchor showing it's connected
Handles.color = new Color(0.3f, 0.4f, 1.0f, 1.0f);
Handles.DrawSolidDisc(from, new Vector3(0.0f, 0.0f, -1.0f), k_EndPointRadius);
if (edgeData.right == null)
Handles.color = oldColor;
Handles.DrawSolidDisc(to, new Vector3(0.0f, 0.0f, -1.0f), k_EndPointRadius);
Handles.color = oldColor;
}
}
}
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView
{
class Edge : GraphElement
{
const float k_EndPointRadius = 4.0f;
const float k_InterceptWidth = 3.0f;
public override void OnDataChanged()
{
base.OnDataChanged();
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;
}
bool invert = false;
if (end.x < start.x)
{
Vector3 t = start;
start = end;
end = t;
invert = true;
}
points = new Vector3[] {start, end};
tangents = new Vector3[2];
const float minTangent = 30;
float weight = .5f;
float weight2 = 1 - weight;
float y = 0;
float cleverness = Mathf.Clamp01(((start - end).magnitude - 10) / 50);
if (orientation == Orientation.Horizontal)
{
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;
}
else
{
float inverse = (invert) ? 1.0f : -1.0f;
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;
}
}
public override bool Overlaps(Rect rect)
{
// bounding box check succeeded, do more fine grained check by checking intersection between the rectangles' diagonal
// and the line segments
var edgeData = GetData<EdgeData>();
if (edgeData == null)
return false;
IConnectable leftData = edgeData.left;
IConnectable rightData = edgeData.right ?? leftData;
if (leftData == null || rightData == null)
return false;
Vector2 from = Vector2.zero;
Vector2 to = Vector2.zero;
GetFromToPoints(ref from, ref to);
Orientation orientation = leftData.orientation;
Vector3[] points, tangents;
GetTangents(leftData.direction, 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 (a >= allPoints.Length - 1)
{
break;
}
Vector2 segmentA = new Vector2(allPoints[a].x, allPoints[a].y);
Vector2 segmentB = new Vector2(allPoints[a + 1].x, allPoints[a + 1].y);
if (RectUtils.IntersectsSegment(rect, segmentA, segmentB))
return true;
}
return false;
}
public override bool ContainsPoint(Vector2 localPoint)
{
// bounding box check succeeded, do more fine grained check by measuring distance to bezier points
var edgeData = GetData<EdgeData>();
if (edgeData == null)
return false;
IConnectable leftData = edgeData.left;
IConnectable rightData = edgeData.right ?? leftData;
if (leftData == null || rightData == null)
return false;
Vector2 from = Vector2.zero;
Vector2 to = Vector2.zero;
GetFromToPoints(ref from, ref to);
// exclude endpoints
if (Vector2.Distance(from, localPoint) <= 2*k_EndPointRadius ||
Vector2.Distance(to, localPoint) <= 2*k_EndPointRadius)
{
return false;
}
Orientation orientation = leftData.orientation;
Vector3[] points, tangents;
GetTangents(leftData.direction, orientation, from, to, out points, out tangents);
Vector3[] allPoints = Handles.MakeBezierPoints(points[0], points[1], tangents[0], tangents[1], 20);
float minDistance = Mathf.Infinity;
foreach (Vector3 currentPoint in allPoints)
{
float distance = Vector3.Distance(currentPoint, localPoint);
minDistance = Mathf.Min(minDistance, distance);
if (minDistance < k_InterceptWidth)
{
return true;
}
}
return false;
}
public override void DoRepaint(PaintContext args)
{
base.DoRepaint(args);
DrawEdge(args);
}
protected void GetFromToPoints(ref Vector2 from, ref Vector2 to)
{
var edgeData = GetData<EdgeData>();
if (edgeData == null)
return;
IConnectable leftData = edgeData.left;
IConnectable rightData = edgeData.right ?? leftData;
if (leftData == null)
return;
GraphElement leftAnchor = parent.allElements.OfType<GraphElement>().First(e => e.dataProvider as IConnectable == leftData);
if (leftAnchor != null)
{
from = leftAnchor.GetGlobalCenter();
from = globalTransform.inverse.MultiplyPoint3x4(from);
}
if (edgeData.candidate)
{
to = globalTransform.inverse.MultiplyPoint3x4(new Vector3(edgeData.candidatePosition.x, edgeData.candidatePosition.y));
}
else
{
GraphElement rightAnchor = parent.allElements.OfType<GraphElement>().First(e => e.dataProvider as IConnectable == rightData);
if (rightAnchor != null)
{
to = rightAnchor.GetGlobalCenter();
to = globalTransform.inverse.MultiplyPoint3x4(to);
}
}
}
protected virtual void DrawEdge(PaintContext args)
{
var edgeData = GetData<EdgeData>();
if (edgeData == null)
return;
IConnectable leftData = edgeData.left;
if (leftData == null)
return;
Vector2 from = Vector2.zero;
Vector2 to = Vector2.zero;
GetFromToPoints(ref from, ref to);
Color edgeColor = (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected) ? Color.yellow : Color.white;
Orientation orientation = leftData.orientation;
Vector3[] points, tangents;
GetTangents(leftData.direction, 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
Vector3[] allPoints = Handles.MakeBezierPoints(points[0], points[1], tangents[0], tangents[1], 20);
Color oldColor = Handles.color;
Handles.color = Color.blue;
Handles.DrawSolidDisc(allPoints[10], new Vector3(0.0f, 0.0f, -1.0f), 6f);
Handles.color = edgeColor;
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);
// dot on top of anchor showing it's connected
Handles.color = new Color(0.3f, 0.4f, 1.0f, 1.0f);
Handles.DrawSolidDisc(from, new Vector3(0.0f, 0.0f, -1.0f), k_EndPointRadius);
if (edgeData.right == null)
Handles.color = oldColor;
Handles.DrawSolidDisc(to, new Vector3(0.0f, 0.0f, -1.0f), k_EndPointRadius);
Handles.color = oldColor;
}
}
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Styles/NodalView.uss


MaterialGraphNode #preview #image {
height: 200;
width: 200;
align-self: center;
}
NodeAnchor {

正在加载...
取消
保存