浏览代码

[canvas2d]Import latest canvas2d

/main
Tim Cooper 9 年前
当前提交
accce8b1
共有 41 个文件被更改,包括 1294 次插入92 次删除
  1. 4
      UnityProject/Assets/GraphFramework/Canvas2D.meta
  2. 53
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Canvas2D.cs
  3. 53
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/CanvasAnimation.cs
  4. 55
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/CanvasElement.cs
  5. 2
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Edge.cs
  6. 2
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Layout.meta
  7. 2
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Layout/CanvasLayout.cs.meta
  8. 2
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Layout/CanvasVerticalLayout.cs.meta
  9. 50
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Draggable.cs
  10. 101
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Frame.cs
  11. 2
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/RectangleSelect.cs.meta
  12. 15
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Resizable.cs
  13. 16
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/ScreenSpaceGrid.cs
  14. 2
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Zoomable.cs
  15. 9
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples.meta
  16. 9
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation.meta
  17. 120
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationCanvas2D.cs
  18. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationCanvas2D.cs.meta
  19. 39
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationDataSource.cs
  20. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationDataSource.cs.meta
  21. 96
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/FlexBox.cs
  22. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/FlexBox.cs.meta
  23. 9
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal.meta
  24. 66
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalCanvas2D.cs
  25. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalCanvas2D.cs.meta
  26. 39
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalDataSource.cs
  27. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalDataSource.cs.meta
  28. 193
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalWidgets.cs
  29. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalWidgets.cs.meta
  30. 9
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple.meta
  31. 225
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/ExampleWidgets.cs
  32. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/ExampleWidgets.cs.meta
  33. 66
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleCanvas2D.cs
  34. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleCanvas2D.cs.meta
  35. 30
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleDataSource.cs
  36. 12
      UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleDataSource.cs.meta
  37. 9
      UnityProject/Assets/GraphFramework/Examples.meta

4
UnityProject/Assets/GraphFramework/Canvas2D.meta


fileFormatVersion: 2
guid: cc01a7f541cf1774e9e6991bdc84abde
guid: 1b5ae96a5eb352841afac01a561f9f20
timeCreated: 1445092807
timeCreated: 1453889577
licenseType: Pro
DefaultImporter:
userData:

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


protected List<CanvasElement> m_Elements = new List<CanvasElement>();
protected List<CanvasElement> m_Selection = new List<CanvasElement>();
private QuadTree<CanvasElement> m_QuadTree = new QuadTree<CanvasElement>();
private UnityEditorInternal.Experimental.QuadTree<CanvasElement> m_QuadTree = new UnityEditorInternal.Experimental.QuadTree<CanvasElement>();
private Rect m_CanvasRect;
private Vector2 m_ViewOffset;
private Vector2 m_ViewOffsetUnscaled;

private ModalWindowProc m_CurrentModalWindow;
private Rect m_CurrentModalWindowRect;
private List<CanvasAnimation> m_Animations = new List<CanvasAnimation>();
private bool m_MustRebuildQuadTree = true;
public ICanvasDataSource dataSource
{

Event evt = Event.current;
/*Rect canvasGLArea = clientRectangle;
canvasGLArea.height += canvasGLArea.y;
GL.Viewport(canvasGLArea);*/
if (m_MustRebuildQuadTree)
{
RebuildQuadTree();
}
if (evt.type == EventType.Layout)
if (evt.type == EventType.Repaint)
// tick animations
}
if (evt.type == EventType.Repaint)
{
if (m_Animations.Count > 0)
{
RebuildQuadTree();
Repaint();
}
// render
RecreateRenderTexture();
if (OnBackground != null)

if (evt.isMouse || evt.isKey)
{
if (!clientRectangle.Contains(evt.mousePosition))
if (m_CaptureSession == null && !clientRectangle.Contains(evt.mousePosition))
return;
}

screenRect.max = MouseToCanvas(new Vector2(Screen.width, Screen.height));
List<CanvasElement> visibleElements = m_QuadTree.ContainedBy(screenRect).OrderBy(c => c.zIndex).ToList();
//List<CanvasElement> visibleFloatingElements = m_QuadTree.ContainedBy(screenRect).Where(c => (c.caps & Capabilities.Floating) != 0).OrderBy(c => c.zIndex).ToList();
// update render textures
RenderTexture prev = RenderTexture.active;

m_QuadTree.DebugDraw();
}
OnRenderList(visibleElements, this);
OnRenderList(visibleElements.Where(c => (c.caps & Capabilities.Floating) == 0).ToList(), this, true);
//m_ShowDebug = true;
if (m_ShowDebug)

