public static string Serialize(Dictionary <int, Node> nodes) { HashSet <int> usedDefaults = GetUsedDefaults(nodes); StringBuilder sb = new StringBuilder(); bool first = true; foreach (var pair in nodes) { Node node = pair.Value; if (node is DefaultNode && !usedDefaults.Contains(node.NodeId)) { continue; } if (!first) { sb.Append('#'); } first = false; sb.Append(NodeCollector.ToID(node.GetType())); sb.Append('|'); sb.Append(node.NodeId); sb.Append('|'); ICustomSerialiser custom = node as ICustomSerialiser; if (custom != null) { sb.Append(custom.Serialize()); continue; } sb.Append(PositionToString(node.Position)); sb.Append('|'); for (int i = 0; i < node.Inputs.Length; i++) { if (i != 0) { sb.Append(' '); } sb.Append(node.Inputs[i].NodeId); } sb.Append('|'); FieldInfo[] fields = node.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance); for (int i = 0; i < fields.Length; i++) { if ((fields[i].Attributes & FieldAttributes.NotSerialized) != 0) { continue; } if (Exeptions.Contains(fields[i].Name)) { continue; } if (i != 0) { sb.Append('|'); } sb.Append(SerializeField(fields[i], node)); } } return(sb.ToString()); }
public Node CreateNode(Node node) { string typeID = NodeCollector.ToID(node.GetType()); return(CreateNode(typeID)); }