Skip to content

Commit a5bec28

Browse files
committed
Added code to close the scene graph window when the scene is closed
1 parent 24ff872 commit a5bec28

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

Assets/com.alelievr.NodeGraphProcessor/Editor/BaseGraphWindow.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using System.Linq;
1+
using System.Linq;
42
using System;
53
using UnityEngine;
64
using UnityEditor;
7-
using UnityEngine.Assertions;
85
using UnityEngine.UIElements;
9-
using UnityEditor.UIElements;
10-
using UnityEditor.Experimental.GraphView;
6+
using UnityEngine.SceneManagement;
7+
using UnityEditor.SceneManagement;
118

129
namespace GraphProcessor
1310
{
@@ -123,6 +120,27 @@ public void InitializeGraph(BaseGraph graph)
123120
graphView.Initialize(graph);
124121

125122
InitializeGraphView(graphView);
123+
124+
// TOOD: onSceneLinked...
125+
126+
if (graph.IsLinkedToScene())
127+
LinkGraphWindowToScene(graph.GetLinkedScene());
128+
else
129+
graph.onSceneLinked += LinkGraphWindowToScene;
130+
}
131+
132+
void LinkGraphWindowToScene(Scene scene)
133+
{
134+
EditorSceneManager.sceneClosed += CloseWindowWhenSceneIsClosed;
135+
136+
void CloseWindowWhenSceneIsClosed(Scene closedScene)
137+
{
138+
if (scene == closedScene)
139+
{
140+
Close();
141+
EditorSceneManager.sceneClosed -= CloseWindowWhenSceneIsClosed;
142+
}
143+
}
126144
}
127145

128146
public virtual void OnGraphDeleted()

Assets/com.alelievr.NodeGraphProcessor/Runtime/Graph/BaseGraph.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ public class BaseGraph : ScriptableObject, ISerializationCallbackReceiver
137137
public event Action onExposedParameterListChanged;
138138
public event Action< ExposedParameter > onExposedParameterModified;
139139
public event Action< ExposedParameter > onExposedParameterValueChanged;
140+
141+
/// <summary>
142+
/// Triggered when the graph is linked to an active scene.
143+
/// </summary>
144+
public event Action< Scene > onSceneLinked;
145+
140146
/// <summary>
141147
/// Triggered when the graph is enabled
142148
/// </summary>
@@ -685,10 +691,21 @@ public bool SetParameterValue(string name, object value)
685691
/// </summary>
686692
/// <param name="scene">Target scene to link</param>
687693
public void LinkToScene(Scene scene)
688-
=> linkedScene = scene;
689-
694+
{
695+
linkedScene = scene;
696+
onSceneLinked?.Invoke(scene);
697+
}
698+
699+
/// <summary>
700+
/// Return true when the graph is linked to a scene, false otherwise.
701+
/// </summary>
690702
public bool IsLinkedToScene() => linkedScene.IsValid();
691703

704+
/// <summary>
705+
/// Get the linked scene. If there is no linked scene, it returns an invalid scene
706+
/// </summary>
707+
public Scene GetLinkedScene() => linkedScene;
708+
692709
HashSet<BaseNode> infiniteLoopTracker = new HashSet<BaseNode>();
693710
int UpdateComputeOrderBreadthFirst(int depth, BaseNode node)
694711
{

0 commit comments

Comments
 (0)