Пример #1
0
    /// <summary>
    /// 获取状态
    /// </summary>
    /// <param name="AIState"></param>
    /// <returns></returns>
    private StateBase GetState(AIStateType AIState)
    {
        if (this.m_StateDic.ContainsKey(AIState))
        {
            return(this.m_StateDic[AIState]);
        }
        StateBase state;

        switch (AIState)
        {
        case AIStateType.Attack:
            state = new AttackState(this.m_ActorBev, this.m_ActorAI);
            break;

        case AIStateType.Dead:
            state = new DeadState(this.m_ActorBev, this.m_ActorAI);
            break;

        case AIStateType.Hurt:
            state = new HurtState(this.m_ActorBev, this.m_ActorAI);
            break;

        case AIStateType.Idle:
            state = new IdleState(this.m_ActorBev, this.m_ActorAI);
            break;

        default: Debug.Log(AIState.ToString() + " not exsit "); return(null);
        }
        this.m_StateDic.Add(AIState, state);
        return(state);
    }
Пример #2
0
        private void OnDrawGizmos()
        {
            Handles.color = Color.black;
            Handles.Label(transform.position + new Vector3(0, 2.2f, 0), currentState.ToString());

            if (Application.isPlaying)
            {
                return;
            }

            currentState = startState;
        }
        /// <summary>
        ///		Determine if we need to update the
        ///		current state type we are in and set
        ///		an associated script
        /// </summary>
        void UpdateStateInformation()
        {
            // Determine the state in heres
            if (currentState == null)
            {
                return;
            }

            AIStateType newStateType = currentState.OnUpdate();

            if (newStateType != currentStateType)
            {
                previousState = currentStateType;
                AIStateBase newState = null;

                // Get the script driving our state
                if (!possibleStates.ContainsKey(newStateType))
                {
                    if (Logging)
                    {
                        Debug.LogError($"There are no scripts available for {newStateType.ToString()}; defaulting to idle.");
                    }
                    newStateType = AIStateType.Idle;
                }

                newState = GetRandomScriptForState(newStateType);
                if (newState == null)
                {
                    if (Logging)
                    {
                        Debug.LogError($"There are no states available for {newStateType.ToString()}");
                    }
                    return;
                }
                updateCurrentState(newState);
                currentStateType = newStateType;
            }
        }
 /// <summary>
 ///		Get a script based on the current state.
 ///		This will be the first script in the list
 /// </summary>
 void assignCurrentState()
 {
     if (possibleStates.ContainsKey(currentStateType))
     {
         currentState = possibleStates[currentStateType][0];
         currentState.OnEnterState();
     }
     else
     {
         if (Logging)
         {
             Debug.LogError($"[AIStateMachine.AssignScript()] This state ({currentStateType.ToString()}) is not allowed. It is not present in the dictionary");
         }
         forceState();
         return;
     }
 }
 /// <summary>
 /// 获取状态
 /// </summary>
 /// <param name="AIState"></param>
 /// <returns></returns>
 private StateBase GetState(AIStateType AIState)
 {
     if (this.m_StateDic.ContainsKey(AIState))
     {
         return this.m_StateDic[AIState];
     }
     StateBase state;
     switch (AIState)
     {
         case AIStateType.Attack:
             state = new AttackState(this.m_ActorBev,this.m_ActorAI);
             break;
         case AIStateType.Dead:
             state = new DeadState(this.m_ActorBev, this.m_ActorAI);
             break;
         case AIStateType.Hurt:
             state = new HurtState(this.m_ActorBev, this.m_ActorAI);
             break;
         case AIStateType.Idle:
             state = new IdleState(this.m_ActorBev, this.m_ActorAI);
             break;
         default: Debug.Log(AIState.ToString() + " not exsit "); return null;
     }
     this.m_StateDic.Add(AIState, state);
     return state;
 }