Exemplo n.º 1
0
        private void SwitchNode(Node toNode)
        {
            if (toNode == null)
            {
                return;
            }

            if (ActiveNode != null)
            {
                ActiveNode.OnExit();
                if (ActiveNode.Parent != null && ActiveNode.Parent != toNode.Parent)
                {
                    ActiveNode.Parent.OnExit();
                }
            }
            ActiveNode = toNode;
            if (this.ActiveNode != null && this.ActiveNode.Parent != this.AnyState.Parent)
            {
                this.AnyState.OnExit();
                this.AnyState = this.ActiveNode.Parent.GetAnyState();
                this.AnyState.OnEnter();
            }
            switchToNode = null;

            ActiveNode.OnEnter();
            //Debug.Log (ActiveNode.Name);
        }
Exemplo n.º 2
0
        /// <summary> Activate a Node </summary>
        /// <param name="nextActiveNode"> Target Node </param>
        /// <param name="connection"> Connection to ping (used as a visual cue in the editor) </param>
        public void SetActiveNode(Node nextActiveNode, Connection connection = null)
        {
            if (ActiveNode != null)
            {
                ActiveNode.OnExit(nextActiveNode, connection);
                ActiveNode.SetActiveGraph(null);
            }

            PreviousActiveNode = ActiveNode;

            if (InfiniteLoopDetected(nextActiveNode))
            {
                throw new OverflowException("Nody detected an Infinite Loop." +
                                            "\n" +
                                            "This loop was detected in the '" + name + "' " + (m_isSubGraph ? "SubGraph" : "Graph") + ", at the '" + nextActiveNode.Name + "' Node. " +
                                            (PreviousActiveNode == null ? "" : "The connection that triggered this exception was between '" + PreviousActiveNode.Name + "' --and--> '" + nextActiveNode.Name + "' Nodes. ") +
                                            "This issue happened because the sockets are connected in such a manner that a closed infinite loop was created. " +
                                            "Please redesign the current UI flow to and from the '" + nextActiveNode.Name + "' Node, because Nody cannot automatically do that for you. " +
                                            "Look at how the '" + nextActiveNode.Name + "' Node is connected to other nodes and try to follow the UI flow in order to understand where the infinite loop happens. " +
                                            "If this exception were not in place, the Unity Editor would freeze, then you would have had to close it by force and lose any unsaved changes in the process." +
                                            "\n");
            }

            ActiveNode = nextActiveNode;
            if (ActiveNode == null)
            {
                return;
            }

            if (ActiveNode.NodeType == NodeType.Exit)
            {
                DeactivateGlobalNodes();                                       //if the ActiveNode is an Exit Node -> then this means that this is a SubGraph that just finished it's cycle -> stop all of its GlobalNodes
            }
            ActiveNode.SetActiveGraph(this);
            ActiveNode.OnEnter(PreviousActiveNode, connection);
        }