-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDiagramEditorWindow.cs
96 lines (68 loc) · 1.85 KB
/
DiagramEditorWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System;
public abstract class DiagramEditorWindow : EditorWindow
{
protected DiagramRoot currentDiagramRoot;
private DiagramContext diagramContext ;
protected DiagramTool currentDiagramTool;
public DiagramRoot GetRoot ()
{
return currentDiagramRoot;
}
protected abstract DiagramRoot getDiagramRoot (GameObject activeGameObject);
protected abstract string GetNullDiagramRootMessage ();
public DiagramEditorWindow ()
{
diagramContext = new DiagramContext (this);
}
void log (string txt)
{
//Debug.Log (txt);
}
void OnSelectionChange ()
{
currentDiagramRoot = getDiagramRoot ();
Repaint ();
}
protected DiagramRoot getDiagramRoot ()
{
GameObject gameObject = Selection.activeGameObject;
if (!gameObject) {
return null;
}
return getDiagramRoot (gameObject);
}
void OnGUI ()
{
if (currentDiagramRoot == null) {
string msg = GetNullDiagramRootMessage ();
GUI.Label (new Rect (20, 20, 300, 100), msg);
return;
}
//Diagram Tool
currentDiagramTool = currentDiagramRoot.GetTool(diagramContext);
if (currentDiagramTool == null) {
currentDiagramTool = new DiagramDefaultTool ();
}
if (currentDiagramTool.OnGUI (diagramContext)) {
//Update Anchors position
foreach (DiagramNode node in currentDiagramRoot.nodes) {
foreach (DiagramEdge edge in node.edges) {
edge.UpdateAnchor (diagramContext);
}
}
// Draw DiagramRoot and children
currentDiagramRoot.Draw (diagramContext);
//Draw Selected Element handles
List<DiagramElement> elements = diagramContext.GetSelection ().GetElements ();
foreach (DiagramElement elm in elements) {
elm.DrawHandle (diagramContext);
}
//Draw Tools
}
//OnGUIimpl();
}
protected abstract void OnGUIimpl ();
}