浏览代码

[canvas2d] Update canvas 2d version

/main
Tim Cooper 9 年前
当前提交
15591be8
共有 32 个文件被更改,包括 807 次插入353 次删除
  1. 58
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Canvas2D.cs
  2. 30
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/CanvasAnimation.cs
  3. 9
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalDataSource.cs
  4. 44
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalWidgets.cs
  5. 447
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/ExampleWidgets.cs
  6. 1
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleCanvas2D.cs
  7. 50
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Edge.cs
  8. 73
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/EdgeConnector.cs
  9. 1
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/IConnect.cs
  10. 10
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Draggable.cs
  11. 2
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Frame.cs
  12. 41
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/ImguiContainer.cs
  13. 3
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Resizable.cs
  14. 2
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/ScreenSpaceGrid.cs
  15. 4
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Zoomable.cs
  16. 4
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/PropertyData.cs
  17. 9
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI.meta
  18. 64
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/CustomEdge.cs
  19. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/CustomEdge.cs.meta
  20. 9
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Resources.meta
  21. 8
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Orientation.cs
  22. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Orientation.cs.meta
  23. 77
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUICanvas2D.cs
  24. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUICanvas2D.cs.meta
  25. 29
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIDataSource.cs
  26. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIDataSource.cs.meta
  27. 62
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIWidget.cs
  28. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIWidget.cs.meta
  29. 6
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Resources/edge.png
  30. 57
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Resources/edge.png.meta

58
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Canvas2D.cs


using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditorInternal;
using UnityEditorInternal.Experimental;
using Object = UnityEngine.Object;
//#pragma warning disable 0414

public Vector2 MouseToCanvas(Vector2 lhs)
{
return new Vector2((lhs.x - m_Translation.x) / m_Scale.x, (lhs.y - m_Translation.y) / m_Scale.y) + (m_ViewOffset / 2.0f);
return new Vector2((lhs.x - m_Translation.x) / m_Scale.x, (lhs.y - m_Translation.y) / m_Scale.y); // +(m_ViewOffset / 2.0f);
return new Vector2((lhs.x * m_Scale.x) + m_Translation.x, (lhs.y * m_Scale.y) + m_Translation.y);
return new Vector2(((lhs.x) * m_Scale.x) + (m_Translation.x), ((lhs.y) * m_Scale.y) + (m_Translation.y));
t -= new Vector3(m_ViewOffsetUnscaled.x / 2.0f, m_ViewOffsetUnscaled.y / 2.0f, 0.0f);
Matrix4x4 mm = Matrix4x4.TRS(t, Quaternion.identity, m_Scale);
Vector3 offset = new Vector3(0.0f, 0.0f, 0.0f);
var inverseScale = new Vector2(1.0f / m_Scale.x, 1.0f / m_Scale.y);
Matrix4x4 scaleMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, m_Scale);
Matrix4x4 txMatrix = Matrix4x4.TRS(m_Translation, Quaternion.identity, Vector3.one);
Matrix4x4 mm = txMatrix * scaleMatrix;
{
new Vector3(r.xMin, r.yMin, 0.0f),
new Vector3(r.xMax, r.yMin, 0.0f),
new Vector3(r.xMax, r.yMax, 0.0f),
new Vector3(r.xMin, r.yMax, 0.0f)
};
{
new Vector3(r.xMin, r.yMin, 0.0f),
new Vector3(r.xMax, r.yMin, 0.0f),
new Vector3(r.xMax, r.yMax, 0.0f),
new Vector3(r.xMin, r.yMax, 0.0f)
};
points[a] += offset;
}
return new Rect(points[0].x, points[0].y, points[2].x - points[0].x, points[2].y - points[0].y);

RebuildQuadTree();
}
if (evt.type == EventType.Layout)
{
if (OnLayout != null)
OnLayout(this, Event.current, this);
}
if (evt.type == EventType.Repaint)
{
// tick animations

if (OnLayout != null)
OnLayout(this, Event.current, this);
RebuildQuadTree();
m_MustRebuildQuadTree = true;
Repaint();
}

// sync selection globally on MouseUp and KeyEvents
bool syncSelection = evt.type == EventType.MouseUp || evt.isKey;
OnEvent(evt);
if (syncSelection)
OnEvent(evt);
if (syncSelection)
{
SyncUnitySelection();
}

//m_Scale = Vector3.one;
GUI.matrix = Matrix4x4.TRS(m_Translation, Quaternion.identity, m_Scale);
m_ViewOffset = new Vector2(0.0f, -(extents.yMin - m_ScreenHeightOffset) * (1.0f / m_Scale.y));
float inverseScale = 1.0f / m_Scale.y;
m_ViewOffset = new Vector2(0.0f, -(extents.yMin - (m_ScreenHeightOffset / 2.0f)) * inverseScale);
m_ViewOffsetUnscaled = new Vector2(0.0f, -(extents.yMin - m_ScreenHeightOffset));
GUI.BeginClip(extents, Vector2.zero, m_ViewOffset, true);

