summaryrefslogtreecommitdiffstats
path: root/Scripts/Fold/Editor/FoldWindow.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts/Fold/Editor/FoldWindow.cs')
-rw-r--r--Scripts/Fold/Editor/FoldWindow.cs68
1 files changed, 53 insertions, 15 deletions
diff --git a/Scripts/Fold/Editor/FoldWindow.cs b/Scripts/Fold/Editor/FoldWindow.cs
index 270bc2a..44e373b 100644
--- a/Scripts/Fold/Editor/FoldWindow.cs
+++ b/Scripts/Fold/Editor/FoldWindow.cs
@@ -1,32 +1,70 @@
-using UnityEngine;
using UnityEditor;
-using GraphProcessor;
+using UnityEngine;
+using UnityEngine.UIElements;
-public class FoldWindow : BaseGraphWindow
+public class FoldWindow : EditorWindow
{
const string GraphPath = "Assets/FoldGraph.asset";
+ FoldGraphView graphView;
+ FoldGraph graphAsset;
+
[MenuItem("Tools/yum_food/Fold")]
public static void Open()
{
- var graph = AssetDatabase.LoadAssetAtPath<FoldGraph>(GraphPath);
- if (graph == null)
+ var window = GetWindow<FoldWindow>();
+ window.titleContent = new GUIContent("Fold");
+ window.Show();
+ }
+
+ void OnEnable()
+ {
+ graphAsset = LoadOrCreateGraph();
+ ConstructGraphView();
+ }
+
+ void OnDisable()
+ {
+ if (graphView != null)
+ {
+ rootVisualElement.Remove(graphView);
+ graphView = null;
+ }
+
+ AssetDatabase.SaveAssets();
+ }
+
+ FoldGraph LoadOrCreateGraph()
+ {
+ var asset = AssetDatabase.LoadAssetAtPath<FoldGraph>(GraphPath);
+ if (asset == null)
{
- graph = ScriptableObject.CreateInstance<FoldGraph>();
- AssetDatabase.CreateAsset(graph, GraphPath);
+ asset = CreateInstance<FoldGraph>();
+ AssetDatabase.CreateAsset(asset, GraphPath);
AssetDatabase.SaveAssets();
}
- var w = GetWindow<FoldWindow>();
- w.InitializeGraph(graph);
- w.Show();
+ return asset;
}
- protected override void OnDestroy() => graphView?.Dispose();
+ void ConstructGraphView()
+ {
+ graphView = new FoldGraphView(this, graphAsset)
+ {
+ name = "Fold Graph"
+ };
- protected override void InitializeWindow(BaseGraph graph)
+ graphView.style.flexGrow = 1f;
+ graphView.style.width = Length.Percent(100);
+ graphView.style.height = Length.Percent(100);
+ rootVisualElement.Add(graphView);
+ }
+
+ public void ShowNotification(string message)
{
- titleContent = new GUIContent("Fold");
- if (graphView == null) rootView.Add(graphView = new FoldGraphView(this));
+ if (string.IsNullOrEmpty(message))
+ return;
+
+ ShowNotification(new GUIContent(message));
}
-} \ No newline at end of file
+}