1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Attempting to fix #81 in a cleaner way. Still not perfect

This commit is contained in:
Thor Brigsted 2018-12-11 01:21:19 +01:00
parent 6c1af6f4cd
commit e6f5ac2d47
2 changed files with 10 additions and 2 deletions

View File

@ -60,7 +60,12 @@ namespace XNode {
/// <summary> It is recommended not to modify these at hand. Instead, see <see cref="InputAttribute"/> and <see cref="OutputAttribute"/> </summary>
[SerializeField] private NodePortDictionary ports = new NodePortDictionary();
/// <summary> Used during node instantiation to fix null/misconfigured graph during OnEnable/Init. Set it before instantiating a node. Will automatically be unset during OnEnable </summary>
public static NodeGraph graphHotfix;
protected void OnEnable() {
graph = graphHotfix;
graphHotfix = null;
UpdateStaticPorts();
Init();
}

View File

@ -18,18 +18,20 @@ namespace XNode {
/// <summary> Add a node to the graph by type </summary>
public virtual Node AddNode(Type type) {
Node.graphHotfix = this;
Node node = ScriptableObject.CreateInstance(type) as Node;
nodes.Add(node);
node.graph = this;
nodes.Add(node);
return node;
}
/// <summary> Creates a copy of the original node in the graph </summary>
public virtual Node CopyNode(Node original) {
Node.graphHotfix = this;
Node node = ScriptableObject.Instantiate(original);
node.graph = this;
node.ClearConnections();
nodes.Add(node);
node.graph = this;
return node;
}
@ -58,6 +60,7 @@ namespace XNode {
// Instantiate all nodes inside the graph
for (int i = 0; i < nodes.Count; i++) {
if (nodes[i] == null) continue;
Node.graphHotfix = graph;
Node node = Instantiate(nodes[i]) as Node;
node.graph = graph;
graph.nodes[i] = node;