public bool OnEvent(Event evt)
{
if (evt.type == EventType.Layout)
{
for (int c = 0; c < m_Children.Count; c++)
{
m_Children[c].DispatchEvents(evt, this);
}
return true;
}
bool logEvent = false;
if ((evt.type != EventType.Repaint) && (evt.type != EventType.Layout))
{

30
UnityProject/Assets/GraphFramework/Canvas2D/Editor/CanvasAnimation.cs


m_ElementBeingAnimated.Invalidate();
}
public CanvasAnimation Lerp(string[] props, object[] from, object[] to)
public CanvasAnimation Lerp(string[] props, object[] from, object[] to, float speed)
{
if ((props.Length != from.Length) ||
(props.Length != from.Length))

return this;
}
var propData = new PropertyData(fi, from[c], to[c]);
var propData = new PropertyData(fi, from[c], to[c], speed);
switch (fi.FieldType.Name)
{

currentAnimation.AddCallback(LerpVector3, propData); break;
case "Color":
currentAnimation.AddCallback(LerpColor, propData); break;
default:
Debug.LogError("No handler found to lerp " + fi.FieldType.Name);
break;

public CanvasAnimation Lerp(string prop, object from, object to)
{
return Lerp(new string[] { prop }, new object[] { from }, new object[] { to });
return Lerp(prop, from, to, 0.08f);
}
public CanvasAnimation Lerp(string prop, object from, object to, float speed)
{
return Lerp(new string[] { prop }, new object[] { from }, new object[] { to }, speed);
}
private void LerpFloat(CanvasElement element, CanvasAnimation owner, object userData)

pData.field.SetValue(m_ElementBeingAnimated, result);
pData.time += 0.08f;
pData.time += pData.speed;
if (pData.time > 1.0f)
{
pData.field.SetValue(m_ElementBeingAnimated, (float)pData.data1);

var pData = userData as PropertyData;
Vector3 result = Vector3.Lerp((Vector3)pData.data0, (Vector3)pData.data1, pData.curve.Evaluate(pData.time));
pData.field.SetValue(m_ElementBeingAnimated, result);
pData.time += 0.08f;
pData.time += pData.speed;
owner.Done();
}
}
private void LerpColor(CanvasElement element, CanvasAnimation owner, object userData)
{
var pData = userData as PropertyData;
Color result = Color.Lerp((Color)pData.data0, (Color)pData.data1, pData.curve.Evaluate(pData.time));
pData.field.SetValue(m_ElementBeingAnimated, result);
pData.time += pData.speed;
if (pData.time > 1.0f)
{
pData.field.SetValue(m_ElementBeingAnimated, (Color)pData.data1);
owner.Done();
}
}

9
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalDataSource.cs


m_Elements.Add(new Node(new Vector2(210.0f, 0.0f), 200.0f, typeof(int), this));
m_Elements.Add(new Node(new Vector2(420.0f, 0.0f), 200.0f, typeof(Color), this));
m_Elements.Add(new Node(new Vector2(0.0f, 210.0f), 200.0f, typeof(float), this));
m_Elements.Add(new FloatingBox(new Vector2(210.0f, 210.0f), 200.0f));
m_Elements.Add(new FloatingBox(new Vector2(210.0f, 210.0f), 200.0f));
m_Elements.Add(new VerticalNode(new Vector2(210.0f, 420.0f), 100.0f, typeof(float), this));
m_Elements.Add(new VerticalNode(new Vector2(320.0f, 420.0f), 100.0f, typeof(float), this));
m_Elements.Add(new VerticalNode(new Vector2(430.0f, 420.0f), 100.0f, typeof(float), this));
}
public CanvasElement[] FetchElements()

public void Connect(NodeAnchor a, NodeAnchor b)
{
m_Elements.Add(new Edge<NodeAnchor>(this, a, b));
m_Elements.Add(new CustomEdge<NodeAnchor>(this, a, b));
}
}
}

44
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalWidgets.cs


{
}
class Node : MoveableBox
{
Type m_OutputType;

Vector3 pos = new Vector3(5.0f, 32.0f, 0.0f);
AddChild(new NodeAnchor(0, pos, typeof(int), this, data));
AddChild(new NodeAnchor(0, pos, typeof(int), data, null));
AddChild(new NodeAnchor(1, pos, typeof(float), this, data));
AddChild(new NodeAnchor(1, pos, typeof(float), data, null));
AddChild(new NodeAnchor(2, pos, typeof(Vector3), this, data));
AddChild(new NodeAnchor(2, pos, typeof(Vector3), data, null));
AddChild(new NodeAnchor(3, pos, typeof(Texture2D), this, data));
AddChild(new NodeAnchor(3, pos, typeof(Texture2D), data, null));
AddChild(new NodeAnchor(4, pos, typeof(Color), this, data));
AddChild(new NodeAnchor(4, pos, typeof(Color), data, null));
AddChild(new NodeOutputAnchor(pos, m_OutputType, this, data));
AddChild(new NodeOutputAnchor(pos, m_OutputType, data));
pos.y += 22;
scale = new Vector3(scale.x, pos.y + 12.0f, 0.0f);
}