GUI.EndClip();
GUI.matrix = m;
OnRenderList(visibleElements.Where(c => (c.caps & Capabilities.Floating) != 0).ToList(), this, false);
if (m_ShowDebug)
{

foreach (CanvasElement c in m_Children)
{
Rect childRect = c.boundingRect;
childRect = RectUtils.Inflate(childRect, 1.1f);
m_CanvasRect = RectUtils.Encompass(m_CanvasRect, childRect);
/* if ((c.caps & Capabilities.Floating) != 0)
{
var matrix = Matrix4x4.TRS(m_Translation, Quaternion.identity, m_Scale).inverse;
Vector3 topCorner = new Vector3(childRect.x, childRect.y, 0.0f);
topCorner = matrix.MultiplyPoint(topCorner);
Vector3 bottomCorner = new Vector3(childRect.xMax, childRect.yMax, 0.0f);
bottomCorner = matrix.MultiplyPoint(bottomCorner);
childRect.x = topCorner.x;
childRect.y = topCorner.y;
childRect.width = bottomCorner.x - topCorner.x;
childRect.height = bottomCorner.y - topCorner.y;
}*/
childRect = UnityEditorInternal.Experimental.RectUtils.Inflate(childRect, 1.1f);
m_CanvasRect = UnityEditorInternal.Experimental.RectUtils.Encompass(m_CanvasRect, childRect);
m_MustRebuildQuadTree = false;
}
public bool OnEvent(Event evt)

{
EndCapture();
}
m_MustRebuildQuadTree = true;
return wasUsed;
}

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


m_ElementBeingAnimated.Invalidate();
}
public CanvasAnimation Lerp(string prop, object from, object to)
public CanvasAnimation Lerp(string[] props, object[] from, object[] to)
FieldInfo fi = GetFieldBeingAnimated(prop);
if (fi.FieldType != from.GetType())
if ((props.Length != from.Length) ||
(props.Length != from.Length))
Debug.LogError("Cannot set a " + from.GetType() + " to " + prop + " because it is a " + fi.FieldType);
Debug.LogError("Invalid call to Lerp, parameter count do not match");
var propData = new PropertyData(fi, from, to);
int count = props.Length;
CanvasAnimation currentAnimation = this;
switch (fi.FieldType.Name)
for (int c = 0; c < count; c++)
case "Single":
AddCallback(LerpFloat, propData);
break;
case "Vector3":
AddCallback(LerpVector3, propData);
break;
default:
Debug.LogError("No handler found to lerp " + fi.FieldType.Name);
break;
if (c > 0)
{
// begin a parallel animation
currentAnimation = m_ElementBeingAnimated.ParentCanvas().Animate(m_ElementBeingAnimated);
}
FieldInfo fi = GetFieldBeingAnimated(props[c]);
if (fi.FieldType != from[c].GetType())
{
Debug.LogError("Cannot set a " + from[c].GetType() + " to " + props[c] + " because it is a " + fi.FieldType);
return this;
}
var propData = new PropertyData(fi, from[c], to[c]);
switch (fi.FieldType.Name)
{
case "Single":
currentAnimation.AddCallback(LerpFloat, propData); break;
case "Vector3":
currentAnimation.AddCallback(LerpVector3, 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 });
}
private void LerpFloat(CanvasElement element, CanvasAnimation owner, object userData)

55
UnityProject/Assets/GraphFramework/Canvas2D/Editor/CanvasElement.cs


namespace UnityEditor.Experimental
{
public class CanvasElement : IBounds
public class CanvasElement : UnityEditorInternal.Experimental.IBounds
{
[Flags]
public enum Capabilities

DoesNotCollapse
DoesNotCollapse,
Floating
}
protected int m_ZIndex;

public Canvas2D ParentCanvas()
{
if (this is Canvas2D)
return this as Canvas2D;
CanvasElement e = FindTopMostParent();
if (e is Canvas2D)
return e as Canvas2D;

Rect childRect = e.boundingRect;
childRect.x += rect.x;
childRect.y += rect.y;
rect = RectUtils.Encompass(rect, childRect);
rect = UnityEditorInternal.Experimental.RectUtils.Encompass(rect, childRect);
if ((m_Caps & Capabilities.Floating) != 0)
{
var canvas2d = ParentCanvas();
var matrix = Matrix4x4.TRS(canvas2d.translation, Quaternion.identity, canvas2d.scale).inverse;
Vector3 topCorner = new Vector3(rect.x, rect.y, 0.0f);
topCorner = matrix.MultiplyPoint(topCorner);
Vector3 bottomCorner = new Vector3(rect.xMax, rect.yMax, 0.0f);
bottomCorner = matrix.MultiplyPoint(bottomCorner);
rect.x = topCorner.x;
rect.y = topCorner.y;
rect.width = bottomCorner.x - topCorner.x;
rect.height = bottomCorner.y - topCorner.y;
}
return rect;
}
}

