コード例 #1
0
    private void Awake()
    {
        base.Awake();
        PathWalker = gameObject.GetComponent <PathWalker>();

        var _builder = new BehaviourTreeBuilder();

        _builder = _builder.Selector(); // MainNode

        _builder = _builder.StateFulSequence("Patrol")
                   .Inverter("!").Condition("HayEnemigo", () => enemyTransform != null).End()
                   .Condition("EndPath", () => PathWalker.Ended)
                   .Do("FindPath", () => { _ = PathWalker.WalkTo(PathFinderManager.Instance.RandomWalkablePosition); PathWalker.WALK_SPEED = 5; return(BehaviorReturnCode.Success); })
                   .End();

        _builder = _builder.StateFulSequence("FindEnemy")
                   .Inverter("!").Condition("HayEnemigo", () => enemyTransform != null).End()
                   .Inverter("!").Do("BuscarEnemigo", FindEnemy).End()
                   .End();

        _builder = _builder.StateFulSequence("Follow")
                   .Condition("HayEnemigo", () => enemyTransform != null)
                   .Inverter("!").Condition("EstaCerca", () => (enemyTransform.position - transform.position).magnitude < attack_range).End()
                   .Condition("EndPath", () => PathWalker.Ended)
                   .Do("FindPath", () => { _ = PathWalker.WalkTo(enemyTransform.position + ((transform.position - enemyTransform.position).normalized * 1.5f)); return(BehaviorReturnCode.Success); })
                   .End();

        _builder = _builder.StateFulSequence("Attack")
                   .Condition("HayEnemigo", () => enemyTransform != null)
                   .Condition("EstaCerca", () => (enemyTransform.position - transform.position).magnitude < attack_range)
                   .Do("AttackEnemy", AttackEnemy)
                   .End();

        _builder = _builder.End(); // End MainNode

        _root = _builder.Build();
    }