mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Fixed compile errors. Still doesn't initialize correctly, nor saves connections
This commit is contained in:
parent
76e8b70316
commit
d52ecf1931
Binary file not shown.
Binary file not shown.
@ -19,18 +19,11 @@ public abstract class Node : ScriptableObject {
|
|||||||
public int InputCount { get { return inputs.Count; } }
|
public int InputCount { get { return inputs.Count; } }
|
||||||
public int OutputCount { get { return outputs.Count; } }
|
public int OutputCount { get { return outputs.Count; } }
|
||||||
|
|
||||||
protected Node() {
|
|
||||||
|
|
||||||
GetPorts(); //Cache the ports at creation time so we don't have to use reflection at runtime
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnEnable() {
|
protected void OnEnable() {
|
||||||
VerifyConnections();
|
|
||||||
GetPorts();
|
GetPorts();
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary> Checks all connections for invalid references, and removes them. </summary>
|
/// <summary> Checks all connections for invalid references, and removes them. </summary>
|
||||||
public void VerifyConnections() {
|
public void VerifyConnections() {
|
||||||
for (int i = 0; i < InputCount; i++) {
|
for (int i = 0; i < InputCount; i++) {
|
||||||
@ -119,6 +112,6 @@ public abstract class Node : ScriptableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void GetPorts() {
|
private void GetPorts() {
|
||||||
NodeDataCache.GetPorts(this, out inputs, out outputs);
|
NodeDataCache.GetPorts(this, ref inputs, ref outputs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,35 +6,43 @@ using System.Linq;
|
|||||||
|
|
||||||
/// <summary> Precaches reflection data in editor so we won't have to do it runtime </summary>
|
/// <summary> Precaches reflection data in editor so we won't have to do it runtime </summary>
|
||||||
public sealed class NodeDataCache : ScriptableObject {
|
public sealed class NodeDataCache : ScriptableObject {
|
||||||
public static NodeDataCache instance { get { return _instance; } }
|
public static NodeDataCache instance { get {
|
||||||
|
if (!_instance)
|
||||||
|
_instance = GetInstance();
|
||||||
|
return _instance;
|
||||||
|
} }
|
||||||
private static NodeDataCache _instance;
|
private static NodeDataCache _instance;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private PortDataCache portDataCache = new PortDataCache();
|
private PortDataCache portDataCache = new PortDataCache();
|
||||||
|
|
||||||
[RuntimeInitializeOnLoadMethod]
|
private static NodeDataCache GetInstance() {
|
||||||
private static void InitializeInstance() {
|
|
||||||
Debug.Log("INIT");
|
|
||||||
NodeDataCache[] ndc = Resources.FindObjectsOfTypeAll<NodeDataCache>();
|
NodeDataCache[] ndc = Resources.FindObjectsOfTypeAll<NodeDataCache>();
|
||||||
if (ndc == null || ndc.Length == 0) {
|
if (ndc == null || ndc.Length == 0) {
|
||||||
Debug.LogWarning("No NodeDataCache found. Creating.");
|
Debug.LogWarning("No NodeDataCache found. Creating.");
|
||||||
_instance = ScriptableObject.CreateInstance<NodeDataCache>();
|
NodeDataCache n = ScriptableObject.CreateInstance<NodeDataCache>();
|
||||||
_instance.BuildCache();
|
n.BuildCache();
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
else if (ndc.Length > 1) {
|
else if (ndc.Length > 1) {
|
||||||
Debug.LogWarning("Multiple NodeDataCaches found.");
|
Debug.LogWarning("Multiple NodeDataCaches found.");
|
||||||
}
|
}
|
||||||
_instance = ndc[0];
|
return ndc[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnEnable() {
|
||||||
|
_instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary> Return port data from cache </summary>
|
/// <summary> Return port data from cache </summary>
|
||||||
public static void GetPorts(Node node, out List<NodePort> inputs, out List<NodePort> outputs) {
|
public static void GetPorts(Node node, ref List<NodePort> inputs, ref List<NodePort> outputs) {
|
||||||
if (_instance == null) InitializeInstance();
|
//if (_instance == null) Resources.FindObjectsOfTypeAll<NodeDataCache>()[0];
|
||||||
|
|
||||||
System.Type nodeType = node.GetType();
|
System.Type nodeType = node.GetType();
|
||||||
inputs = new List<NodePort>();
|
inputs = new List<NodePort>();
|
||||||
outputs = new List<NodePort>();
|
outputs = new List<NodePort>();
|
||||||
if (!_instance.portDataCache.ContainsKey(nodeType)) return;
|
if (!instance.portDataCache.ContainsKey(nodeType)) return;
|
||||||
for (int i = 0; i < _instance.portDataCache[nodeType].Count; i++) {
|
for (int i = 0; i < _instance.portDataCache[nodeType].Count; i++) {
|
||||||
if (_instance.portDataCache[nodeType][i].direction == NodePort.IO.Input) inputs.Add(new NodePort(_instance.portDataCache[nodeType][i], node));
|
if (_instance.portDataCache[nodeType][i].direction == NodePort.IO.Input) inputs.Add(new NodePort(_instance.portDataCache[nodeType][i], node));
|
||||||
else outputs.Add(new NodePort(_instance.portDataCache[nodeType][i], node));
|
else outputs.Add(new NodePort(_instance.portDataCache[nodeType][i], node));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user