Tim Cooper
9 年前
当前提交
accce8b1
共有 41 个文件被更改,包括 1294 次插入 和 92 次删除
-
4UnityProject/Assets/GraphFramework/Canvas2D.meta
-
53UnityProject/Assets/GraphFramework/Canvas2D/Editor/Canvas2D.cs
-
53UnityProject/Assets/GraphFramework/Canvas2D/Editor/CanvasAnimation.cs
-
55UnityProject/Assets/GraphFramework/Canvas2D/Editor/CanvasElement.cs
-
2UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Edge.cs
-
2UnityProject/Assets/GraphFramework/Canvas2D/Editor/Layout.meta
-
2UnityProject/Assets/GraphFramework/Canvas2D/Editor/Layout/CanvasLayout.cs.meta
-
2UnityProject/Assets/GraphFramework/Canvas2D/Editor/Layout/CanvasVerticalLayout.cs.meta
-
50UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Draggable.cs
-
101UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Frame.cs
-
2UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/RectangleSelect.cs.meta
-
15UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Resizable.cs
-
16UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/ScreenSpaceGrid.cs
-
2UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Zoomable.cs
-
9UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples.meta
-
9UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation.meta
-
120UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationCanvas2D.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationCanvas2D.cs.meta
-
39UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationDataSource.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/AnimationDataSource.cs.meta
-
96UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/FlexBox.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Animation/FlexBox.cs.meta
-
9UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal.meta
-
66UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalCanvas2D.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalCanvas2D.cs.meta
-
39UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalDataSource.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalDataSource.cs.meta
-
193UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalWidgets.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalWidgets.cs.meta
-
9UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple.meta
-
225UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/ExampleWidgets.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/ExampleWidgets.cs.meta
-
66UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleCanvas2D.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleCanvas2D.cs.meta
-
30UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleDataSource.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleDataSource.cs.meta
-
9UnityProject/Assets/GraphFramework/Examples.meta
|
|||
fileFormatVersion: 2 |
|||
guid: cc01a7f541cf1774e9e6991bdc84abde |
|||
guid: 1b5ae96a5eb352841afac01a561f9f20 |
|||
timeCreated: 1445092807 |
|||
timeCreated: 1453889577 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|
|||
fileFormatVersion: 2 |
|||
guid: b66aa6e87ee581345a628ff2d8953060 |
|||
folderAsset: yes |
|||
timeCreated: 1453895629 |
|||
timeCreated: 1453896766 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7f41ab74fba2d8d40bc59cdeaea4309e |
|||
folderAsset: yes |
|||
timeCreated: 1453896275 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 02837f5858f6ede42a114638307ab5bc |
|||
folderAsset: yes |
|||
timeCreated: 1454076601 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8a5ab5a21ec27bb448a1137d453edc98 |
|||
timeCreated: 1454077311 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bb396815780168c44a3e0ad3d0312c59 |
|||
timeCreated: 1454077312 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c10e62f6cebfd854e8683209c001e5e3 |
|||
timeCreated: 1454076602 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a952c41345df3424a8e559597973d1f3 |
|||
folderAsset: yes |
|||
timeCreated: 1445110932 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5d9e5a2d019354c49be1e4f033989cb4 |
|||
timeCreated: 1445110933 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5c20bd4924c374341a98acfca70d03e3 |
|||
timeCreated: 1445110933 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e44b276cac1cc6342abdf25d7ba86bb2 |
|||
timeCreated: 1445110936 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ae8b0c120c2e6c745b880ba4ad6080b3 |
|||
folderAsset: yes |
|||
timeCreated: 1445093418 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6c0420a11402ba047a601f7d7fe5be02 |
|||
timeCreated: 1445104490 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e2a5a3a05bd86cb44a0472f4d39bc252 |
|||
timeCreated: 1445093419 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 082770099e8693940ae67b186ad1c91f |
|||
timeCreated: 1445099539 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e2cbda12d8ee5324ba86a9be383f8e89 |
|||
folderAsset: yes |
|||
timeCreated: 1445093418 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue