mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Fix misconfigured node.graph reference during node instantiation and graph cloning (#85)
* Attempting to fix #81 in a cleaner way. Still not perfect * Fixed setting to null during OnEnable * Fixed spelling
This commit is contained in:
parent
6c1af6f4cd
commit
a0eee5b9ca
@ -60,7 +60,13 @@ namespace XNode {
|
|||||||
/// <summary> It is recommended not to modify these at hand. Instead, see <see cref="InputAttribute"/> and <see cref="OutputAttribute"/> </summary>
|
/// <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();
|
[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() {
|
protected void OnEnable() {
|
||||||
|
if (graphHotfix != null) graph = graphHotfix;
|
||||||
|
graphHotfix = null;
|
||||||
UpdateStaticPorts();
|
UpdateStaticPorts();
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,18 +18,20 @@ namespace XNode {
|
|||||||
|
|
||||||
/// <summary> Add a node to the graph by type </summary>
|
/// <summary> Add a node to the graph by type </summary>
|
||||||
public virtual Node AddNode(Type type) {
|
public virtual Node AddNode(Type type) {
|
||||||
|
Node.graphHotfix = this;
|
||||||
Node node = ScriptableObject.CreateInstance(type) as Node;
|
Node node = ScriptableObject.CreateInstance(type) as Node;
|
||||||
nodes.Add(node);
|
|
||||||
node.graph = this;
|
node.graph = this;
|
||||||
|
nodes.Add(node);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Creates a copy of the original node in the graph </summary>
|
/// <summary> Creates a copy of the original node in the graph </summary>
|
||||||
public virtual Node CopyNode(Node original) {
|
public virtual Node CopyNode(Node original) {
|
||||||
|
Node.graphHotfix = this;
|
||||||
Node node = ScriptableObject.Instantiate(original);
|
Node node = ScriptableObject.Instantiate(original);
|
||||||
|
node.graph = this;
|
||||||
node.ClearConnections();
|
node.ClearConnections();
|
||||||
nodes.Add(node);
|
nodes.Add(node);
|
||||||
node.graph = this;
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +60,7 @@ namespace XNode {
|
|||||||
// Instantiate all nodes inside the graph
|
// Instantiate all nodes inside the graph
|
||||||
for (int i = 0; i < nodes.Count; i++) {
|
for (int i = 0; i < nodes.Count; i++) {
|
||||||
if (nodes[i] == null) continue;
|
if (nodes[i] == null) continue;
|
||||||
|
Node.graphHotfix = graph;
|
||||||
Node node = Instantiate(nodes[i]) as Node;
|
Node node = Instantiate(nodes[i]) as Node;
|
||||||
node.graph = graph;
|
node.graph = graph;
|
||||||
graph.nodes[i] = node;
|
graph.nodes[i] = node;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user