1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-02-04 14:24:54 +08:00

Fixed missing connections after serialization/deserialization

This commit is contained in:
Paul 2018-07-27 14:07:13 +03:00
parent ad5a8dfc25
commit ea14f27a23

View File

@ -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 {
/// <summary> Stores node positions for all nodePorts. </summary>
public Dictionary<XNode.NodePort, Rect> portConnectionPoints { get { return _portConnectionPoints; } }
private Dictionary<XNode.NodePort, Rect> _portConnectionPoints = new Dictionary<XNode.NodePort, Rect>();
[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<XNode.Node, Vector2> nodeSizes { get { return _nodeSizes; } }
private Dictionary<XNode.Node, Vector2> _nodeSizes = new Dictionary<XNode.Node, Vector2>();
public XNode.NodeGraph graph;
@ -25,7 +79,7 @@ namespace XNodeEditor {
if (graphEditor != null && NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
}
partial void OnEnable();
//partial void OnEnable();
/// <summary> Create editor window </summary>
public static NodeEditorWindow Init() {
NodeEditorWindow w = CreateInstance<NodeEditorWindow>();