From 3dae0910dc77fcbdade7bd321cbb05e2d1e6227c Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Fri, 13 Oct 2017 00:08:33 +0200 Subject: [PATCH] Serialization now works correctly. Removal of nodes still broken --- Example/ExampleNodeGraph.asset | 69 ---------------------- Example/ExampleNodeGraph.asset.meta | 9 --- Example/Nodes/Editor/DisplayValueEditor.cs | 1 - Scripts/Node.cs | 6 +- Scripts/NodeGraph.cs | 10 ++-- Scripts/NodePort.cs | 10 ++-- 6 files changed, 13 insertions(+), 92 deletions(-) delete mode 100644 Example/ExampleNodeGraph.asset delete mode 100644 Example/ExampleNodeGraph.asset.meta diff --git a/Example/ExampleNodeGraph.asset b/Example/ExampleNodeGraph.asset deleted file mode 100644 index f223852..0000000 --- a/Example/ExampleNodeGraph.asset +++ /dev/null @@ -1,69 +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: ExampleNodeGraph - m_EditorClassIdentifier: - nodes: - - {fileID: 114169009298143184} - - {fileID: 114520184832602068} ---- !u!114 &114169009298143184 -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: 130 - y: 6 - width: 200 - height: 200 - inputs: - - _fieldName: value - connections: - - node: {fileID: 114520184832602068} - fieldName: result - _direction: 0 - outputs: [] - value: 0 ---- !u!114 &114520184832602068 -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: 22e05e2a1f5ad7645850d52212143629, type: 3} - m_Name: Math - m_EditorClassIdentifier: - rect: - serializedVersion: 2 - x: -176 - y: 96 - width: 200 - height: 200 - inputs: [] - outputs: - - _fieldName: result - connections: - - node: {fileID: 114169009298143184} - fieldName: value - _direction: 1 - a: 0 - b: 0 - result: 0 - mathType: 0 diff --git a/Example/ExampleNodeGraph.asset.meta b/Example/ExampleNodeGraph.asset.meta deleted file mode 100644 index 51a01a0..0000000 --- a/Example/ExampleNodeGraph.asset.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 2c7ed5ea36166484a8bcecda71ad8cc8 -timeCreated: 1507760054 -licenseType: Free -NativeFormatImporter: - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Example/Nodes/Editor/DisplayValueEditor.cs b/Example/Nodes/Editor/DisplayValueEditor.cs index b0f4643..34276a8 100644 --- a/Example/Nodes/Editor/DisplayValueEditor.cs +++ b/Example/Nodes/Editor/DisplayValueEditor.cs @@ -20,7 +20,6 @@ public class DisplayValueEditor : NodeEditor { NodePort connection = port.GetConnection(i); if (connection == null) continue; - object obj = connection.GetValue(); if (obj == null) continue; diff --git a/Scripts/Node.cs b/Scripts/Node.cs index 7759d6e..60db807 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -41,21 +41,19 @@ public abstract class Node : ScriptableObject { else return GetInputByFieldName(fieldName); } - /// Returns output port which matches fieldName + /// Returns output port which matches fieldName. Returns null if none found. public NodePort GetOutputByFieldName(string fieldName) { for (int i = 0; i < OutputCount; i++) { if (outputs[i].fieldName == fieldName) return outputs[i]; } - Debug.LogWarning("No outputs with fieldName '" + fieldName+"'"); return null; } - /// Returns input port which matches fieldName + /// Returns input port which matches. Returns null if none found. public NodePort GetInputByFieldName(string fieldName) { for (int i = 0; i < InputCount; i++) { if (inputs[i].fieldName == fieldName) return inputs[i]; } - Debug.LogWarning("No inputs with fieldName '" + fieldName+"'"); return null; } diff --git a/Scripts/NodeGraph.cs b/Scripts/NodeGraph.cs index 7c00faf..4c1d798 100644 --- a/Scripts/NodeGraph.cs +++ b/Scripts/NodeGraph.cs @@ -49,17 +49,17 @@ public abstract class NodeGraph : ScriptableObject, ISerializationCallbackReceiv } public void OnAfterDeserialize() { - for (int i = 0; i < nodes.Count; i++) { + /*for (int i = 0; i < nodes.Count; i++) { nodes[i].graph = this; - } - VerifyConnections(); + }*/ + //VerifyConnections(); } - /// Checks all connections for invalid references, and removes them. + /*/// Checks all connections for invalid references, and removes them. public void VerifyConnections() { for (int i = 0; i < nodes.Count; i++) { nodes[i].VerifyConnections(); } - } + }*/ } diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs index ad51779..f36be55 100644 --- a/Scripts/NodePort.cs +++ b/Scripts/NodePort.cs @@ -18,10 +18,10 @@ public class NodePort { public bool IsInput { get { return direction == IO.Input; } } public bool IsOutput { get { return direction == IO.Output; } } - public Node node { get; private set; } public string fieldName { get { return _fieldName; } } + [SerializeField] public Node node; [SerializeField] private string _fieldName; [SerializeField] public Type type; [SerializeField] private List connections = new List(); @@ -57,7 +57,7 @@ public class NodePort { } } - public object GetValue() { + public object GetValue() { return node.GetValue(this); } @@ -77,7 +77,8 @@ public class NodePort { } public NodePort GetConnection(int i) { - return connections[i].Port; + NodePort port = connections[i].node.GetPortByFieldName(connections[i].fieldName); + return port; } public bool IsConnectedTo(NodePort port) { @@ -108,8 +109,8 @@ public class NodePort { [Serializable] public class PortConnection { - [SerializeField] public Node node; [SerializeField] public string fieldName; + [SerializeField] public Node node; public NodePort Port { get { return port != null ? port : port = GetPort(); } } [NonSerialized] private NodePort port; @@ -120,6 +121,7 @@ public class NodePort { } private NodePort GetPort() { + for (int i = 0; i < node.OutputCount; i++) { if (node.outputs[i].fieldName == fieldName) return node.outputs[i]; }