summaryrefslogtreecommitdiffstats
path: root/Scripts/Fold/Editor/FoldWindow.cs
blob: 69d706668384215c3dea68989915384742733336 (plain)
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
using UnityEngine;
using UnityEditor;
using GraphProcessor;

public class FoldWindow : BaseGraphWindow
{
    const string DefaultGraphPath = "Assets/FoldGraph.asset";

    [MenuItem("Tools/yum_food/Fold")]
    public static BaseGraphWindow Open()
    {
        var graphWindow = GetWindow<FoldWindow>();

        var graph = AssetDatabase.LoadAssetAtPath<FoldGraph>(DefaultGraphPath);
        if (graph == null)
        {
            graph = ScriptableObject.CreateInstance<FoldGraph>();
            AssetDatabase.CreateAsset(graph, DefaultGraphPath);
            AssetDatabase.SaveAssets();
        }

        graphWindow.InitializeGraph(graph);

        graphWindow.Show();
        return graphWindow;
    }

    protected override void OnDestroy()
    {
        graphView?.Dispose();
    }

    protected override void InitializeWindow(BaseGraph graph)
    {
        titleContent = new GUIContent("Fold");

        // Create the graph view with our custom view
        if (graphView == null)
            graphView = new FoldGraphView(this);

        rootView.Add(graphView);
    }
}