protected object m_Source;
protected Direction m_Direction;
private NodalDataSource m_Data;
public Node m_Node;
protected Orientation m_Orientation = Orientation.Horizontal;
public NodeAnchor(int portIndex, Vector3 position, Type type, Node node, NodalDataSource data)
static public float kNodeSize = 15.0f;
public NodeAnchor(int portIndex, Vector3 position, Type type, NodalDataSource data, EdgeRenderMethod customEdgeDrawMethod)
scale = new Vector3(15.0f, 15.0f, 1.0f);
scale = new Vector3(kNodeSize, kNodeSize, 1.0f);
AddManipulator(new EdgeConnector<NodeAnchor>());
AddManipulator(new EdgeConnector<NodeAnchor>(customEdgeDrawMethod));
m_Direction = Direction.Input;
Type genericClass = typeof(PortSource<>);

m_Node = node;
m_PortIndex = portIndex;
}

anchorColor.a = 0.7f;
base.Render(parentRect, canvas);
EditorGUI.DrawRect(new Rect(translation.x, translation.y, scale.x, scale.y), anchorColor);
if (m_Orientation == Orientation.Vertical)
{
float yPosition = translation.y + 20.0f;
if ((yPosition) > parent.boundingRect.height)
{
yPosition = translation.y - 20.0f;
}
labelRect = new Rect(translation.x, yPosition, 200.0f, 20.0f);
}
GUI.Label(labelRect, m_Type.Name);
}

