From ae9943fae1613561f2829db7c41911c305e9ad7e Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Wed, 27 Sep 2017 00:01:09 +0200 Subject: [PATCH] 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. --- Scripts/Node.cs | 9 --------- Scripts/NodeGraph.cs | 44 -------------------------------------------- 2 files changed, 53 deletions(-) diff --git a/Scripts/Node.cs b/Scripts/Node.cs index a9191b3..b5b27ee 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -10,8 +10,6 @@ public abstract class Node { /// Name of the node 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(); diff --git a/Scripts/NodeGraph.cs b/Scripts/NodeGraph.cs index 4ceb107..eefff63 100644 --- a/Scripts/NodeGraph.cs +++ b/Scripts/NodeGraph.cs @@ -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[] { "" }; - string json = JsonUtility.ToJson(this); - //json = json.Replace("\"\"", GetSerializedList(nodes)); - return json; - } - - private string GetSerializedList(List 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(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";