mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-04 22:34:54 +08:00
Still haven't found a solution to initializing a static scriptableObject instance
This commit is contained in:
parent
d52ecf1931
commit
984364f08f
@ -11,10 +11,8 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: a6399826e2c44b447b32a3ed06646162, type: 3}
|
m_Script: {fileID: 11500000, guid: a6399826e2c44b447b32a3ed06646162, type: 3}
|
||||||
m_Name: ExampleNodeGraph
|
m_Name: ExampleNodeGraph
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
nodes:
|
nodes: []
|
||||||
- {fileID: 114778235353399140}
|
--- !u!114 &114063446055957998
|
||||||
- {fileID: 114295993062301438}
|
|
||||||
--- !u!114 &114295993062301438
|
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
m_PrefabParentObject: {fileID: 0}
|
m_PrefabParentObject: {fileID: 0}
|
||||||
@ -27,33 +25,13 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
rect:
|
rect:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
x: -330.1812
|
x: 0
|
||||||
y: -108.116974
|
y: 0
|
||||||
width: 200
|
width: 200
|
||||||
height: 200
|
height: 200
|
||||||
inputs: []
|
inputs: []
|
||||||
outputs: []
|
outputs: []
|
||||||
a: 2.01
|
a: 0
|
||||||
b: 0.01
|
b: 0
|
||||||
result: 0
|
result: 0
|
||||||
mathType: 0
|
mathType: 0
|
||||||
--- !u!114 &114778235353399140
|
|
||||||
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: 98f6f901f0da53142b79277ea3f42518, type: 3}
|
|
||||||
m_Name: DisplayValue
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
rect:
|
|
||||||
serializedVersion: 2
|
|
||||||
x: 100.23894
|
|
||||||
y: -132.62592
|
|
||||||
width: 200
|
|
||||||
height: 200
|
|
||||||
inputs: []
|
|
||||||
outputs: []
|
|
||||||
value: 0
|
|
||||||
|
|||||||
@ -3,38 +3,20 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
/// <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 {
|
public static NodeDataCache instance {
|
||||||
if (!_instance)
|
get {
|
||||||
_instance = GetInstance();
|
if (_instance == null) _instance = Resources.FindObjectsOfTypeAll<NodeDataCache>().FirstOrDefault();
|
||||||
return _instance;
|
return _instance;
|
||||||
} }
|
}
|
||||||
private static NodeDataCache _instance;
|
}
|
||||||
|
public static NodeDataCache _instance;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private PortDataCache portDataCache = new PortDataCache();
|
private PortDataCache portDataCache = new PortDataCache();
|
||||||
|
|
||||||
private static NodeDataCache GetInstance() {
|
|
||||||
NodeDataCache[] ndc = Resources.FindObjectsOfTypeAll<NodeDataCache>();
|
|
||||||
if (ndc == null || ndc.Length == 0) {
|
|
||||||
Debug.LogWarning("No NodeDataCache found. Creating.");
|
|
||||||
NodeDataCache n = ScriptableObject.CreateInstance<NodeDataCache>();
|
|
||||||
n.BuildCache();
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
else if (ndc.Length > 1) {
|
|
||||||
Debug.LogWarning("Multiple NodeDataCaches found.");
|
|
||||||
}
|
|
||||||
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, 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 (_instance == null) Resources.FindObjectsOfTypeAll<NodeDataCache>()[0];
|
||||||
@ -43,16 +25,17 @@ public sealed class NodeDataCache : ScriptableObject {
|
|||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
[UnityEditor.InitializeOnLoadMethod]
|
[UnityEditor.InitializeOnLoadMethod( )]
|
||||||
#endif
|
#endif
|
||||||
private static void Init() {
|
private static void Init() {
|
||||||
|
Debug.Log("Init");
|
||||||
instance.BuildCache();
|
instance.BuildCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user