return m_Direction;
}
public Orientation GetOrientation()
{
return m_Orientation;
}
public void Highlight(bool highlighted)

};
internal class NodeOutputAnchor : NodeAnchor
{
public NodeOutputAnchor(Vector3 position, Type type, Node node, NodalDataSource data)
: base(-1, position, type, node, data)
public NodeOutputAnchor(Vector3 position, Type type, NodalDataSource data)
: base(-1, position, type, data, null)
{
m_Direction = Direction.Output;
}

447
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/ExampleWidgets.cs


using UnityEngine;
namespace UnityEditor.Experimental.Graph.Examples
{
class SimpleBox : CanvasElement
{
protected string m_Title = "simpleBox";
public SimpleBox(Vector2 position, float size)
{
translation = position;
scale = new Vector2(size, size);
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
Color selectedColor = new Color(1.0f, 0.7f, 0.0f, 0.7f);
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), selected ? selectedColor : backgroundColor);
GUI.Label(new Rect(0, 0, scale.x, 26f), GUIContent.none, new GUIStyle("preToolbar"));
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Title, EditorStyles.toolbarTextField);
base.Render(parentRect, canvas);
}
}
class MoveableBox : SimpleBox
{
public MoveableBox(Vector2 position, float size)
: base(position, size)
{
m_Title = "Drag me!";
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
}
}
class FloatingBox : CanvasElement
{
public FloatingBox(Vector2 position, float size)
{
m_Translation = position;
m_Scale = new Vector3(size, size, size);
m_Caps |= Capabilities.Floating;
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
Color selectedColor = new Color(1.0f, 0.7f, 0.0f, 0.7f);
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), selected ? selectedColor : backgroundColor);
GUI.Label(new Rect(0, 0, m_Scale.x, 20.0f), "Floating Minimap");
foreach (var child in canvas.Children())
{
if ((child.caps & Capabilities.Floating) != 0)
continue;
var rect = child.canvasBoundingRect;
rect.x /= canvas.clientRect.width;
rect.width /= canvas.clientRect.width;
rect.y /= canvas.clientRect.height;
rect.height /= canvas.clientRect.height;
rect.x *= m_Scale.x / 2.0f;
rect.y *= m_Scale.y / 2.0f;
rect.width *= m_Scale.x / 2.0f;
rect.height *= m_Scale.y / 2.0f;
rect.y += 20;
EditorGUI.DrawRect(rect, Color.grey);
}
Invalidate();
canvas.Repaint();
}
}
class InvisibleBorderContainer : CanvasElement
{
private bool m_NormalizedDragRegion = false;
private Draggable m_DragManipulator = null;
public InvisibleBorderContainer(Vector2 position, float size, bool normalizedDragRegion)
{
translation = position;
scale = new Vector2(size, size);
m_NormalizedDragRegion = normalizedDragRegion;
if (normalizedDragRegion)
{
m_DragManipulator = new Draggable(new Rect(0.1f, 0.1f, 0.9f, 0.9f), true);
AddManipulator(m_DragManipulator);
}
else
{
float padding = size / 10.0f;
m_DragManipulator = new Draggable(new Rect(padding, padding, size - (padding * 2), size - (padding * 2)), false);
AddManipulator(m_DragManipulator);
}
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
EditorGUI.DrawRect(new Rect(0, 0, m_Scale.x, m_Scale.y), m_Selected ? Color.blue : new Color(0.0f, 0.0f, 0.0f, 0.5f));
Rect activeDragRect = m_DragManipulator.ComputeDragRegion(this, false);
EditorGUI.DrawRect(new Rect(activeDragRect.x - boundingRect.x, activeDragRect.y - boundingRect.y, activeDragRect.width, activeDragRect.height), Color.green);
GUI.Label(new Rect(0, (m_Scale.y * 0.5f) - 10.0f, 100, 20), "normalized:" + m_NormalizedDragRegion);
base.Render(parentRect, canvas);
}
}
class Circle : CanvasElement
{
public Circle(Vector2 position, float size)
{
translation = position;
scale = new Vector2(size, size);
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
Handles.DrawSolidDisc(new Vector3(scale.x / 2.0f, scale.x / 2.0f, 0.0f), new Vector3(0.0f, 0.0f, -1.0f), scale.x / 2.0f);
}
public override bool Contains(Vector2 point)
{
Rect canvasRect = canvasBoundingRect;
return Vector2.Distance(canvasRect.center, point) <= (scale.x / 2.0f);
}
}
class ResizableBox : SimpleBox
{
public ResizableBox(Vector2 position, float size)
: base(position, size)
{
m_Title = "Resize me!";
AddManipulator(new Resizable());
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
}
}
class WWWImageBox : SimpleBox
{
Texture2D m_WWWTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
WWW www = null;
private float timeToNextPicture = 0.0f;
public WWWImageBox(Vector2 position, float size)
: base(position, size)
{
m_Title = "I cause repaints every frame!";
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
if (www != null && www.isDone)
{
www.LoadImageIntoTexture(m_WWWTexture);
www = null;
timeToNextPicture = 3.0f;
}
timeToNextPicture -= Time.deltaTime;
if (timeToNextPicture < 0.0f)
{
timeToNextPicture = 99999.0f;
www = new WWW("http://lorempixel.com/200/200");
}
base.Render(parentRect, canvas);
GUI.DrawTexture(new Rect(0, 20, 200, 200), m_WWWTexture);
Invalidate();
canvas.Repaint();
}
}
class IMGUIControls : SimpleBox
{
private string m_Text1 = "this is a text field";
private string m_Text2 = "this is a text field";
private bool m_Toggle = true;
private Texture2D m_aTexture = null;
public IMGUIControls(Vector2 position, float size)
: base(position, size)
{
m_Caps = Capabilities.Unselectable;
m_Title = "modal";
AddManipulator(new Draggable());
AddManipulator(new Resizable());
AddManipulator(new ImguiContainer());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
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_aTexture = EditorGUI.ObjectField(new Rect(0, currentY, 80, 100), m_aTexture, typeof(Texture2D), false) as Texture2D;
}
}
using UnityEngine;
using UnityEditor.Experimental;
namespace UnityEditor.Experimental.Graph.Examples
{
class SimpleBox : CanvasElement
{
protected string m_Title = "simpleBox";
public SimpleBox(Vector2 position, float size)
{
translation = position;
scale = new Vector2(size, size);
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
Color selectedColor = new Color(1.0f, 0.7f, 0.0f, 0.7f);
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), selected ? selectedColor : backgroundColor);
GUI.Label(new Rect(0, 0, scale.x, 26f), GUIContent.none, new GUIStyle("preToolbar"));
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Title, EditorStyles.toolbarTextField);
base.Render(parentRect, canvas);
}
}
class MoveableBox : SimpleBox
{
public MoveableBox(Vector2 position, float size)
: base(position, size)
{
m_Title = "Drag me!";
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
}
}
class FloatingBox : CanvasElement
{
public FloatingBox(Vector2 position, float size)
{
m_Translation = position;
m_Scale = new Vector3(size, size, size);
m_Caps |= Capabilities.Floating;
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
Color selectedColor = new Color(1.0f, 0.7f, 0.0f, 0.7f);
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), selected ? selectedColor : backgroundColor);
GUI.Label(new Rect(0, 0, m_Scale.x, 20.0f), "Floating Minimap");
foreach (var child in canvas.Children())
{
if ((child.caps & Capabilities.Floating) != 0)
continue;
var rect = child.canvasBoundingRect;
rect.x /= canvas.clientRect.width;
rect.width /= canvas.clientRect.width;
rect.y /= canvas.clientRect.height;
rect.height /= canvas.clientRect.height;
rect.x *= m_Scale.x / 2.0f;
rect.y *= m_Scale.y / 2.0f;
rect.width *= m_Scale.x / 2.0f;
rect.height *= m_Scale.y / 2.0f;
rect.y += 20;
EditorGUI.DrawRect(rect, Color.grey);
}
Invalidate();
canvas.Repaint();
}
}
class InvisibleBorderContainer : CanvasElement
{
private bool m_NormalizedDragRegion = false;
private Draggable m_DragManipulator = null;
public InvisibleBorderContainer(Vector2 position, float size, bool normalizedDragRegion)
{
translation = position;
scale = new Vector2(size, size);
m_NormalizedDragRegion = normalizedDragRegion;
if (normalizedDragRegion)
{
m_DragManipulator = new Draggable(new Rect(0.1f, 0.1f, 0.9f, 0.9f), true);
AddManipulator(m_DragManipulator);
}
else
{
float padding = size / 10.0f;
m_DragManipulator = new Draggable(new Rect(padding, padding, size - (padding * 2), size - (padding * 2)), false);
AddManipulator(m_DragManipulator);
}
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
EditorGUI.DrawRect(new Rect(0, 0, m_Scale.x, m_Scale.y), m_Selected ? Color.blue : new Color(0.0f, 0.0f, 0.0f, 0.5f));
Rect activeDragRect = m_DragManipulator.ComputeDragRegion(this, false);
EditorGUI.DrawRect(new Rect(activeDragRect.x - boundingRect.x, activeDragRect.y - boundingRect.y, activeDragRect.width, activeDragRect.height), Color.green);
GUI.Label(new Rect(0, (m_Scale.y * 0.5f) - 10.0f, 100, 20), "normalized:" + m_NormalizedDragRegion);
base.Render(parentRect, canvas);
}
}
class Circle : CanvasElement
{
public Circle(Vector2 position, float size)
{
translation = position;
scale = new Vector2(size, size);
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
Handles.DrawSolidDisc(new Vector3(scale.x / 2.0f, scale.x / 2.0f, 0.0f), new Vector3(0.0f, 0.0f, -1.0f), scale.x / 2.0f);
}
public override bool Contains(Vector2 point)
{
Rect canvasRect = canvasBoundingRect;
return Vector2.Distance(canvasRect.center, point) <= (scale.x / 2.0f);
}
}
class ResizableBox : SimpleBox
{
public ResizableBox(Vector2 position, float size)
: base(position, size)
{
m_Title = "Resize me!";
AddManipulator(new Resizable());
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
}
}
class WWWImageBox : SimpleBox
{
Texture2D m_WWWTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
WWW www = null;
private float timeToNextPicture = 0.0f;
public WWWImageBox(Vector2 position, float size)
: base(position, size)
{
m_Title = "I cause repaints every frame!";
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
if (www != null && www.isDone)
{
www.LoadImageIntoTexture(m_WWWTexture);
www = null;
timeToNextPicture = 3.0f;
}
timeToNextPicture -= Time.deltaTime;
if (timeToNextPicture < 0.0f)
{
timeToNextPicture = 99999.0f;
www = new WWW("http://lorempixel.com/200/200");
}
base.Render(parentRect, canvas);
GUI.DrawTexture(new Rect(0, 20, 200, 200), m_WWWTexture);
Invalidate();
canvas.Repaint();
}
}
class IMGUIControls : SimpleBox
{
private string m_Text1 = "this is a text field";
private string m_Text2 = "this is a text field";
private bool m_Toggle = true;
private Texture2D m_aTexture = null;
public IMGUIControls(Vector2 position, float size)
: base(position, size)
{
m_Caps = Capabilities.Unselectable;
m_Title = "modal";
AddManipulator(new Draggable());
AddManipulator(new Resizable());
AddManipulator(new ImguiContainer());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
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_aTexture = EditorGUI.ObjectField(new Rect(0, currentY, 80, 100), m_aTexture, typeof(Texture2D), false) as Texture2D;
}
}
}

