mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Serialization now works correctly. Removal of nodes still broken
This commit is contained in:
parent
8ce0d63903
commit
3dae0910dc
@ -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
|
||||
@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c7ed5ea36166484a8bcecda71ad8cc8
|
||||
timeCreated: 1507760054
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -41,21 +41,19 @@ public abstract class Node : ScriptableObject {
|
||||
else return GetInputByFieldName(fieldName);
|
||||
}
|
||||
|
||||
/// <summary> Returns output port which matches fieldName </summary>
|
||||
/// <summary> Returns output port which matches fieldName. Returns null if none found. </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary> Returns input port which matches fieldName </summary>
|
||||
/// <summary> Returns input port which matches. Returns null if none found. </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
/// <summary> Checks all connections for invalid references, and removes them. </summary>
|
||||
/*/// <summary> Checks all connections for invalid references, and removes them. </summary>
|
||||
public void VerifyConnections() {
|
||||
for (int i = 0; i < nodes.Count; i++) {
|
||||
nodes[i].VerifyConnections();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
@ -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<PortConnection> connections = new List<PortConnection>();
|
||||
@ -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];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user