public virtual bool Intersects(Rect rect)
{
if (RectUtils.Contains(rect, canvasBoundingRect))
if (UnityEditorInternal.Experimental.RectUtils.Contains(rect, canvasBoundingRect))
{
return true;
}

private void CreateTexture()
{
Rect textureRect = boundingRect;
textureRect.width = Mathf.Max(textureRect.width, 1.0f);
textureRect.height = Mathf.Max(textureRect.height, 1.0f);
m_Texture = new RenderTexture((int)textureRect.width, (int)textureRect.height, 0, RenderTextureFormat.ARGB32);
}

if (!m_Dirty || !m_SupportsRenderToTexture)
return false;
var bounds = boundingRect;
else if ((int)boundingRect.width != m_Texture.width || (int)boundingRect.height != m_Texture.height)
else if ((int)bounds.width != m_Texture.width || (int)bounds.height != m_Texture.height)
{
Object.DestroyImmediate(m_Texture);
CreateTexture();

}
}
public virtual void OnRenderList(List<CanvasElement> visibleList, Canvas2D parent)
public virtual void OnRenderList(List<CanvasElement> visibleList, Canvas2D parent, bool renderWidgets)
max = parent.MouseToCanvas(new Vector2(Screen.width, Screen.height))
max = parent.MouseToCanvas(new Vector2(parent.clientRect.width, parent.clientRect.height))
};
Rect thisRect = boundingRect;
for (int i = 0; i < visibleList.Count; i++)

{
float ratio = 1.0f;
float ratioY = 1.0f;
float ratioX = 1.0f;
Rect r = new Rect(e.translation.x, e.translation.y, e.texture.width, e.texture.height);
if (r.y < screenRect.y)
{

if (r.height < 0.0f)
r.height = 0.0f;
ratio = r.height / e.texture.height;
ratioY = r.height / e.texture.height;
Graphics.DrawTexture(r, e.texture, new Rect(0, 0, 1.0f, ratio), 0, 0, 0, 0);
if (r.xMax > screenRect.xMax)
{
float overlap = r.xMax - screenRect.xMax;
r.width -= overlap;
if (r.width < 0.0f)
r.width = 0.0f;
ratioX = r.width / e.texture.width;
}
Graphics.DrawTexture(r, e.texture, new Rect(0, 0, ratioX, ratioY), 0, 0, 0, 0);
}
else
e.Render(thisRect, parent);

if (OnWidget != null)
if (OnWidget != null && renderWidgets)
OnWidget(this, Event.current, parent);
}

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


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))
if (UnityEditorInternal.Experimental.RectUtils.IntersectsSegment(rect, segmentA, segmentB))
return true;
}

2
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Layout.meta


fileFormatVersion: 2
guid: b66aa6e87ee581345a628ff2d8953060
folderAsset: yes
timeCreated: 1453895629
timeCreated: 1453896766
licenseType: Pro
DefaultImporter:
userData:

2
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Layout/CanvasLayout.cs.meta


fileFormatVersion: 2
guid: 6962f04c3435c0e4a99a7361ff10ba32
timeCreated: 1453895629
timeCreated: 1453896767
licenseType: Pro
MonoImporter:
serializedVersion: 2

2
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Layout/CanvasVerticalLayout.cs.meta


fileFormatVersion: 2
guid: 4af706ffecc72fc4187eda927b3e1569
timeCreated: 1453895629
timeCreated: 1453896767
licenseType: Pro
MonoImporter:
serializedVersion: 2

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


