diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs
index 7fdc49d..b9ea2a5 100644
--- a/Scripts/Editor/NodeEditorWindow.cs
+++ b/Scripts/Editor/NodeEditorWindow.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
@@ -10,7 +10,61 @@ namespace XNodeEditor {
/// Stores node positions for all nodePorts.
public Dictionary portConnectionPoints { get { return _portConnectionPoints; } }
+
private Dictionary _portConnectionPoints = new Dictionary();
+
+ [System.Serializable]
+ private class NodePortReference {
+ [SerializeField]
+ private XNode.Node _node;
+ [SerializeField]
+ private string _name;
+
+
+ public NodePortReference(XNode.NodePort nodePort) {
+ _node = nodePort.node;
+ _name = nodePort.fieldName;
+ }
+
+ public XNode.NodePort GetNodePort() {
+ if (_node == null) {
+ return null;
+ }
+
+ return _node.GetPort(_name);
+ }
+
+ }
+
+ [SerializeField]
+ private NodePortReference[] _references = new NodePortReference[0];
+ [SerializeField]
+ private Rect[] _rects = new Rect[0];
+
+ private void OnDisable() {
+ int count = portConnectionPoints.Count;
+ _references = new NodePortReference[count];
+ _rects = new Rect[count];
+ int index = 0;
+ foreach (var portConnectionPoint in portConnectionPoints) {
+ _references[index] = new NodePortReference(portConnectionPoint.Key);
+ _rects[index] = portConnectionPoint.Value;
+ index++;
+ }
+ }
+
+ private void OnEnable() {
+ int length = _references.Length;
+
+ if (length == _rects.Length) {
+ for (int i = 0; i < length; i++) {
+ XNode.NodePort nodePort = _references[i].GetNodePort();
+ if (nodePort != null)
+ _portConnectionPoints.Add(nodePort, _rects[i]);
+ }
+ }
+ }
+
public Dictionary nodeSizes { get { return _nodeSizes; } }
private Dictionary _nodeSizes = new Dictionary();
public XNode.NodeGraph graph;
@@ -25,7 +79,7 @@ namespace XNodeEditor {
if (graphEditor != null && NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
}
- partial void OnEnable();
+ //partial void OnEnable();
/// Create editor window
public static NodeEditorWindow Init() {
NodeEditorWindow w = CreateInstance();