1
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleCanvas2D.cs


using UnityEngine;
using UnityEditor.Experimental;
#pragma warning disable 0414
#pragma warning disable 0219

50
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Edge.cs


using System;
using UnityEngine;
using UnityEditorInternal;
using UnityEditorInternal.Experimental;
//#pragma warning disable 0414
//#pragma warning disable 0219

internal class Edge<T> : CanvasElement where T : CanvasElement, IConnect
{
private T m_Left;
private T m_Right;
private ICanvasDataSource m_Data;
protected T m_Left;
protected T m_Right;
protected ICanvasDataSource m_Data;
public Edge(ICanvasDataSource data, T left, T right)
{

Vector3 from = m_Left.ConnectPosition();
Vector3 to = m_Right.ConnectPosition();
if (to.x < from.x)
{
Vector3 t = from;
from = to;
to = t;
}
Orientation orientation = m_Left.GetOrientation();
EdgeConnector<T>.GetTangents(from, to, out points, out tangents);
EdgeConnector<T>.GetTangents(m_Left.GetDirection(), 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++)

Vector3 from = m_Left.ConnectPosition();
Vector3 to = m_Right.ConnectPosition();
if (to.x < from.x)
{
Vector3 t = from;
from = to;
to = t;
}
Orientation orientation = m_Left.GetOrientation();
EdgeConnector<T>.GetTangents(from, to, out points, out tangents);
EdgeConnector<T>.GetTangents(m_Left.GetDirection(), orientation, from, to, out points, out tangents);
Vector3[] allPoints = Handles.MakeBezierPoints(points[0], points[1], tangents[0], tangents[1], 20);
float minDistance = Mathf.Infinity;

Vector3 from = m_Left.ConnectPosition();
Vector3 to = m_Right.ConnectPosition();
if (to.x < from.x)
{
Vector3 t = from;
from = to;
to = t;
}
Orientation orientation = m_Left.GetOrientation();
EdgeConnector<T>.GetTangents(from, to, out points, out tangents);
EdgeConnector<T>.GetTangents(m_Left.GetDirection(), 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.color = new Color(0.3f, 0.4f, 1.0f, 1.0f);
Handles.DrawSolidDisc(from, new Vector3(0.0f, 0.0f, -1.0f), 4f);
Handles.DrawSolidDisc(to, new Vector3(0.0f, 0.0f, -1.0f), 4f);
/*if (EditorApplication.isPlaying)
{
Handles.color = Color.red;
Handles.DrawSolidDisc(allPoints[m_RealtimeFeedbackPointIndex], new Vector3(0.0f, 0.0f, -1.0f), 6f);
m_RealtimeFeedbackPointIndex++;
if (m_RealtimeFeedbackPointIndex >= 20)
{
m_RealtimeFeedbackPointIndex = 0;
}
}*/
Handles.color = oldColor;
}

73
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/EdgeConnector.cs


namespace UnityEditor.Experimental.Graph
{
public delegate void EdgeRenderMethod(Canvas2D parent, IConnect source, IConnect target, Vector3 from, Vector3 to);
internal class EdgeConnector<T> : IManipulate where T : IConnect
{
private static readonly Color s_EdgeColor = new Color(1.0f, 1.0f, 1.0f, 0.8f);

private Color m_Color = s_EdgeColor;
private IConnect m_SnappedTarget;
private IConnect m_SnappedSource;
private EdgeRenderMethod m_DrawMethod = null;
private List<IConnect> m_CompatibleAnchors = new List<IConnect>();
private List<IConnect> m_CompatibleAnchors = new List<IConnect>();
public EdgeConnector(EdgeRenderMethod customDrawMethod)
{
m_DrawMethod = customDrawMethod;
}
public EdgeConnector()
{
m_DrawMethod = null;
}
public bool GetCaps(ManipulatorCapability cap)
{
return false;

{
IConnect toCnx = anchor as IConnect;
if (toCnx == null)
continue;
if (cnx.GetOrientation() != toCnx.GetOrientation())
continue;
bool isBidirectional = ((cnx.GetDirection() == Direction.Bidirectional) ||

return false;
}
bool invert = m_End.x < m_Start.x;
if (m_DrawMethod != null)
{
m_DrawMethod(canvas, m_SnappedSource, m_SnappedTarget, m_Start, m_End);
return true;
}
IConnect thisCnx = element as IConnect;
GetTangents(invert ? m_End : m_Start, invert ? m_Start : m_End, out points, out tangents);
IConnect cnx = element as IConnect;
GetTangents(thisCnx.GetDirection(), cnx.GetOrientation(), m_Start, m_End, out points, out tangents);
Handles.DrawBezier(points[0], points[1], tangents[0], tangents[1], m_Color, null, 5f);
// little widget on the middle of the edge

return false;
}
public static void GetTangents(Vector2 start, Vector2 end, out Vector3[] points, out Vector3[] tangents)
public 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;
}
float weight = (start.y < end.y) ? .3f : .7f;
weight = .5f;
float weight = .5f;
if (start.x > end.x)
{
weight2 = weight = -.25f;
float aspect = (start.x - end.x) / (start.y - end.y);
if (Mathf.Abs(aspect) > .5f)
{
float asp = (Mathf.Abs(aspect) - .5f) / 8;
asp = Mathf.Sqrt(asp);
y = Mathf.Min(asp * 80, 80);
if (start.y > end.y)
y = -y;
}
}
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;
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;
}
}
};
}