internal class Draggable : IManipulate
{
private EventModifiers m_ActivatorModifiers;
private int m_ActivatorButton;
private int m_ActivatorButton = 0;
private bool m_UseDragRegion = false;
private Rect m_DragRegion;
private bool m_DragRegionIsNormalized = false;
public Draggable(Rect activeDragRegion, bool normalized)
{
m_DragRegion = activeDragRegion;
m_DragRegionIsNormalized = normalized;
m_UseDragRegion = true;
m_ActivatorButton = 0;
m_ActivatorModifiers = EventModifiers.None;
}
public Draggable()
{

return false;
}
if (m_UseDragRegion)
{
var dragRegion = ComputeDragRegion(element, true);
if (!dragRegion.Contains(canvas.MouseToCanvas(e.mousePosition)))
{
return false;
}
}
canvas.StartCapture(this, element);
e.Use();

public Rect ComputeDragRegion(CanvasElement element, bool canvasSpace)
{
Rect dragRegion = canvasSpace ? element.canvasBoundingRect : element.boundingRect;
if (m_DragRegionIsNormalized)
{
Rect bounds = dragRegion;
dragRegion.x += bounds.width * m_DragRegion.x;
dragRegion.y += bounds.height * m_DragRegion.y;
dragRegion.width = (bounds.width * m_DragRegion.width) - (bounds.width * m_DragRegion.x);
dragRegion.height = (bounds.height * m_DragRegion.height) - (bounds.height * m_DragRegion.y);
}
else
{
dragRegion.x += m_DragRegion.x;
dragRegion.y += m_DragRegion.y;
dragRegion.width = m_DragRegion.width;
dragRegion.height = m_DragRegion.height;
}
return dragRegion;
}
private bool EndDrag(CanvasElement element, Event e, Canvas2D canvas)
{
if (e.type == EventType.Used)

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;
scaleFactorY = 1.0f;
}
Vector3 tx = element.translation;
tx.x += e.delta.x * scaleFactorX;

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


};
private readonly FrameType m_Type;
private bool m_Animate = true;
}
public Frame(FrameType type, bool animate)
{
m_Type = type;
m_Animate = animate;
}
public bool GetCaps(ManipulatorCapability cap)

public void AttachTo(CanvasElement element)
{
element.KeyDown += KeyDown;
element.DoubleClick += (elem, evt, Canvas) =>
{
return true;
};
}
private bool KeyDown(CanvasElement element, Event e, Canvas2D parent)

rectToFit = s[0].boundingRect;
foreach (CanvasElement c in s)
{
rectToFit = RectUtils.Encompass(rectToFit, c.boundingRect);
rectToFit = UnityEditorInternal.Experimental.RectUtils.Encompass(rectToFit, c.boundingRect);
// bring slightly smaller screen rect into GUI space
Rect screenRect = new Rect();
screenRect.xMin = 50;
screenRect.xMax = Screen.width - 50;
screenRect.yMin = 50;
screenRect.yMax = Screen.height - 50;
Vector3 frameTranslation = Vector3.zero;
Vector3 frameScaling = Vector3.one;
CalculateFrameTransform(parent, rectToFit, out frameTranslation, out frameScaling);
if (m_Animate == false)
{
parent.scale = frameScaling;
parent.translation = frameTranslation;
}
else
{
parent.Animate(parent)
.Lerp(new string[] { "m_Scale", "m_Translation" },
new object[] { parent.scale, parent.translation },
new object[] { frameScaling, frameTranslation });
}
e.Use();
return true;
}
return false;
}
void CalculateFrameTransform(Canvas2D parent, Rect rectToFit, out Vector3 frameTranslation, out Vector3 frameScaling)
{
// bring slightly smaller screen rect into GUI space
Rect screenRect = new Rect();
screenRect.xMin = 50;
screenRect.xMax = parent.clientRect.width - 50;
screenRect.yMin = 50;
screenRect.yMax = parent.clientRect.height - 50;
Matrix4x4 m = GUI.matrix;
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);
Rect identity = GUIUtility.ScreenToGUIRect(screenRect);
Matrix4x4 m = GUI.matrix;
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);
Rect identity = GUIUtility.ScreenToGUIRect(screenRect);
// measure zoom level necessary to fit the canvas rect into the screen rect
float zoomLevel = Math.Min(identity.width / rectToFit.width, identity.height / rectToFit.height);
// measure zoom level necessary to fit the canvas rect into the screen rect
float zoomLevel = Math.Min(identity.width / rectToFit.width, identity.height / rectToFit.height);
// clamp
zoomLevel = Mathf.Clamp(zoomLevel, 0.08f, 1.0f);
// clamp
zoomLevel = Mathf.Clamp(zoomLevel, 0.08f, 1.0f);
parent.scale = new Vector3(zoomLevel, zoomLevel, 1.0f);
parent.translation = Vector3.zero;
Vector3 cachedScale = parent.scale;
Vector3 cachedTranslation = parent.translation;
parent.scale = new Vector3(zoomLevel, zoomLevel, 1.0f);
parent.translation = Vector3.zero;
// make a rect of the screen in GUI space and measure the distance between that rect
// and the canvas rect. Multiply this by the scale level to get the offset to center the view
Vector2 edge = parent.MouseToCanvas(new Vector2(Screen.width, Screen.height));
Vector2 origin = parent.MouseToCanvas(new Vector2(0.0f, 0.0f));
Rect r = new Rect();
r.min = origin;
r.max = edge;
// make a rect of the screen in GUI space and measure the distance between that rect
// and the canvas rect. Multiply this by the scale level to get the offset to center the view
Vector2 edge = parent.MouseToCanvas(new Vector2(parent.clientRect.width, parent.clientRect.height));
Vector2 origin = parent.MouseToCanvas(new Vector2(0.0f, 0.0f));
Vector2 offset = (r.center - rectToFit.center) * parent.scale.x;
parent.translation = new Vector3(offset.x, offset.y, 0.0f);
Rect r = new Rect();
r.min = origin;
r.max = edge;
GUI.matrix = m;
Vector2 offset = (r.center - rectToFit.center) * parent.scale.x;
parent.translation = new Vector3(offset.x, offset.y, 0.0f);
e.Use();
frameTranslation = parent.translation;
frameScaling = parent.scale;
return true;
}
parent.scale = cachedScale;
parent.translation = cachedTranslation;
return false;
GUI.matrix = m;
}
};
}

