void OnEnterState(CuboState newState) { switch (m_state) { case CuboState.IDLE: m_navAgent.SetDestination(transform.position); m_navAgent.isStopped = true; break; case CuboState.MOVING_TO_EMPTY: m_navAgent.SetDestination(m_moveTarget); m_navAgent.isStopped = false; break; case CuboState.MOVING_TO_WORK: m_navAgent.SetDestination(m_moveTarget); m_navAgent.isStopped = false; break; case CuboState.WORKING: m_orderableTarget.OccupyWorkTarget(m_workTarget); m_navAgent.Move(m_workTarget.pos - transform.position); m_navAgent.SetDestination(m_workTarget.pos); m_navAgent.isStopped = false; m_lastWorkTime = Time.time + Random.Range(0f, 0.3f); break; default: throw new UnityException("Unrecognized cubo state: " + m_state); } }
void Start() { m_state = CuboState.IDLE; m_navAgent = GetComponent <NavMeshAgent>(); SpawnAnim(); Camera.main.GetComponent <AudioSource>().PlayOneShot(spawnNoise); }
void OnExitState(CuboState oldState, CuboState nextState) { switch (m_state) { case CuboState.IDLE: break; case CuboState.MOVING_TO_EMPTY: m_isUnmoving = false; break; case CuboState.MOVING_TO_WORK: break; case CuboState.WORKING: break; default: throw new UnityException("Unrecognized cubo state: " + m_state); } }
void SwitchState(CuboState newState) { OnExitState(m_state, newState); m_state = newState; OnEnterState(newState); }