diff --git a/Example/ExampleNodeGraph.asset b/Example/ExampleNodeGraph.asset
index c624f53..2871ba7 100644
Binary files a/Example/ExampleNodeGraph.asset and b/Example/ExampleNodeGraph.asset differ
diff --git a/Example/ExampleNodeGraph.asset.meta b/Example/ExampleNodeGraph.asset.meta
index 723ec56..04eb901 100644
--- a/Example/ExampleNodeGraph.asset.meta
+++ b/Example/ExampleNodeGraph.asset.meta
@@ -1,7 +1,7 @@
fileFormatVersion: 2
-guid: 5398d565241ec2d489f41c368ca6cf24
-timeCreated: 1507498811
-licenseType: Free
+guid: b21c76861277d8445a55b4691205fd00
+timeCreated: 1507704049
+licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
diff --git a/Scripts/NodeDataCache.cs b/Scripts/NodeDataCache.cs
index aa02cd1..681eaa2 100644
--- a/Scripts/NodeDataCache.cs
+++ b/Scripts/NodeDataCache.cs
@@ -7,52 +7,46 @@ using UnityEditor;
/// Precaches reflection data in editor so we won't have to do it runtime
public sealed class NodeDataCache : ScriptableObject {
- public static NodeDataCache instance {
- get {
- if (_instance == null) _instance = Resources.FindObjectsOfTypeAll().FirstOrDefault();
- return _instance;
+ public static NodeDataCache instance { get; private set;}
+ public static bool Initialized { get { return instance != null; } }
+
+ [SerializeField] private PortDataCache portDataCache;
+
+#if UNITY_EDITOR
+ [UnityEditor.Callbacks.DidReloadScripts]
+#endif
+ public static void Initialize() {
+ if (!Initialized) {
+ instance = Resources.LoadAll("").FirstOrDefault();
+#if UNITY_EDITOR
+ instance.BuildCache();
+#endif
}
}
- public static NodeDataCache _instance;
- public static bool Initialized { get { return _instance != null; } }
-
- [SerializeField]
- private PortDataCache portDataCache = new PortDataCache();
/// Return port data from cache
public static void GetPorts(Node node, ref List inputs, ref List outputs) {
- if (!Initialized) Initialize();
+ Initialize();
System.Type nodeType = node.GetType();
inputs = new List();
outputs = new List();
- if (!_instance.portDataCache.ContainsKey(nodeType)) return;
- 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));
- else outputs.Add(new NodePort(_instance.portDataCache[nodeType][i], node));
- }
- }
-
- public static void Initialize() {
- _instance = Resources.LoadAll("").FirstOrDefault();
+ if (!instance.portDataCache.ContainsKey(nodeType)) return;
+ 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));
+ else outputs.Add(new NodePort(instance.portDataCache[nodeType][i], node));
+ }
}
#if UNITY_EDITOR
- [UnityEditor.Callbacks.DidReloadScripts]
- private static void Reload() {
- Initialize();
- instance.BuildCache();
- }
-#endif
-
private void BuildCache() {
+ portDataCache = new PortDataCache();
System.Type baseType = typeof(Node);
Assembly assembly = Assembly.GetAssembly(baseType);
System.Type[] nodeTypes = assembly.GetTypes().Where(t =>
!t.IsAbstract &&
baseType.IsAssignableFrom(t)
).ToArray();
- portDataCache.Clear();
for (int i = 0; i < nodeTypes.Length; i++) {
CachePorts(nodeTypes[i]);
@@ -60,9 +54,6 @@ public sealed class NodeDataCache : ScriptableObject {
}
private void CachePorts(System.Type nodeType) {
- List inputPorts = new List();
- List outputPorts = new List();
-
System.Reflection.FieldInfo[] fieldInfo = nodeType.GetFields();
for (int i = 0; i < fieldInfo.Length; i++) {
@@ -80,6 +71,7 @@ public sealed class NodeDataCache : ScriptableObject {
}
}
}
+#endif
[System.Serializable]
private class PortDataCache : Dictionary>, ISerializationCallbackReceiver {