2
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/RectangleSelect.cs.meta


fileFormatVersion: 2
guid: a58257dc242be394084635b5e4375312
timeCreated: 1453895629
timeCreated: 1453896767
licenseType: Pro
MonoImporter:
serializedVersion: 2

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


{
private bool m_Active;
private Vector2 m_Start;
private Vector2 m_MinimumScale;
public Resizable()
{
m_MinimumScale = new Vector2(0.1f, 0.1f);
}
public Resizable(Vector2 minimumScale)
{
m_MinimumScale = minimumScale;
}
public bool GetCaps(ManipulatorCapability cap)
{

Vector2 diff = newPosition - m_Start;
m_Start = newPosition;
Vector3 newScale = element.scale;
newScale.x = Mathf.Max(0.1f, newScale.x + diff.x);
newScale.y = Mathf.Max(0.1f, newScale.y + diff.y);
newScale.x = Mathf.Max(m_MinimumScale.x, newScale.x + diff.x);
newScale.y = Mathf.Max(m_MinimumScale.y, newScale.y + diff.y);
element.scale = newScale;

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


{
private readonly float m_Spacing = 50f;
private readonly int m_ThickLines = 10;
private readonly Color m_LineColor = new Color(0f, 0f, 0f, 0.18f);
private readonly Color m_ThickLineColor = new Color(0f, 0f, 0f, 0.38f);
private readonly Color m_Background = new Color(0.17f, 0.17f, 0.17f, 1.0f);
//private Color m_Background = new Color(1.0f, 1.0f, 1.0f, 1.0f);
private Color m_LineColor = new Color(0f, 0f, 0f, 0.18f);
private Color m_ThickLineColor = new Color(0f, 0f, 0f, 0.38f);
private Color m_Background = new Color(0.17f, 0.17f, 0.17f, 1.0f);
public ScreenSpaceGrid(Color lineColor, Color thickLineColor, Color backgroundColor)
{
m_LineColor = lineColor;
m_ThickLineColor = thickLineColor;
m_Background = backgroundColor;
}
public ScreenSpaceGrid(float spacing, int thickLineFrequency, Color lineColor, Color thickLineColor, Color background)
{

private bool DrawGrid(CanvasElement element, Event e, Canvas2D canvas)
{
Rect clientRect = new Rect(0, canvas.clientRect.y, Screen.width, Screen.height);
Rect clientRect = new Rect(0, canvas.clientRect.y, canvas.clientRect.width, canvas.clientRect.height);
// background
UIHelpers.ApplyWireMaterial();

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


element.translation = currentTranslation;
}
element.ParentCanvas().RebuildQuadTree();
e.Use();
return true;
}

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


fileFormatVersion: 2
guid: 7f41ab74fba2d8d40bc59cdeaea4309e
folderAsset: yes
timeCreated: 1453896275
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


fileFormatVersion: 2
guid: 02837f5858f6ede42a114638307ab5bc
folderAsset: yes
timeCreated: 1454076601
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

120
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationCanvas2D.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Experimental;
using Object = UnityEngine.Object;
#pragma warning disable 0414
#pragma warning disable 0219
namespace UnityEditor
{
internal class AnimationCanvas2D : EditorWindow
{
[MenuItem("Window/Canvas2D/Animation Example")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(AnimationCanvas2D));
}
private Canvas2D m_Canvas = null;
private EditorWindow m_HostWindow = null;
private List<CanvasElement> m_Data = new List<CanvasElement>();
private int k_sideDashBoardSize = 200;
private int k_sideDashBoardPadding = 4;
public void AddElement(CanvasElement e)
{
m_Data.Add(e);
m_Canvas.ReloadData();
var scaling = e.scale;
m_Canvas.Animate(e).Lerp("m_Scale", new Vector3(0.1f, 0.1f, 0.1f), scaling);
}
private void InitializeCanvas()
{
if (m_Canvas == null)
{
m_Canvas = new Canvas2D(this, m_HostWindow, new AnimationDataSource(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());
m_Canvas.AddManipulator(new ContextualMenu((e, parent, customData) =>
{
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent("Add FlexBox"), false, (canvas) =>
{
var pos = m_Canvas.MouseToCanvas(e.mousePosition);
AddElement(new FlexBox(pos, 250.0f));
}
, this);
menu.ShowAsContext();
return false;
}));
}
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 - k_sideDashBoardSize, position.height));
GUILayout.BeginArea(new Rect(position.width - k_sideDashBoardSize + k_sideDashBoardPadding, 0, k_sideDashBoardSize - (k_sideDashBoardPadding * 2), position.height));
GUILayout.Space(3f);
GUILayout.Label("This example shows the Canvas2D.Animate feature which enabled any CanvasElement property to be animated. You can chain animations together to create sequences, or animate many parameters simultaneously.", EditorStyles.helpBox);
GUILayout.Space(3f);
if (GUILayout.Button(new GUIContent("Clear Canvas")))
{
m_Data.Clear();
Rebuild();
}
GUILayout.Space(3f);
if (GUILayout.Button(new GUIContent("Create Animated FlexBox", "Add a new animated flexbox to the canvas")))
{
Vector2 spawnPosition = new Vector2(UnityEngine.Random.Range(m_Canvas.clientRect.x, m_Canvas.clientRect.width),
UnityEngine.Random.Range(m_Canvas.clientRect.y, m_Canvas.clientRect.height - 50.0f));
AddElement(new FlexBox(spawnPosition, 250.0f));
}
m_Canvas.showQuadTree = GUILayout.Toggle(m_Canvas.showQuadTree, new GUIContent("Show Debug Info", "Turns debug info on and off"));
GUILayout.EndArea();
}
}
}