1
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/IConnect.cs


public interface IConnect
{
Direction GetDirection();
Orientation GetOrientation();
void Highlight(bool highlighted);
void RenderOverlay(Canvas2D canvas);
object Source();

10
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Draggable.cs


}
float scaleFactorX = element == canvas ? 1.0f : 1.0f / canvas.scale.x;
float scaleFactorY = element == canvas ? 1.0f : 1.0f / canvas.scale.y;
if ((element.caps & CanvasElement.Capabilities.Floating) != 0)
{
scaleFactorX = 1.0f;
float scaleFactorY = element == canvas ? 1.0f : 1.0f / canvas.scale.y;
if ((element.caps & CanvasElement.Capabilities.Floating) != 0)
{
scaleFactorX = 1.0f;
scaleFactorY = 1.0f;
}

2
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Frame.cs


parent.Animate(parent)
.Lerp(new string[] { "m_Scale", "m_Translation" },
new object[] { parent.scale, parent.translation },
new object[] { frameScaling, frameTranslation });
new object[] { frameScaling, frameTranslation }, 0.08f);
}
e.Use();

41
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/ImguiContainer.cs


public void AttachTo(CanvasElement element)
{
element.AllEvents += (target, evt, canvas) =>
{
Vector2 canvasPos = canvas.MouseToCanvas(evt.mousePosition);
Rect rect = canvas.CanvasToScreen(element.boundingRect);
GUI.BeginGroup(rect);
element.Render(canvas.boundingRect, canvas);
GUI.EndGroup();
element.AllEvents += Render;
}
private bool Render(CanvasElement target, Event evt, Canvas2D canvas)
{
if (evt.type == EventType.Repaint)
return false;
EventType et = Event.current.type;
Matrix4x4 old = GUI.matrix;
GUI.matrix = Matrix4x4.identity;
Rect screenRect = canvas.CanvasToScreen(target.canvasBoundingRect);
Vector2 normalizedMouseOffset = (Event.current.mousePosition - screenRect.min);
Vector2 screenWidth = (screenRect.max - screenRect.min);
normalizedMouseOffset.x /= screenWidth.x;
normalizedMouseOffset.y /= screenWidth.y;
normalizedMouseOffset.x *= target.boundingRect.width;
normalizedMouseOffset.y *= target.boundingRect.height;
canvas.Repaint();
element.Invalidate();
Vector2 currentMousePosition = Event.current.mousePosition;
Event.current.mousePosition = normalizedMouseOffset;
Event.current.type = et;
return false;
};
target.Render(canvas.boundingRect, canvas);
target.Invalidate();
GUI.matrix = old;
return false;
}
}
}

