Beispiel #1
0
        public SerializationContainer Serialize(List <Node> nodes)
        {
            if (nodes == null)
            {
                return(null);
            }
            bool wasTriggering = TriggerEvents;

            TriggerEvents = false;

            SerializationContainer container = new SerializationContainer();

            for (var index = 0; index < nodes.Count; index++)
            {
                var node = nodes[index];
                container.Nodes.Add(node.ToSerializedNode());
                for (var i = 0; i < node.Sockets.Count; i++)
                {
                    var socket = node.Sockets[i];
                    if (socket.IsInput() && socket.IsConnected())
                    // serialize only input socket edges to avoid double edge serialization
                    {
                        InputSocket inputSocket = (InputSocket)socket;
                        container.Edges.Add(inputSocket.Edge.ToSerializedEgde());
                    }
                }
            }
            TriggerEvents = wasTriggering;
            return(container);
        }
Beispiel #2
0
        /// <summary>Unity serialization callback.</summary>
        public void OnBeforeSerialize()
        {
            if (_nodes.Count == 0)
            {
                return;                                // nothing to serialize
            }
            _serializedEdges.Clear();
            _serializedNodes.Clear();
            // serialize data
            SerializationContainer container = Serialize(_nodes);

            if (container != null)
            {
                _serializedEdges = container.Edges;
                _serializedNodes = container.Nodes;
            }
        }