12
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationCanvas2D.cs.meta


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

39
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationDataSource.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using Object = UnityEngine.Object;
namespace UnityEditor
{
internal class AnimationDataSource : ICanvasDataSource
{
List<CanvasElement> m_Elements;
public AnimationDataSource(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);
}
public void Connect(NodeAnchor a, NodeAnchor b)
{
m_Elements.Add(new Edge<NodeAnchor>(this, a, b));
}
}
}

12
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationDataSource.cs.meta


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

96
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/FlexBox.cs


using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.IO.Pipes;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Cryptography;
using System.Text;
using System.IO;
using System.Reflection;
using UnityEngine;
using UnityEditor.Animations;
using UnityEditor.Experimental;
using UnityEditorInternal;
using UnityEngine.Experimental.Director;
using Object = UnityEngine.Object;
namespace UnityEditor
{
class ColoredBlockUI : CanvasElement
{
Color m_Color;
public float m_Alpha = 0.0f;
public ColoredBlockUI(float height)
{
m_Scale = new Vector3(0.0f, height, 0.0f);
m_Color = UnityEngine.Random.ColorHSV();
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
Color c = GUI.color;
GUI.color = new Color(1.0f, 1.0f, 1.0f, m_Alpha);
EditorGUI.DrawRect(new Rect(0, translation.y, scale.x, scale.y), m_Color);
GUI.color = c;
}
}
class FlexBox : MoveableBox
{
private float m_FooterHeight = 15;
private float m_ButtonWidth = 80.0f;
public FlexBox(Vector2 position, float size)
: base(position, size)
{
m_Title = "flexbox";
AddManipulator(new Draggable());
AddManipulator(new Resizable(new Vector2(m_ButtonWidth + 4.0f, 100.0f)));
AddManipulator(new ImguiContainer());
}
public override void Layout()
{
float height = 50;
for (int c = 0; c < m_Children.Count; c++)
{
var tx = m_Children[c].translation;
tx.y = height;
m_Children[c].translation = tx;
var s = m_Children[c].scale;
s.x = scale.x;
m_Children[c].scale = s;
height += m_Children[c].boundingRect.height;
}
height += m_FooterHeight;
scale = new Vector2(scale.x, height);
base.Layout();
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
var currentEvent = Event.current.type;
base.Render(parentRect, canvas);
if (GUI.Button(new Rect((m_Scale.x / 2.0f) - (m_ButtonWidth / 2.0f), 22, m_ButtonWidth, 20), "grow"))
{
ColoredBlockUI nb = new ColoredBlockUI(UnityEngine.Random.Range(30.0f, 78.0f));
AddChild(nb);
canvas.Animate(nb)
.Lerp("m_Scale", new Vector3(scale.x, 0.0f, 0.0f), new Vector3(scale.x, nb.scale.y, 0.0f))
.Lerp("m_Alpha", 0.0f, 1.0f)
.Then((elem, anim, userData) =>
{
anim.Done();
});
Invalidate();
canvas.Repaint();
}
EditorGUI.DrawRect(new Rect(canvas.CanvasToScreen(boundingRect.center), new Vector2(2.0f, 2.0f)), Color.red);
}
}
}