3
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Resizable.cs


private bool m_Active;
private Vector2 m_Start;
private Vector2 m_MinimumScale;
private GUIStyle style = new GUIStyle("WindowBottomResize");
public Resizable()
{

private bool DrawResizeWidget(CanvasElement element, Event e, Canvas2D parent)
{
GUIStyle style = new GUIStyle("WindowBottomResize");
Rect r = element.boundingRect;
Rect widget = r;
widget.min = new Vector2(r.max.x - 10.0f, r.max.y - 7.0f);

2
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/ScreenSpaceGrid.cs


from = tx.MultiplyPoint(from);
to = tx.MultiplyPoint(to);
Handles.DrawWireDisc(from, new Vector3(0.0f, 0.0f, -1.0f), 6f);
float thickGridLineX = from.x;
float thickGridLineY = from.y;

4
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Zoomable.cs


if (!outOfZoomBounds)
{
element.translation = currentTranslation;
}
}
element.ParentCanvas().RebuildQuadTree();
e.Use();

4
UnityProject/Assets/GraphFramework/Canvas2D/Editor/PropertyData.cs


{
internal class PropertyData
{
public PropertyData(FieldInfo f, object o1, object o2)
public PropertyData(FieldInfo f, object o1, object o2, float animSpeed)
speed = animSpeed;
curve = AnimationCurve.EaseInOut(0.0f, 0.0f, 1.0f, 1.0f); //@todo replace this by google material curve
}

public float time;
public float speed;
public AnimationCurve curve;
}
}

9
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI.meta


fileFormatVersion: 2
guid: b9fdaa3082bcc6e4dab1bdbba8593987
folderAsset: yes
timeCreated: 1454941770
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

64
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/CustomEdge.cs


using System;
using UnityEngine;
namespace UnityEditor.Experimental.Graph.Examples
{
class CustomEdge<T> : Edge<T> where T : CanvasElement, IConnect
{
static private Texture2D m_EdgeTexture = null;
Color edgeColor = Color.white;
public CustomEdge(ICanvasDataSource data, T source, T target)
: base(data, source, target)
{
if (source.ParentCanvas() != null)
source.ParentCanvas().Animate(this).Lerp("edgeColor", new Color(0.0f, 0.0f, 0.0f, 0.2f), Color.white, 0.02f);
m_EdgeTexture = Resources.Load("edge") as Texture2D;
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
Vector3 from = m_Left.ConnectPosition();
Vector3 to = m_Right.ConnectPosition();
Orientation orientation = m_Left.GetOrientation();
Vector3[] points, tangents;
EdgeConnector<T>.GetTangents(m_Left.GetDirection(), orientation, from, to, out points, out tangents);
Handles.DrawBezier(points[0], points[1], tangents[0], tangents[1], edgeColor, m_EdgeTexture, 5f);
}
}
class VerticalNode : CanvasElement
{
public VerticalNode(Vector2 position, float size, Type outputType, NodalDataSource data)
{
m_Translation = position;
m_Scale = new Vector3(size, size, 1.0f);
AddManipulator(new Draggable());
AddChild(new VerticalNodeAnchor(0, new Vector3(size / 2.0f - (NodeAnchor.kNodeSize / 2.0f), 3.0f, 0.0f), outputType, data, Direction.Input));
AddChild(new VerticalNodeAnchor(0, new Vector3(size / 2.0f - (NodeAnchor.kNodeSize / 2.0f), size - NodeAnchor.kNodeSize - 3.0f, 0.0f), outputType, data, Direction.Output));
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
EditorGUI.DrawRect(new Rect(0, 0, m_Scale.x, m_Scale.y), new Color(0.2f, 0.2f, 1.0f, 0.8f));
base.Render(parentRect, canvas);
}
}
internal class VerticalNodeAnchor : NodeAnchor
{
public VerticalNodeAnchor(int portIndex, Vector3 position, Type type, NodalDataSource data, Direction direction)
: base(portIndex, position, type, data, DrawCustomEdgeConnector)
{
m_Orientation = Orientation.Vertical;
m_Direction = direction;
}
static void DrawCustomEdgeConnector(Canvas2D parent, IConnect source, IConnect target, Vector3 from, Vector3 to)
{
Handles.DrawAAPolyLine(15.0f, new[] { from, to });
}
}
}

12
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/CustomEdge.cs.meta


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

9
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Resources.meta


fileFormatVersion: 2
guid: 20e4e36d7a76e114fa2735973796f0ac
folderAsset: yes
timeCreated: 1454696943
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

8
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Orientation.cs


namespace UnityEditor.Experimental.Graph
{
public enum Orientation
{
Horizontal,
Vertical
}
}

12
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Orientation.cs.meta


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

77
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUICanvas2D.cs


