mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Possible solution found. NodeGraph now initializes NodeDataCache before creating any nodes.
This commit is contained in:
parent
984364f08f
commit
963eb84edb
BIN
Resources/New Node Data Cache.asset
Normal file
BIN
Resources/New Node Data Cache.asset
Normal file
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6799b9b87b05a14f9053390f4500d7b
|
||||
timeCreated: 1507567505
|
||||
licenseType: Free
|
||||
guid: a05ee176e92214f48a94c321dad1614d
|
||||
timeCreated: 1507703437
|
||||
licenseType: Pro
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
@ -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: []
|
||||
@ -14,30 +14,36 @@ public sealed class NodeDataCache : ScriptableObject {
|
||||
}
|
||||
}
|
||||
public static NodeDataCache _instance;
|
||||
public static bool Initialized { get { return _instance != null; } }
|
||||
|
||||
[SerializeField]
|
||||
private PortDataCache portDataCache = new PortDataCache();
|
||||
|
||||
/// <summary> Return port data from cache </summary>
|
||||
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();
|
||||
inputs = new List<NodePort>();
|
||||
outputs = new List<NodePort>();
|
||||
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 (!_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<NodeDataCache>("").FirstOrDefault();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.InitializeOnLoadMethod( )]
|
||||
#endif
|
||||
private static void Init() {
|
||||
Debug.Log("Init");
|
||||
[UnityEditor.Callbacks.DidReloadScripts]
|
||||
private static void Reload() {
|
||||
Initialize();
|
||||
instance.BuildCache();
|
||||
}
|
||||
#endif
|
||||
|
||||
private void BuildCache() {
|
||||
System.Type baseType = typeof(Node);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
@ -16,6 +15,7 @@ public abstract class NodeGraph : ScriptableObject, ISerializationCallbackReceiv
|
||||
}
|
||||
|
||||
public virtual Node AddNode(Type type) {
|
||||
if (!NodeDataCache.Initialized) NodeDataCache.Initialize();
|
||||
Node node = ScriptableObject.CreateInstance(type) as Node;
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user