Tim Cooper
9 年前
当前提交
15591be8
共有 32 个文件被更改,包括 807 次插入 和 353 次删除
-
58UnityProject/Assets/GraphFramework/Canvas2D/Editor/Canvas2D.cs
-
30UnityProject/Assets/GraphFramework/Canvas2D/Editor/CanvasAnimation.cs
-
9UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalDataSource.cs
-
44UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/NodalWidgets.cs
-
447UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/ExampleWidgets.cs
-
1UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Simple/SimpleCanvas2D.cs
-
50UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Edge.cs
-
73UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/EdgeConnector.cs
-
1UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/IConnect.cs
-
10UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Draggable.cs
-
2UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Frame.cs
-
41UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/ImguiContainer.cs
-
3UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Resizable.cs
-
2UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/ScreenSpaceGrid.cs
-
4UnityProject/Assets/GraphFramework/Canvas2D/Editor/Manipulators/Zoomable.cs
-
4UnityProject/Assets/GraphFramework/Canvas2D/Editor/PropertyData.cs
-
9UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI.meta
-
64UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/CustomEdge.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Nodal/CustomEdge.cs.meta
-
9UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Resources.meta
-
8UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Orientation.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Graph/Orientation.cs.meta
-
77UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUICanvas2D.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUICanvas2D.cs.meta
-
29UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIDataSource.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIDataSource.cs.meta
-
62UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIWidget.cs
-
12UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/IMGUI/IMGUIWidget.cs.meta
-
6UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Resources/edge.png
-
57UnityProject/Assets/GraphFramework/Canvas2D/Editor/Examples/Resources/edge.png.meta
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b9fdaa3082bcc6e4dab1bdbba8593987 |
|||
folderAsset: yes |
|||
timeCreated: 1454941770 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 }); |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7d0bd36cf6d6649428b405d292ed92e9 |
|||
timeCreated: 1454687477 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 20e4e36d7a76e114fa2735973796f0ac |
|||
folderAsset: yes |
|||
timeCreated: 1454696943 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEditor.Experimental.Graph |
|||
{ |
|||
public enum Orientation |
|||
{ |
|||
Horizontal, |
|||
Vertical |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7f10af2a2e9bcb24aa94d1c5e8cb904e |
|||
timeCreated: 1454699653 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c866a70f749cf8e4195710539ab8de34 |
|||
timeCreated: 1454941770 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a4c48985993b70f4995ef129b6fdda80 |
|||
timeCreated: 1454941770 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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"); |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1ed59ab8b2422c9459566af3c37116f6 |
|||
timeCreated: 1454942229 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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: |
撰写
预览
正在加载...
取消
保存
Reference in new issue