mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-04 22:34:54 +08:00
Removed JSON serialization.
Might re-add later. Removed because current implementation is hacky and i don't believe it is very future proof. For now, you can create and save ScriptableObjects in the editor, and use them at runtime.
This commit is contained in:
parent
0e6eb55143
commit
ae9943fae1
@ -10,8 +10,6 @@ public abstract class Node {
|
|||||||
/// <summary> Name of the node </summary>
|
/// <summary> Name of the node </summary>
|
||||||
public string name = "";
|
public string name = "";
|
||||||
[NonSerialized] public NodeGraph graph;
|
[NonSerialized] public NodeGraph graph;
|
||||||
public string NodeType { get { return nodeType; } }
|
|
||||||
[SerializeField] private string nodeType;
|
|
||||||
|
|
||||||
[SerializeField] public Rect position = new Rect(0,0,200,200);
|
[SerializeField] public Rect position = new Rect(0,0,200,200);
|
||||||
[SerializeField] private NodePort[] inputs = new NodePort[0];
|
[SerializeField] private NodePort[] inputs = new NodePort[0];
|
||||||
@ -21,7 +19,6 @@ public abstract class Node {
|
|||||||
public int OutputCount { get { return outputs.Length; } }
|
public int OutputCount { get { return outputs.Length; } }
|
||||||
|
|
||||||
protected Node() {
|
protected Node() {
|
||||||
nodeType = GetType().ToString();
|
|
||||||
CachePorts();
|
CachePorts();
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
@ -60,12 +57,6 @@ public abstract class Node {
|
|||||||
return new NodePort(name, type, this, NodePort.IO.Output);
|
return new NodePort(name, type, this, NodePort.IO.Output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FinalizeDeserialization() {
|
|
||||||
for (int i = 0; i < outputs.Length; i++) {
|
|
||||||
outputs[i].FinalizeDeserialization();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ClearConnections() {
|
public void ClearConnections() {
|
||||||
for (int i = 0; i < inputs.Length; i++) {
|
for (int i = 0; i < inputs.Length; i++) {
|
||||||
inputs[i].ClearConnections();
|
inputs[i].ClearConnections();
|
||||||
|
|||||||
@ -49,50 +49,6 @@ public class NodeGraph : ScriptableObject {
|
|||||||
nodes.Clear();
|
nodes.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Serialize() {
|
|
||||||
//Unity serializer doesn't support polymorphism, so we'll have to use a hack
|
|
||||||
s_nodes = new string[nodes.Count];
|
|
||||||
for (int i = 0; i < nodes.Count; i++) {
|
|
||||||
s_nodes[i] = JsonUtility.ToJson(nodes[i]);
|
|
||||||
}
|
|
||||||
//s_nodes = new string[] { "<SERIALIZED_NODES>" };
|
|
||||||
string json = JsonUtility.ToJson(this);
|
|
||||||
//json = json.Replace("\"<SERIALIZED_NODES>\"", GetSerializedList(nodes));
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetSerializedList<T>(List<T> list) {
|
|
||||||
string[] s_list = new string[list.Count];
|
|
||||||
for (int i = 0; i < list.Count; i++) {
|
|
||||||
s_list[i] = JsonUtility.ToJson(list[i]);
|
|
||||||
}
|
|
||||||
return string.Join(",", s_list);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static NodeGraph Deserialize(string json) {
|
|
||||||
NodeGraph nodeGraph = JsonUtility.FromJson<NodeGraph>(json);
|
|
||||||
|
|
||||||
//If we are trying to open a newly created nodegraph, it will be empty
|
|
||||||
if (nodeGraph == null) nodeGraph = new NodeGraph();
|
|
||||||
if (nodeGraph.s_nodes != null) {
|
|
||||||
|
|
||||||
for (int i = 0; i < nodeGraph.s_nodes.Length; i++) {
|
|
||||||
NodeTyper tempNode = new NodeTyper();
|
|
||||||
JsonUtility.FromJsonOverwrite(nodeGraph.s_nodes[i], tempNode);
|
|
||||||
//Node node = nodeGraph.AddNode(tempNode.nodeType);
|
|
||||||
Type type = Type.GetType(tempNode.nodeType);
|
|
||||||
Node node = JsonUtility.FromJson(nodeGraph.s_nodes[i], type) as Node;
|
|
||||||
nodeGraph.AddNode(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nodeGraph.nodes != null){
|
|
||||||
for (int i = 0; i < nodeGraph.nodes.Count; i++) {
|
|
||||||
nodeGraph.nodes[i].FinalizeDeserialization();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodeGraph;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class NodeTyper {
|
private class NodeTyper {
|
||||||
public string nodeType = "Node";
|
public string nodeType = "Node";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user