Example #1
0
    //just excute current node one time and return
    private IEnumerator ActionNode(AINode <bool> aiNode)
    {
        aiNode.lastNode = lastNodeTmp;

        bool isEnter = aiNode.Enter(this); //if false, AITree will ignore current aiNode and execute to its right child

        if (isEnter)
        {
            yield return(StartCoroutine(aiNode.Execute()));

            lastNodeTmp = aiNode;
        }

        // decide how to do the next step
        // if the node places in the last level(it dosen't have any child node)
        // just excute its behaviour and stop
        if (aiNode.Data)
        {
            if (aiNode.RChild != null)
            {
                yield return(StartCoroutine(ActionNode(aiNode.RChild as AINode <bool>)));
            }
        }
        else
        {
            if (aiNode.LChild != null)
            {
                yield return(StartCoroutine(ActionNode(aiNode.LChild as AINode <bool>)));
            }
        }

        yield return(0);
    }
Example #2
0
    //just excute current node one time and return
    private IEnumerator ActionNode(AINode <bool> aiNode)
    {
        aiNode.lastNode = lastNodeTmp;

        bool isEnter = aiNode.Enter(this); //if false, AITree will ignore current aiNode and execute to its right child

        //Debug.Log(aiNode.GetType() + " By " + UnitManager.GetInstance().units.IndexOf(aiUnit));
        if (isEnter)
        {
            yield return(StartCoroutine(aiNode.Execute()));

            lastNodeTmp = aiNode;
        }
        //Debug.Log(aiNode.GetType() + " By " + UnitManager.GetInstance().units.IndexOf(aiUnit) + " Complete. aiNode.Data:" + aiNode.Data.ToString());
        // decide how to do the next step
        // if the node places in the last level(it dosen't have any child node)
        // just excute its behaviour and stop
        if (aiNode.Data)
        {
            if (aiNode.RChild != null)
            {
                yield return(StartCoroutine(ActionNode(aiNode.RChild as AINode <bool>)));
            }
        }
        else
        {
            if (aiNode.LChild != null)
            {
                yield return(StartCoroutine(ActionNode(aiNode.LChild as AINode <bool>)));
            }
        }

        yield return(0);
    }