1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-21 01:36:03 +08:00

Possible solution found. NodeGraph now initializes NodeDataCache before creating any nodes.

This commit is contained in:
Thor 2017-10-11 08:36:36 +02:00
parent 984364f08f
commit 963eb84edb
5 changed files with 21 additions and 29 deletions

Binary file not shown.

View File

@ -1,7 +1,7 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: a6799b9b87b05a14f9053390f4500d7b guid: a05ee176e92214f48a94c321dad1614d
timeCreated: 1507567505 timeCreated: 1507703437
licenseType: Free licenseType: Pro
NativeFormatImporter: NativeFormatImporter:
mainObjectFileID: 11400000 mainObjectFileID: 11400000
userData: userData:

View File

@ -1,14 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a6399826e2c44b447b32a3ed06646162, type: 3}
m_Name: NodeDataCache
m_EditorClassIdentifier:
nodes: []

View File

@ -14,30 +14,36 @@ public sealed class NodeDataCache : ScriptableObject {
} }
} }
public static NodeDataCache _instance; public static NodeDataCache _instance;
public static bool Initialized { get { return _instance != null; } }
[SerializeField] [SerializeField]
private PortDataCache portDataCache = new PortDataCache(); private PortDataCache portDataCache = new PortDataCache();
/// <summary> Return port data from cache </summary> /// <summary> Return port data from cache </summary>
public static void GetPorts(Node node, ref List<NodePort> inputs, ref List<NodePort> outputs) { public static void GetPorts(Node node, ref List<NodePort> inputs, ref List<NodePort> outputs) {
//if (_instance == null) Resources.FindObjectsOfTypeAll<NodeDataCache>()[0]; if (!Initialized) Initialize();
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));
} }
} }
public static void Initialize() {
_instance = Resources.LoadAll<NodeDataCache>("").FirstOrDefault();
}
#if UNITY_EDITOR #if UNITY_EDITOR
[UnityEditor.InitializeOnLoadMethod( )] [UnityEditor.Callbacks.DidReloadScripts]
#endif private static void Reload() {
private static void Init() { Initialize();
Debug.Log("Init");
instance.BuildCache(); instance.BuildCache();
} }
#endif
private void BuildCache() { private void BuildCache() {
System.Type baseType = typeof(Node); System.Type baseType = typeof(Node);

View File

@ -1,5 +1,4 @@
using System.Collections; using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using System; using System;
@ -16,6 +15,7 @@ public abstract class NodeGraph : ScriptableObject, ISerializationCallbackReceiv
} }
public virtual Node AddNode(Type type) { public virtual Node AddNode(Type type) {
if (!NodeDataCache.Initialized) NodeDataCache.Initialize();
Node node = ScriptableObject.CreateInstance(type) as Node; Node node = ScriptableObject.CreateInstance(type) as Node;
#if UNITY_EDITOR #if UNITY_EDITOR
if (!Application.isPlaying) { if (!Application.isPlaying) {