12
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/FlexBox.cs.meta


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

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


fileFormatVersion: 2
guid: a952c41345df3424a8e559597973d1f3
folderAsset: yes
timeCreated: 1445110932
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

66
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalCanvas2D.cs


using UnityEngine;
using UnityEditor.Experimental;
#pragma warning disable 0414
#pragma warning disable 0219
namespace UnityEditor
{
internal class NodalCanvas2D : EditorWindow
{
[MenuItem("Window/Canvas2D/Nodal UI")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(NodalCanvas2D));
}
private Canvas2D m_Canvas = null;
private EditorWindow m_HostWindow = null;
private void InitializeCanvas()
{
if (m_Canvas == null)
{
m_Canvas = new Canvas2D(this, m_HostWindow, new NodalDataSource());
// 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());
}
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/Nodal/NodalCanvas2D.cs.meta


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

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


using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
namespace UnityEditor
{
internal class NodalDataSource : ICanvasDataSource
{
List<CanvasElement> m_Elements = new List<CanvasElement>();
public NodalDataSource()
{
m_Elements.Add(new InvisibleBorderContainer(new Vector2(630.0f, 0.0f), 200.0f, true));
m_Elements.Add(new InvisibleBorderContainer(new Vector2(630.0f, 210.0f), 200.0f, false));
m_Elements.Add(new Circle(new Vector2(630.0f, 420.0f), 200.0f));
m_Elements.Add(new Node(Vector2.zero, 200.0f, typeof(Vector3), this));
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));
}
public CanvasElement[] FetchElements()
{
return m_Elements.ToArray();
}
public void DeleteElement(CanvasElement e)
{
m_Elements.Remove(e);
}
public void Connect(NodeAnchor a, NodeAnchor b)
{
m_Elements.Add(new Edge<NodeAnchor>(this, a, b));
}
}
}

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


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

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


using System;
using UnityEngine;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
namespace UnityEditor
{
class PortSource<T>
{
}
class Node : MoveableBox
{
Type m_OutputType;
public Node(Vector2 position, float size, Type outputType, NodalDataSource data)
: base(position, size)
{
m_Title = "Some Operator";
m_OutputType = outputType;
Vector3 pos = new Vector3(5.0f, 32.0f, 0.0f);
AddChild(new NodeAnchor(0, pos, typeof(int), this, data));
pos.y += 22;
AddChild(new NodeAnchor(1, pos, typeof(float), this, data));
pos.y += 22;
AddChild(new NodeAnchor(2, pos, typeof(Vector3), this, data));
pos.y += 22;
AddChild(new NodeAnchor(3, pos, typeof(Texture2D), this, data));
pos.y += 22;
AddChild(new NodeAnchor(4, pos, typeof(Color), this, data));
pos.y += 22;
// output port
pos.x = size - 20.0f;
AddChild(new NodeOutputAnchor(pos, m_OutputType, this, data));
pos.y += 22;
scale = new Vector3(scale.x, pos.y + 12.0f, 0.0f);
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
}
}
internal class NodeAnchor : CanvasElement, IConnect
{
protected Type m_Type;
protected object m_Source;
protected Direction m_Direction;
private NodalDataSource m_Data;
public Node m_Node;
public int m_PortIndex;
public NodeAnchor(int portIndex, Vector3 position, Type type, Node node, NodalDataSource data)
{
m_Type = type;
scale = new Vector3(15.0f, 15.0f, 1.0f);
translation = position;
AddManipulator(new EdgeConnector<NodeAnchor>());
m_Direction = Direction.Input;
Type genericClass = typeof(PortSource<>);
Type constructedClass = genericClass.MakeGenericType(type);
m_Source = Activator.CreateInstance(constructedClass);
m_Data = data;
m_Node = node;
m_PortIndex = portIndex;
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
var anchorColor = Color.yellow;
anchorColor.a = 0.7f;
base.Render(parentRect, canvas);
EditorGUI.DrawRect(new Rect(translation.x, translation.y, scale.x, scale.y), anchorColor);
Rect labelRect = new Rect(translation.x + scale.x + 10.0f, translation.y, parentRect.width, 20.0f);
GUI.Label(labelRect, m_Type.Name);
}
// IConnect
public Direction GetDirection()
{
return m_Direction;
}
public void Highlight(bool highlighted)
{
}
public void RenderOverlay(Canvas2D canvas)
{
Rect thisRect = canvasBoundingRect;
thisRect.x += 4;
thisRect.y += 4;
thisRect.width -= 8;
thisRect.height -= 8;
thisRect = canvas.CanvasToScreen(thisRect);
EditorGUI.DrawRect(thisRect, new Color(0.0f, 0.0f, 0.8f));
}
public object Source()
{
return m_Source;
}
public Vector3 ConnectPosition()
{
return canvasBoundingRect.center;
}
public void OnConnect(IConnect other)
{
if (other == null)
return;
NodeAnchor otherAnchor = other as NodeAnchor;
m_Data.Connect(this, otherAnchor);
ParentCanvas().ReloadData();
}
};
internal class NodeOutputAnchor : NodeAnchor
{
public NodeOutputAnchor(Vector3 position, Type type, Node node, NodalDataSource data)
: base(-1, position, type, node, data)
{
m_Direction = Direction.Output;
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
var anchorColor = Color.yellow;
anchorColor.a = 0.7f;
base.Render(parentRect, canvas);
EditorGUI.DrawRect(new Rect(translation.x, translation.y, scale.x, scale.y), anchorColor);
Vector2 sizeOfText = GUIStyle.none.CalcSize(new GUIContent(m_Type.Name));
Rect labelRect = new Rect(translation.x - sizeOfText.x - 4.0f, translation.y, sizeOfText.x + 4.0f, sizeOfText.y + 4.0f);
GUI.Label(labelRect, m_Type.Name);
}
};
internal static class MyNodeAdapters
{
internal static bool Adapt(this NodeAdapter value, PortSource<int> a, PortSource<int> b)
{
// run adapt code for int to int connections
return true;
}
internal static bool Adapt(this NodeAdapter value, PortSource<float> a, PortSource<float> b)
{
// run adapt code for float to float connections
return true;
}
internal static bool Adapt(this NodeAdapter value, PortSource<int> a, PortSource<float> b)
{
// run adapt code for int to float connections, perhaps by insertion a conversion node
return true;
}
internal static bool Adapt(this NodeAdapter value, PortSource<Vector3> a, PortSource<Vector3> b)
{
// run adapt code for vec3 to vec3 connections
return true;
}
internal static bool Adapt(this NodeAdapter value, PortSource<Color> a, PortSource<Color> b)
{
// run adapt code for Color to Color connections
return true;
}
internal static bool Adapt(this NodeAdapter value, PortSource<Vector3> a, PortSource<Color> b)
{
// run adapt code for vec3 to Color connections
return true;
}
internal static bool Adapt(this NodeAdapter value, PortSource<Color> a, PortSource<Vector3> b)
{
// run adapt code for Color to vec3 connections
return true;
}
}
}

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


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

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


