Beispiel #1
0
        /// <summary>
        /// 添加状态
        /// </summary>
        /// <param name="state"></param>
        public void AddState(ISoldierState state)
        {
            if (state == null)
            {
                Debug.LogError("要田间的状态为空"); return;
            }

            if (mStates.Count == 0)
            {
                mStates.Add(state);
                mCurrentState = state;
                return;
            }

            foreach (ISoldierState s in mStates)
            {
                if (s.stateID == state.stateID)
                {
                    Debug.LogError("要添加的状态[" + s.stateID + "]已经存在");
                    return;
                }
            }

            mStates.Add(state);
        }
Beispiel #2
0
        /// <summary>
        /// 转换
        /// </summary>
        public void PerformTransition(SoldierTransition trans)
        {
            if (trans == SoldierTransition.NullTransition)
            {
                Debug.LogError("要执行的转换条件为空:" + trans);
                return;
            }

            SoldierStateID nextStateID = mCurrentState.GetOutPutState(trans);

            if (nextStateID == SoldierStateID.NullState)
            {
                Debug.LogError("在转换条件[" + trans + "]下,没有对应的转换状态");
                return;
            }

            foreach (ISoldierState s in mStates)
            {
                if (s.stateID == nextStateID)
                {
                    mCurrentState.DoBeforeLeaving();
                    mCurrentState = s;
                    mCurrentState.DoBeforeEntering();

                    return;
                }
            }
        }