コード例 #1
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public async void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        try
        {
            if (pathWalker == null)
            {
                pathWalker = animator.gameObject.GetComponent <PathWalker>();
            }
            if (creature == null)
            {
                creature = animator.gameObject.GetComponent <Creature>();
            }

            var go = GameManager.Instance.Creatures.Where(x => x.name.Contains("Enemy")).FirstOrDefault(x => (x.gameObject.transform.position - animator.gameObject.transform.position).magnitude < creature.view_range);

            if (go == null)
            {
                animator.SetBool("EnemyInRange", false);
                return;
            }

            SoundManager.Instance.PlaySound(Sound.Footman_Aggro);
            enemy = go.GetComponent <Creature>();
            await pathWalker.WalkTo(enemy.gameObject.transform.position + ((animator.transform.position - enemy.gameObject.transform.position).normalized * 1.5f));
        }
        catch (System.Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
コード例 #2
0
    override public async void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        try
        {
            if (pathWalker == null)
            {
                pathWalker = animator.gameObject.GetComponent <PathWalker>();
            }
            if (behaviourDisplay == null)
            {
                behaviourDisplay = animator.gameObject.GetComponentInChildren <TextMesh>();
            }
            if (mineDetector == null)
            {
                mineDetector = animator.gameObject.GetComponentInChildren <MineDetector>();
            }
            if (creature == null)
            {
                creature = animator.gameObject.GetComponent <Creature>();
            }

            behaviourDisplay.text = $"{ GetType() }";
            await pathWalker.WalkTo(PathFinderManager.Instance.RandomWalkablePosition);
        }
        catch (Exception e)
        {
            Debug.LogError(e);
            OnStateEnter(animator, stateInfo, layerIndex);
        }
    }
コード例 #3
0
    override public async void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        try
        {
            if (pathWalker == null)
            {
                pathWalker = animator.gameObject.GetComponent <PathWalker>();
            }
            if (behaviourDisplay == null)
            {
                behaviourDisplay = animator.gameObject.GetComponentInChildren <TextMesh>();
            }
            if (explorerDetector == null)
            {
                explorerDetector = animator.gameObject.GetComponentInChildren <MineDetector>();
            }

            behaviourDisplay.text = $"{ GetType() }";

            SoundManager.Instance.PlaySound(Sound.Footman_As_You_Wish_Sound_Effect);

            await pathWalker.WalkTo(explorerDetector.Mine.Position);
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
コード例 #4
0
    override public async void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        try
        {
            if (pathWalker == null)
            {
                pathWalker = animator.gameObject.GetComponent <PathWalker>();
            }
            if (behaviourDisplay == null)
            {
                behaviourDisplay = animator.gameObject.GetComponentInChildren <TextMesh>();
            }
            if (mineDetector == null)
            {
                mineDetector = animator.gameObject.GetComponentInChildren <MineDetector>();
            }

            if (mineDetector.Mine == null)
            {
                animator.SetBool("MinesInView", false);
                return;
            }

            await pathWalker.WalkTo(mineDetector.Mine.Position);

            SoundManager.Instance.PlaySound(Sound.Peasant_More_Work_Sound_Effect);
            behaviourDisplay.text = $"{ GetType() }";
            collectedGold         = animator.GetInteger("Gold");
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
コード例 #5
0
    override public async void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        try
        {
            if (pathWalker == null)
            {
                pathWalker = animator.gameObject.GetComponent <PathWalker>();
            }
            if (behaviourDisplay == null)
            {
                behaviourDisplay = animator.gameObject.GetComponentInChildren <TextMesh>();
            }
            if (base_home == null)
            {
                base_home = GameManager.Instance.GetBase();
            }
            if (mineDetector == null)
            {
                mineDetector = animator.gameObject.GetComponentInChildren <MineDetector>();
            }

            behaviourDisplay.text = $"{ GetType() }";
            collectedGold         = animator.GetInteger("Gold");
            base_home             = GameManager.Instance.GetBase();

            SoundManager.Instance.PlaySound(Sound.Peasant_Yes_My_Lord_Sound_Effect);
            await pathWalker.WalkTo(base_home.transform.position);
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }
コード例 #6
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();
    }
コード例 #7
0
    BehaviorReturnCode FindEnemy()
    {
        Debug.Log("Buscando enemigo");

        var go = GameManager.Instance.Creatures
                 .Where(x => x.name.Contains("Explorer") || x.name.Contains("Worker"))
                 .Where(x => x.GetComponent <Creature>() != null)
                 .FirstOrDefault(x => (x.gameObject.transform.position - transform.position).magnitude < view_range);

        if (go == null)
        {
            return(BehaviorReturnCode.Failure);
        }

        enemyTransform = go.transform;
        Debug.Log("Encontrado enemigo");
        _ = PathWalker.WalkTo(enemyTransform.position); // Corta el camino anterior
        PathWalker.WALK_SPEED = 12;
        SoundManager.Instance.PlaySound(Sound.Wolf_Aggro);
        return(BehaviorReturnCode.Success);
    }