-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventGraphViewWindow.cs
More file actions
88 lines (74 loc) · 2.47 KB
/
EventGraphViewWindow.cs
File metadata and controls
88 lines (74 loc) · 2.47 KB
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
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEditor.Experimental.GraphView;
namespace EventGraph
{
public class EventGraphViewWindow : EditorWindow
{
private EventGraphView _graphView;
private GraphDataAsset _loadedGraphDataAsset;
[MenuItem("Window/Event Graph")]
public static void OpenEventGraphWindow()
{
var window = GetWindow<EventGraphViewWindow>();
window.titleContent = new GUIContent("Event Graph");
}
private void OnEnable()
{
ConstructGraphView();
GenerateToolbar();
}
private void OnDisable()
{
rootVisualElement.Remove(_graphView);
}
private void ConstructGraphView()
{
_graphView = new EventGraphView
{
name = "Event Graph"
};
_graphView.StretchToParentSize();
rootVisualElement.Add(_graphView);
}
private void GenerateToolbar()
{
var toolbar = new Toolbar();
var addButton = new Button(() => { _graphView.AddEventNode(new Vector2(200, 200)); })
{
text = "Add Event Node"
};
var saveButton = new Button(() => { _graphView.SaveGraphData(); })
{
text = "Save Graph"
};
var loadButton = new Button(LoadGraphData)
{
text = "Load Graph Data"
};
toolbar.Add(loadButton);
toolbar.Add(addButton);
toolbar.Add(saveButton);
rootVisualElement.Add(toolbar);
}
private void LoadGraphData()
{
string path = EditorUtility.OpenFilePanel("Load Graph Data", Application.dataPath, "asset");
if (!string.IsNullOrEmpty(path))
{
path = "Assets" + path.Replace(Application.dataPath, "");
_loadedGraphDataAsset = AssetDatabase.LoadAssetAtPath<GraphDataAsset>(path);
if (_loadedGraphDataAsset != null)
{
_graphView.LoadGraphData(_loadedGraphDataAsset);
}
else
{
Debug.LogError("Failed to load graph data asset.");
}
}
}
}
}