예제 #1
0
        public bool Equals(StateTransition <T> other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(mInitState.Equals(other.GetInitState()) && mEndState.Equals(other.GetEndState()));
        }
예제 #2
0
        // 상태 전이 등록
        public void AddTransition(T init, T end,
                                  Callback _callback_excute,
                                  Callback _callback_exit  = null,
                                  Callback _callback_enter = null,
                                  IEnumerable _routine     = null)
        {
            StateTransition <T> tr = new StateTransition <T>(init, end);

            if (mTransExcute.ContainsKey(tr))
            {
                Debug.LogErrorFormat("[FSM] Transition: {0} - {1} exists already.", tr.GetInitState(), tr.GetEndState());
                return;
            }

            mTransEnter.Add(tr, _callback_enter);
            mTransExcute.Add(tr, _callback_excute);
            mTransExit.Add(tr, _callback_exit);
            mTransEnumerator.Add(tr, _routine);

            //Debug.Log("[FSM] Added transition " + mTransExcute.Count + ": " + tr.GetInitState() + " - " + tr.GetEndState() + ", Callback: " + _callback_excute);
        }
예제 #3
0
        // Advece to next state
        public bool Advance(T nextState)
        {
            if (mbLocked)
            {
                return(false);
            }

            // Check if the transition is valid
            StateTransition <T> transition = new StateTransition <T>(mState, nextState);

            System.Delegate _delegate;
            if (!mTransExcute.TryGetValue(transition, out _delegate))             // new StateTransition(mState, nextState)
            {
                Debug.LogErrorFormat("[FSM] Cannot advance from {0}  to {1} state", mState, nextState);
                return(false);
            }

            // Do Exit prev state
            _DoCallback(mTransExit, new StateTransition <T>(mPrevState, mState));

            //Debug.Log(ColorType.cyan, "[FSM] Advancing to " + nextState + " from " + mState);

            // Change state
            mPrevState           = mState;
            mState               = nextState;
            this.currTransExcute = transition;

            // pick up current one
            mTransEnumerator.TryGetValue(transition, out currTransEnumerator);


            // Do Enter State
            _DoCallback(mTransEnter, transition);

            return(true);
        }
예제 #4
0
        // do callback
        static void _DoCallback(Dictionary <StateTransition <T>, System.Delegate> dicTrans, StateTransition <T> trans)
        {
            if (null == trans || null == dicTrans)
            {
                return;
            }

            System.Delegate _delegate;
            if (dicTrans.TryGetValue(trans, out _delegate))
            {
                Callback _callback = _delegate as Callback;
                if (null != _callback)
                {
                    _callback();
                }
            }
        }