using System.Collections.Generic;
using UnityEngine;
#pragma warning disable 0414
#pragma warning disable 0219
namespace UnityEditor.Experimental.Graph.Examples
{
internal class IMGUICanvas2D : EditorWindow
{
[MenuItem("Window/Canvas2D/IMGUI Coexistence Example")]
public static void ShowWindow()
{
GetWindow(typeof(IMGUICanvas2D));
}
private Canvas2D m_Canvas = null;
private EditorWindow m_HostWindow = null;
private List<CanvasElement> m_Data = new List<CanvasElement>();
public void AddElement(CanvasElement e)
{
m_Data.Add(e);
m_Canvas.ReloadData();
var scaling = e.scale;
}
private void InitializeCanvas()
{
if (m_Canvas == null)
{
m_Canvas = new Canvas2D(this, m_HostWindow, new IMGUIDataSource(m_Data));
// draggable manipulator allows to move the canvas around. Note that individual elements can have the draggable manipulator on themselves
m_Canvas.AddManipulator(new Draggable(2, EventModifiers.None));
m_Canvas.AddManipulator(new Draggable(0, EventModifiers.Alt));
// make the canvas zoomable
m_Canvas.AddManipulator(new Zoomable());
// allow framing the selection when hitting "F" (frame) or "A" (all). Basically shows how to trap a key and work with the canvas selection
m_Canvas.AddManipulator(new Frame(Frame.FrameType.All));
m_Canvas.AddManipulator(new Frame(Frame.FrameType.Selection));
// The following manipulator show how to work with canvas2d overlay and background rendering
m_Canvas.AddManipulator(new RectangleSelect());
m_Canvas.AddManipulator(new ScreenSpaceGrid());
AddElement(new IMGUIExampleWidget(new Vector2(0.0f, 250.0f), 300.0f));
}
Rebuild();
}
private void Rebuild()
{
if (m_Canvas == null)
return;
m_Canvas.Clear();
m_Canvas.ReloadData();
m_Canvas.ZSort();
}
void OnGUI()
{
m_HostWindow = this;
if (m_Canvas == null)
{
InitializeCanvas();
}
m_Canvas.OnGUI(this, new Rect(0, 0, position.width, position.height));
}
}
}

12
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUICanvas2D.cs.meta


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

29
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIDataSource.cs


using System.Collections.Generic;
namespace UnityEditor.Experimental.Graph.Examples
{
internal class IMGUIDataSource : ICanvasDataSource
{
List<CanvasElement> m_Elements;
public IMGUIDataSource(List<CanvasElement> m_Data)
{
m_Elements = m_Data;
}
public CanvasElement[] FetchElements()
{
return m_Elements.ToArray();
}
public void DeleteElement(CanvasElement e)
{
m_Elements.Remove(e);
}
public void AddElement(CanvasElement e)
{
m_Elements.Add(e);
}
}
}

12
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIDataSource.cs.meta


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

62
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIWidget.cs


using UnityEngine;
namespace UnityEditor.Experimental.Graph.Examples
{
class IMGUIExampleWidget : CanvasElement
{
private int m_ControlInteger = 0;
private bool m_GUIToggle = false;
private float m_GUIFloatValue = 42.0f;
private string m_SomeText = "<enter some text>";
public Rect windowRect = new Rect(20, 20, 120, 50);
public IMGUIExampleWidget(Vector2 position, float size)
{
translation = position;
scale = new Vector2(size, size);
AddManipulator(new Draggable());
AddManipulator(new Resizable(new Vector2(200, 100.0f)));
AddManipulator(new ImguiContainer());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
EventType t = Event.current.type;
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
Color selectedColor = new Color(1.0f, 0.7f, 0.0f, 0.7f);
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), selected ? selectedColor : backgroundColor);
GUILayout.BeginVertical();
GUILayout.Label("Layout begins here");
if (GUILayout.Button("Layout Buttton" + m_ControlInteger, GUILayout.Width(150)))
{
m_ControlInteger++;
Debug.Log("Layout Button was pressed: " + m_ControlInteger);
}
m_GUIToggle = GUILayout.Toggle(m_GUIToggle, "GUI Toggle");
m_GUIFloatValue = GUILayout.HorizontalSlider(m_GUIFloatValue, 0.0f, 100.0f, GUILayout.Width(150));
m_SomeText = GUILayout.TextField(m_SomeText, GUILayout.Width(200));
GUILayout.Label("Layout ends here");
GUILayout.EndVertical();
float y = 150.0f;
GUI.Label(new Rect(0, y, 150, 30), "No-layout begins here");
if (GUI.Button(new Rect(0, y + 30.0f, 120, 30), "GUI Button:" + m_ControlInteger))
{
m_ControlInteger++;
Debug.Log("GUI Button was pressed: " + m_ControlInteger);
}
m_GUIToggle = GUI.Toggle(new Rect(120, y + 30.0f, 120, 30), m_GUIToggle, "GUI Toggle");
m_GUIFloatValue = GUI.HorizontalSlider(new Rect(0, y + 60.0f, 120, 30), m_GUIFloatValue, 0.0f, 100.0f);
GUI.Label(new Rect(0, y + 90.0f, 120, 30), "No-layout ends here");
}
}
}

12
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIWidget.cs.meta


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

6
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Resources/edge.png

之前 之后
宽度: 1  |  高度: 3  |  大小: 250 B

57
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Resources/edge.png.meta


fileFormatVersion: 2
guid: 5abb892602e9d7148b9146c430302450
timeCreated: 1454697073
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 7
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存