Пример #1
0
    public IEnumerator Tick()
    {
        {
            int index = 0;
            while (treeNodes.Count > 0)
            {
                TreeNode node = treeNodes[index];
                while (true)
                {
                    BTEvaluationResult result = BTEvaluationResult.Default;
                    yield return(EnemyManager.instance.StartCoroutine(node.Test(delegate(BTEvaluationResult res)
                    {
                        result = res;
                    })));

                    while (result == BTEvaluationResult.Default)
                    {
                        yield return(null);
                    }
                    switch (result)
                    {
                    case BTEvaluationResult.Success:
                        yield return(EnemyManager.instance.StartCoroutine(node.success()));

                        break;

                    case BTEvaluationResult.Failure:
                        yield return(EnemyManager.instance.StartCoroutine(node.failure()));

                        break;

                    case BTEvaluationResult.Continue:
                        break;

                    default:
                        break;
                    }
                    if (result != BTEvaluationResult.Continue)
                    {
                        index++;
                        if (index >= treeNodes.Count)
                        {
                            index = 0;
                        }
                        break;
                    }
                    yield return(null);
                }
                yield return(null);
            }
        }
    }
Пример #2
0
    // runs each child node below it, running each of their tests and stopping if one of them returns sucess or failure
    // if niether, it moves on to the next child node
    public override IEnumerator Test(Action <BTEvaluationResult> callback)
    {
        {
            int index = 0;
            while (index < children.Length)
            {
                BTEvaluationResult result = BTEvaluationResult.Continue;
                yield return(EnemyManager.instance.StartCoroutine(children[index].Test(delegate(BTEvaluationResult res)
                {
                    result = res;
                })));

                switch (result)
                {
                case BTEvaluationResult.Success:
                    yield return(EnemyManager.instance.StartCoroutine(children[index].success()));

                    index = children.Length;
                    break;

                case BTEvaluationResult.Failure:
                    yield return(EnemyManager.instance.StartCoroutine(children[index].failure()));

                    index = children.Length;
                    break;

                case BTEvaluationResult.Continue:
                    index++;
                    break;

                default:
                    index = children.Length;
                    break;
                }
            }
        }
    }