Exemplo n.º 1
0
        /// <summary>
        /// Recursively checks whether this node is a child of the other node
        /// </summary>
        public bool isChildOf(Node otherNode)
        {
            if (otherNode == null || otherNode == this)
            {
                return(false);
            }
            if (BeginRecursiveSearchLoop())
            {
                return(false);
            }
            for (int i = 0; i < inputPorts.Count; i++)
            {
                ConnectionPort port = inputPorts[i];
                for (int t = 0; t < port.connections.Count; t++)
                {
                    Node conBody = port.connections[t].body;
                    if (conBody == otherNode || conBody.isChildOf(otherNode))
                    {
                        StopRecursiveSearchLoop();
                        return(true);
                    }
                }
            }

            EndRecursiveSearchLoop();
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether a connection can be applied between this port and the specified port
        /// </summary>
        public virtual bool CanApplyConnection(ConnectionPort port)
        {
            if (port == null || body == port.body || connections.Contains(port))
            {
                return(false);
            }

            if (direction == Direction.None && port.direction == Direction.None)
            {
                return(true); // None-Directive connections can always connect
            }
            if (direction == Direction.In && port.direction != Direction.Out)
            {
                return(false); // Cannot connect inputs with anything other than outputs
            }
            if (direction == Direction.Out && port.direction != Direction.In)
            {
                return(false); // Cannot connect outputs with anything other than inputs
            }
            if (!body.canvas.allowRecursion)
            {
                // Assure no loop would be created
                bool loop;
                if (direction == Direction.Out)
                {
                    loop = body.isChildOf(port.body);
                }
                else
                {
                    loop = port.body.isChildOf(body);
                }
                if (loop)
                {
                    // Loop would be created, not allowed
                    Debug.LogWarning("Cannot apply connection: Recursion detected!");
                    return(false);
                }
            }

            return(true);
        }