示例#1
0
 public void StartAi()
 {
     _target    = BattleManager._Instance.CurrentPlayer;
     _currentAI = eAiState.Idle;
     StartCoroutine(coAIUpdate());
 }
示例#2
0
    IEnumerator coAIUpdate()
    {
        while (true)
        {
            eAnimationStateName curState = CurrentStateName();
            switch (_currentAI)
            {
            case eAiState.Idle:
                //인식 범위
                if (CalDistance() > _unit.Stat.AppreciateDistance)
                {
                    if (HasState(eAnimationStateName.Hide))
                    {
                        ChangeState(eAnimationStateName.Hide);
                    }
                }
                else
                {
                    CalDirToTarget();
                    switch (curState)
                    {
                    case eAnimationStateName.Idle:
                        if (HasState(eAnimationStateName.Run))
                        {
                            ChangeState(eAnimationStateName.Run);
                            _currentAI = eAiState.MoveToTarget;
                        }
                        else if (HasState(eAnimationStateName.Attack))
                        {
                            ChangeState(eAnimationStateName.Attack);
                            _currentAI = eAiState.Attack;
                        }
                        break;

                    case eAnimationStateName.Hide:
                        if (HasState(eAnimationStateName.Rise))
                        {
                            ChangeState(eAnimationStateName.Rise);
                            _currentAI = eAiState.MoveToTarget;
                        }
                        break;
                    }
                }

                break;

            case eAiState.MoveToTarget:
                if (CalDistance() > _unit.Stat.AttackRange)
                {
                    if (HasState(eAnimationStateName.Run))
                    {
                        CalDirToTarget();
                        ChangeState(eAnimationStateName.Run);
                    }
                }
                else
                {
                    CalDirToTarget();
                    switch (curState)
                    {
                    case eAnimationStateName.Run:
                        if (HasState(eAnimationStateName.Attack))
                        {
                            ChangeState(eAnimationStateName.Attack);
                            _currentAI = eAiState.Attack;
                        }
                        else
                        {
                            ChangeState(eAnimationStateName.Idle);
                            _currentAI = eAiState.Idle;
                        }
                        break;
                    }
                }

                break;

            case eAiState.Attack:
                if (CalDistance() > _unit.Stat.AttackRange)
                {
                    ChangeState(eAnimationStateName.Idle);
                    _currentAI = eAiState.Idle;
                }
                else
                {
                    switch (curState)
                    {
                    case eAnimationStateName.Idle:
                        if (HasState(eAnimationStateName.Attack) && CurrentStateName() != eAnimationStateName.Attack)
                        {
                            CalDirToTarget();
                            ChangeState(eAnimationStateName.Attack);
                        }
                        break;
                    }
                }
                break;
            }
            yield return(_waitSec);
        }
    }
示例#3
0
 private void Awake()
 {
     _updateDealy = 0.5f;
     _currentAI   = eAiState.Idle;
     _waitSec     = new WaitForSeconds(_updateDealy);
 }