1
0
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:
Thor Brigsted 2017-09-27 00:01:09 +02:00
parent 0e6eb55143
commit ae9943fae1
2 changed files with 0 additions and 53 deletions

View File

@ -10,8 +10,6 @@ public abstract class Node {
/// <summary> Name of the node </summary>
public string name = "";
[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] private NodePort[] inputs = new NodePort[0];
@ -21,7 +19,6 @@ public abstract class Node {
public int OutputCount { get { return outputs.Length; } }
protected Node() {
nodeType = GetType().ToString();
CachePorts();
Init();
}
@ -60,12 +57,6 @@ public abstract class Node {
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() {
for (int i = 0; i < inputs.Length; i++) {
inputs[i].ClearConnections();

View File

@ -49,50 +49,6 @@ public class NodeGraph : ScriptableObject {
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 {
public string nodeType = "Node";