/// <summary>Unity serialization callback.</summary> public void OnAfterDeserialize() { if (serializedNodes.Count == 0) { return; // Nothing to deserialize. } bool wasTriggering = TriggerEvents; TriggerEvents = false; nodes.Clear(); // clear original data. // deserialize nodes foreach (var sNode in serializedNodes) { Node n = CreateNode(Type.GetType(sNode.type), sNode.id); if (n != null) { JsonUtility.FromJsonOverwrite(sNode.data, n); n.OnDeserialization(sNode); n.X = sNode.X; n.Y = sNode.Y; AddNode(n); } } // deserialize edges foreach (var sEdge in serializedEdges) { Node inputNode = GetNode(sEdge.InputNodeId); Node outputNode = GetNode(sEdge.OutputNodeId); if (inputNode == null || outputNode == null) { Debug.LogWarning("Try to create an edge but can not find at least on of the nodes."); continue; } if (sEdge.OutputSocketIndex > outputNode.Sockets.Count || sEdge.InputSocketIndex > inputNode.Sockets.Count) { Debug.LogWarning("Try to create an edge but can not find at least on of the sockets."); continue; } Edge edge = new Edge(inputNode.Sockets[sEdge.InputSocketIndex], outputNode.Sockets[sEdge.OutputSocketIndex]); inputNode.Sockets[sEdge.InputSocketIndex].Edge = edge; outputNode.Sockets[sEdge.OutputSocketIndex].Edge = edge; } TriggerEvents = wasTriggering; }
/// <summary>Unity serialization callback.</summary> public void OnAfterDeserialize() { if (_serializedNodes.Count == 0) { return; // Nothing to deserialize. } bool wasTriggering = TriggerEvents; TriggerEvents = false; _nodes.Clear(); // clear original data. // deserialize nodes foreach (var sNode in _serializedNodes) { Type nodeType = Type.GetType(sNode.type); if (nodeType == null) { Debug.LogWarning("Unknown node type: " + sNode.type); continue; } Node n = CreateNode(nodeType, sNode.id); if (n != null) { JsonUtility.FromJsonOverwrite(sNode.data, n); n.OnDeserialization(sNode); n.X = sNode.X; n.Y = sNode.Y; for (var i = 0; i < sNode.directInputValues.Length; i++) { if (n.Sockets[i].IsInput()) { InputSocket inputSocket = (InputSocket)n.Sockets[i]; inputSocket.SetDirectInputNumber(sNode.directInputValues[i], false); } } if (sNode.Collapsed) { n.Collapse(); } AddNode(n); } } // deserialize edges foreach (var sEdge in _serializedEdges) { Node inputNode = GetNode(sEdge.InputNodeId); Node outputNode = GetNode(sEdge.OutputNodeId); if (inputNode == null || outputNode == null) { Debug.LogWarning("Try to create an edge but can not find at least on of the nodes."); continue; } if (sEdge.OutputSocketIndex > outputNode.Sockets.Count || sEdge.InputSocketIndex > inputNode.Sockets.Count) { Debug.LogWarning("Try to create an edge but can not find at least on of the sockets."); continue; } InputSocket inputSocket = (InputSocket)inputNode.Sockets[sEdge.InputSocketIndex]; OutputSocket outputSocket = (OutputSocket)outputNode.Sockets[sEdge.OutputSocketIndex]; Edge edge = new Edge(outputSocket, inputSocket); inputSocket.Edge = edge; outputSocket.Edges.Add(edge); } TriggerEvents = wasTriggering; }