fileFormatVersion: 2
guid: ae8b0c120c2e6c745b880ba4ad6080b3
folderAsset: yes
timeCreated: 1445093418
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


using UnityEngine;
using UnityEditor.Experimental;
namespace UnityEditor
{
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;
}
}
}

12
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/ExampleWidgets.cs.meta


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

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


using UnityEngine;
using UnityEditor.Experimental;
#pragma warning disable 0414
#pragma warning disable 0219
namespace UnityEditor
{
internal class SimpleCanvas2D : EditorWindow
{
[MenuItem("Window/Canvas2D/SimpleCanvas2D")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(SimpleCanvas2D));
}
private Canvas2D m_Canvas = null;
private EditorWindow m_HostWindow = null;
private void InitializeCanvas()
{
if (m_Canvas == null)
{
m_Canvas = new Canvas2D(this, m_HostWindow, new SimpleDataSource());
// 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());
}
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/Simple/SimpleCanvas2D.cs.meta


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

30
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleDataSource.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Experimental;
namespace UnityEditor
{
internal class SimpleDataSource : ICanvasDataSource
{
List<CanvasElement> m_Elements = new List<CanvasElement>();
public SimpleDataSource()
{
m_Elements.Add(new SimpleBox(Vector2.zero, 200.0f));
m_Elements.Add(new MoveableBox(new Vector2(400.0f, 400.0f), 200.0f));
m_Elements.Add(new ResizableBox(new Vector2(400.0f, 200.0f), 100.0f));
m_Elements.Add(new WWWImageBox(new Vector2(300.0f, 300.0f), 200.0f));
m_Elements.Add(new IMGUIControls(new Vector2(100.0f, 200.0f), 100.0f));
}
public CanvasElement[] FetchElements()
{
return m_Elements.ToArray();
}
public void DeleteElement(CanvasElement e)
{
m_Elements.Remove(e);
}
}
}

12
UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleDataSource.cs.meta


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

9
UnityProject/Assets/GraphFramework/Examples.meta


fileFormatVersion: 2
guid: e2cbda12d8ee5324ba86a9be383f8e89
folderAsset: yes
timeCreated: 1445093418
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存