diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs
index 08b0a56..24bd8f5 100644
--- a/Scripts/Editor/NodeEditorWindow.cs
+++ b/Scripts/Editor/NodeEditorWindow.cs
@@ -70,6 +70,20 @@ namespace XNodeEditor {
if (graphEditor != null && NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
}
+ [InitializeOnLoadMethod]
+ private static void OnLoad() {
+ Selection.selectionChanged -= OnSelectionChanged;
+ Selection.selectionChanged += OnSelectionChanged;
+ }
+
+ /// Handle Selection Change events
+ private static void OnSelectionChanged() {
+ XNode.NodeGraph nodeGraph = Selection.activeObject as XNode.NodeGraph;
+ if (nodeGraph && !AssetDatabase.Contains(nodeGraph)) {
+ Open(nodeGraph);
+ }
+ }
+
/// Create editor window
public static NodeEditorWindow Init() {
NodeEditorWindow w = CreateInstance();
@@ -147,14 +161,21 @@ namespace XNodeEditor {
public static bool OnOpen(int instanceID, int line) {
XNode.NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as XNode.NodeGraph;
if (nodeGraph != null) {
- NodeEditorWindow w = GetWindow(typeof(NodeEditorWindow), false, "xNode", true) as NodeEditorWindow;
- w.wantsMouseMove = true;
- w.graph = nodeGraph;
+ Open(nodeGraph);
return true;
}
return false;
}
+ /// Open the provided graph in the NodeEditor
+ public static void Open(XNode.NodeGraph graph) {
+ if (!graph) return;
+
+ NodeEditorWindow w = GetWindow(typeof(NodeEditorWindow), false, "xNode", true) as NodeEditorWindow;
+ w.wantsMouseMove = true;
+ w.graph = graph;
+ }
+
/// Repaint all open NodeEditorWindows.
public static void RepaintAll() {
NodeEditorWindow[] windows = Resources.FindObjectsOfTypeAll();