Esempio n. 1
0
        public override void Update()
        {
            timer -= Time.deltaTime;
            if (timer < 0)
            {
                timer = checkEverySeconds;

                firstChild.Restart();
                firstChild.Beginn();
                bool useSecondChild = firstChild.IsFulfilled();

                if (!started)
                {
                    started = true;

                    SetExecutingNode(useSecondChild);
                }
                else if (wasOnSecondChild != useSecondChild)
                {
                    switch (onNodeChange)
                    {
                    case BNodeUtil.ReturnOperation.ReturnFailure:
                        CurrentStatus = Status.Failure;
                        return;

                    case BNodeUtil.ReturnOperation.ReturnSuccess:
                        CurrentStatus = Status.Success;
                        return;
                    }

                    SetExecutingNode(useSecondChild);
                }
            }

            switch (currentExecutingNode.CurrentStatus)
            {
            case Status.Running:
                currentExecutingNode.Update();
                break;

            case Status.Success:
                OnCheckReturnOperation(wasOnSecondChild ? onIfNodeSuccess : onElseNodeSuccess, currentExecutingNode);
                break;

            case Status.Failure:
                OnCheckReturnOperation(wasOnSecondChild ? onIfNodeFailure : onElseNodeFailure, currentExecutingNode);
                break;
            }
        }
Esempio n. 2
0
        public override void Update()
        {
            if (children.Length != 2)
            {
                Debug.LogWarning("Node " + name + " on " + tree.AttachedBrain.name + " has not 2 children. It will always return failure!");
                CurrentStatus = Status.Failure;
            }

            if (check == Check.EverySeconds || forceCheck == true)
            {
                timer -= Time.deltaTime;
                if (timer < 0 || forceCheck == true)
                {
                    // If the firstChild is a bool node
                    if (boolNode != null)
                    {
                        boolNode.Restart();
                        boolNode.Beginn(tree);

                        // if boolNode failed
                        if (boolNode.IsFulfilled() != true)
                        {
                            if (OnChild1Failure() == false)
                            {
                                return;
                            }
                        }

                        timer      = checkEverySeconds;
                        forceCheck = false;
                    }
                    else
                    {
                        // first child is an ordinary node
                        // first check if we already restarted
                        if (restartedFirstChild == false)
                        {
                            children[0].Restart();
                            children[0].Beginn(tree);
                            restartedFirstChild = true;
                        }

                        switch (children[0].CurrentStatus)
                        {
                        case Status.Running:
                            children[0].Update();
                            break;

                        case Status.Success:     // Restart the node
                            timer = checkEverySeconds;
                            restartedFirstChild = false;
                            forceCheck          = false;
                            break;

                        case Status.Failure:
                            if (OnChild1Failure() == true)
                            {
                                goto case Status.Success;
                            }
                            return;
                        }
                    }
                } // end if timer < 0
            }     // end if check is everyseconds

            switch (children[1].CurrentStatus)
            {
            case Status.Running:
                children[1].Update();
                break;

            case Status.Success:     // restart the node
                children[1].InnerRestart();
                children[1].Beginn(tree);
                forceCheck = true;
                break;

            case Status.Failure:
                switch (child2OnFailure)
                {
                case OnFailure.ReturnFailure:
                    CurrentStatus = Status.Failure;
                    return;

                case OnFailure.ReturnSuccess:
                    CurrentStatus = Status.Success;
                    return;
                }
                // case was restarting so jump to success case i.e. restart the node
                goto case Status.Success;
            }
        }
Esempio n. 3
0
        public override void Update()
        {
            if (children.Length != 2)
            {
                Debug.LogError("Children length of Guard node does not equal 2. This node will always return failure");
                CurrentStatus = Status.Failure;
                return;
            }

            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                if (convertedBoolNode != null)
                {
                    convertedBoolNode.Restart();
                    convertedBoolNode.Beginn();
                    if (convertedBoolNode.IsFulfilled() == false)
                    {
                        CurrentStatus = Status.Failure;
                        return;
                    }
                    timer = checkEverySeconds;
                }
                else // children[0] is not a boolNode
                {
                    switch (children[0].CurrentStatus)
                    {
                    case Status.Running:
                        children[0].Update();
                        break;

                    case Status.Success:
                        timer = checkEverySeconds;
                        children[0].Restart();
                        children[0].Beginn();
                        break;

                    case Status.Failure:
                        CurrentStatus = Status.Failure;
                        return;
                    }
                }
            }

            switch (children[1].CurrentStatus)
            {
            case Status.Waiting:
                children[1].Restart();
                children[1].Beginn();
                goto case Status.Running;

            case Status.Running:
                children[1].Update();
                break;

            case Status.Success:
                CurrentStatus = Status.Success;
                break;

            case Status.Failure:
                CurrentStatus = Status.Failure;
                break;
            }
        }