Пример #1
0
        internal override void OnPortDisconnect(ConnectionPort nodePort, ConnectionPort connectedPort)
        {
            // Enable all hidden connected nodes.
            if (nodePort != m_onEnterOutput && nodePort != m_onUpdateOutput && nodePort != m_onExitOutput)
            {
                return;
            }

            List <Node> nodes = new List <Node> ();

            NodeUtility.FindAllConnectedNodesOnPort(nodePort, nodes);

            for (int i = 0; i < nodes.Count; i++)
            {
                nodes[i].isHidden = false;
            }
        }
        /// <summary>
        /// Creates a deep copy of the given controller.
        /// </summary>
        /// <param name="originalController">The controller to copy.</param>
        /// <returns>Returns a deep copy of the given controller.</returns>
        public static AIController Copy(AIController originalController)
        {
            // Create a copy of the existing controller.
            AIControllerSerializer serializer = new AIControllerSerializer {
                m_originalController = originalController,
                m_copiedController   = Object.Instantiate(originalController)
            };

            // create a copy of all nodes and port references.
            foreach (Node originalNode in serializer.m_originalController.nodes)
            {
                Node copyNode = Object.Instantiate(originalNode);
                copyNode.name = originalNode.name;
                serializer.m_nodes.Add(originalNode, copyNode);

                foreach (ConnectionPort originalPort in originalNode.ports)
                {
                    ConnectionPort copyPort = Object.Instantiate(originalPort);
                    copyPort.name = originalPort.name;
                    serializer.m_ports.Add(originalPort, copyPort);
                }
            }

            // deep copy port references.
            foreach (ConnectionPort originalPort in serializer.m_ports.Keys)
            {
                ConnectionPort copyPort = serializer.m_ports[originalPort];
                copyPort.Copy(serializer, originalPort);
            }

            // deep copy node references.
            foreach (Node originalNode in serializer.m_nodes.Keys)
            {
                Node copyNode = serializer.m_nodes[originalNode];
                copyNode.Copy(serializer, originalNode);
            }

            // deep copy controller references.
            serializer.m_copiedController.Copy(serializer, serializer.m_originalController);

            return(serializer.m_copiedController);
        }
        /// <summary>
        /// Find all connected Nodes on the given port.
        /// </summary>
        public static void FindAllConnectedNodesOnPort(ConnectionPort port, List <Node> connectedNodes)
        {
            if (port == null)
            {
                Debug.LogError("the given port is null");
                return;
            }

            Node baseNode = port.node;

            ConnectionPort[] connectedPorts = port.connectedPorts;

            for (int i = 0; i < connectedPorts.Length; i++)
            {
                ConnectionPort connectedPort = connectedPorts[i];
                Node           connectedNode = connectedPort.node;

                FindAllConnectedNodesOnPort(baseNode, baseNode, connectedNode, connectedNodes);
            }
        }
        /// <summary>
        /// Find the first node of type T that is connected with the given node.
        /// Otherwise it will return null.
        /// </summary>
        public static T FindConnectedNodeOfType <T> (Node startNode) where T : Node
        {
            T foundNode = null;

            ConnectionPort[] nodePorts = startNode.ports;
            for (int nodePortIndex = 0; nodePortIndex < nodePorts.Length; nodePortIndex++)
            {
                ConnectionPort nodePort = nodePorts[nodePortIndex];

                ConnectionPort[] connectedPorts = nodePort.connectedPorts;
                for (int connectedPortIndex = 0; connectedPortIndex < connectedPorts.Length; connectedPortIndex++)
                {
                    ConnectionPort connectedPort = connectedPorts[connectedPortIndex];

                    Node connectedNode = connectedPort.node;

                    FindConnectedNodeOfType <T> (startNode, connectedNode, ref foundNode);
                }
            }

            return(foundNode);
        }
Пример #5
0
 /// <summary>
 /// Can the nodePort connect to the given otherPort.
 /// </summary>
 /// <param name="nodePort">The port that is part of this node.</param>
 /// <param name="otherPort">The port that should connect to the nodePort.</param>
 /// <param name="error">Error if it's not a valid connection.</param>
 /// <returns>Returns true if is is a valid connection.</returns>
 internal virtual bool IsValidConnection(ConnectionPort nodePort, ConnectionPort otherPort, out string error)
 {
     error = "";
     return(true);
 }
Пример #6
0
 /// <summary>
 /// Is called if the nodePort disconnect to the connected port.
 /// </summary>
 /// <param name="nodePort">The port of this node.</param>
 /// <param name="connectedPort">The connected port.</param>
 internal virtual void OnPortDisconnect(ConnectionPort nodePort, ConnectionPort connectedPort)
 {
 }