Exemple #1
0
        public FiniteState <T> AddState(int state, IFiniteStateExecutor <T> executor)
        {
            FiniteState <T> addState = AddState(state);

            addState.SetStateExecutor(executor);
            return(addState);
        }
Exemple #2
0
        /**
         * 为两个状态之间添加关联。如果两个状态已经存在关联,则返回该关联。
         *
         * @param src
         * @param dst
         * @return
         */
        public FiniteStateTransaction <T> AddTranscation(FiniteState <T> src, FiniteState <T> dst)
        {
            if (!transactions.ContainsKey(src))
            {
                throw new Exception("存在为止的state:" + src);
            }

            List <FiniteStateTransaction <T> > list             = transactions[src];
            FiniteStateTransaction <T>         fightTransaction = null;

            foreach (FiniteStateTransaction <T> t in list)
            {
                if (t.GetDstState() == dst)
                {
                    fightTransaction = t;
                    break;
                }
            }

            if (fightTransaction == null)
            {
                fightTransaction = new FiniteStateTransaction <T>(dst);
                list.Add(fightTransaction);
            }
            return(fightTransaction);
        }
Exemple #3
0
 /// <summary>
 /// 将一个状态设置为默认状态
 /// </summary>
 /// <param name="fightState"></param>
 public void setDefaultState(FiniteState <T> defaultState)
 {
     if (defaultState == null)
     {
         throw new NullReferenceException("Can not found such state " + defaultState + " as default state.");
     }
     currentState = defaultState;
 }
Exemple #4
0
        /// <summary>
        /// 将一个状态设置为默认状态
        /// </summary>
        /// <param name="state"></param>
        public void setDefaultState(int state)
        {
            FiniteState <T> defaultState = allState[state];

            if (defaultState == null)
            {
                throw new NullReferenceException("Can not found such state " + state + " as default state.");
            }
            setDefaultState(defaultState);
        }
Exemple #5
0
        public void Init(Enemy enemy)
        {
            this.enemy = enemy;

            foreach (var state in states)
            {
                state.SetStateMachine(this);
            }

            currentState = states[0];
        }
Exemple #6
0
 public void RemoveState(FiniteState <T, U> state)
 {
     if (mStateDic.ContainsKey(state.StateID))
     {
         mStateDic.Remove(state.StateID);
     }
     else
     {
         Debug.LogError("not found state");
     }
 }
Exemple #7
0
        public void Update()
        {
            currentState.Execute();
            FiniteState next = currentState.GetNextState();

            if (next != null)
            {
                currentState.Shutdown();
                currentState = next;
                currentState.Startup();
            }
        }
Exemple #8
0
        /// <summary>
        /// tick方法即是状态机的触发,你只要在每帧中调用这个方法,
        /// 状态机就会自己根据一些输入的情况进行状态跳转,并执行当前状态下应该执行的行为。
        /// </summary>
        /// <param name="t"></param>
        /// <param name="now"></param>
        /// <param name="duration"></param>

        public void Tick(T t, long now, int duration)
        {
            //更新新的状态
            if (lastState != currentState)
            {
                currentState.onInit(this, t, now, duration);
                LogUtil.Log("Change State -- old state=" + lastState + ", new state=" + currentState);
                onStateChangeProcesser.OnChange(this, t, lastState, currentState);
                lastState = currentState;
            }
            //处理当前状态的执行器的执行函数
            currentState.DoState(this, t, now, duration);
            //更新执行函数后的数据
            ProcessOnCurrentState(currentState, t, now, duration);
            //检查执行函数后状态是否变化
            checkCurrentState();
        }
Exemple #9
0
        private void checkCurrentState()
        {
            FiniteState <T> state = null;
            List <FiniteStateTransaction <T> > list = transactions[currentState];

            foreach (FiniteStateTransaction <T> t in list)
            {
                if (t.Check(intParams, boolParams, longParams))
                {
                    state = t.GetDstState();
                    break;
                }
            }
            if (state != null && state != currentState)
            {
                currentState = state;
            }
        }
Exemple #10
0
        public void ChangeState(FiniteState <T, U> nextState)
        {
            if (mCurrentState == nextState)
            {
                Debug.LogError("change to same state...");
                return;
            }

            if (mCurrentState != null)
            {
                mCurrentState.Exit();
                mPreviousState = mCurrentState;
            }

            mCurrentState = nextState;

            mCurrentState.Enter();
        }
Exemple #11
0
        /// <summary>
        /// 增加一个状态,如果已存在,则不添加。
        /// </summary>
        /// <param name="state">返回当前状态。</param>
        /// <returns></returns>
        public FiniteState <T> AddState(int state)
        {
            FiniteState <T> fightState;

            if (!allState.ContainsKey(state))
            {
                fightState = new FiniteState <T>(state);
                allState.Add(state, fightState);

                if (!transactions.ContainsKey(fightState))
                {
                    transactions.Add(fightState, new List <FiniteStateTransaction <T> >());
                }
            }
            else
            {
                fightState = allState[state];
            }
            return(fightState);
        }
Exemple #12
0
        public void AddState(FiniteState <T, U> state)
        {
            if (state == null)
            {
                return;
            }

            state.SetEntity(this.mEntity);

            if (mStateDic.ContainsKey(state.StateID) == false)
            {
                mStateDic.Add(state.StateID, state);
            }
            else
            {
                mStateDic[state.StateID] = null;
                mStateDic[state.StateID] = state;
                Debug.LogError("overlap to add state");
            }

            state.Initialize();
        }
Exemple #13
0
 public override void Process(FiniteStateMachine <T> stateMachine, FiniteState <T> currentState, T hoster, long now, int duration)
 {
     stateMachine.SetBool(Monster.KEY_TARGET_EXIST, hoster.target);
     stateMachine.SetBool(Monster.KEY_TARGET_DEAD, hoster.targetHP == 0);
     stateMachine.SetInt(Monster.KET_DISTANCE, hoster.distance2Target);
 }
Exemple #14
0
 public FiniteStateTransaction(FiniteState <T> dst)
 {
     this.dst = dst;
 }
Exemple #15
0
 public void ProcessOnCurrentState(FiniteState <T> currentState, T t, long now, int duration)
 {
     statesProcesser.Process(this, currentState, t, now, duration);
 }