示例#1
0
    /// <summary>
    /// Select a child to run based on the policy.
    /// </summary>
    /// <param name="tank">Tank being controlled</param>
    /// <returns>Child to run, or null if no runnable children.</returns>
    private BehaviorTreeNode SelectChild(AIInput g)
    {
        switch (Policy)
        {
        case SelectionPolicy.Prioritized:

            for (int i = 0; i < Children.Count; i++)
            {
                BehaviorTreeNode child = Children[i];
                //Debug.Log(child +" - "+i);
                if (selected == child)
                {
                    return(child);
                }
                if (child.Decide(g))
                {
                    return(child);
                }
            }
            //Debug.Log("none");
            return(null);

        case SelectionPolicy.Sequential:

            for (int i = 0; i < Children.Count; i++)
            {
                int j = (i + sequentialChild) % Children.Count;
                BehaviorTreeNode child = Children[j];
                //Debug.Log(child +" - "+i);
                if (selected == child)
                {
                    return(child);
                }
                if (child.Decide(g))
                {
                    sequentialChild = j;
                    return(child);
                }
            }
            //Debug.Log("none");
            return(null);

        default:
            throw new NotImplementedException("Unimplemented policy: " + Policy);
        }
    }