Esempio n. 1
0
        //---------------------------------------------------------------------
        void _rattleOn()
        {
            if (mbRattleOn || mbDestroy)
            {
                return;
            }
            mbRattleOn = true;

            while (mQueEvent.Count > 0)
            {
                IEbEvent ev = mQueEvent.Dequeue();

                for (int i = mQueCurrentState.Count - 1; i >= 0; i--)
                {
                    var it = mQueCurrentState[i];

                    EbState state = it;

                    if (!state._isBindEvent(ev.name))
                    {
                        continue;
                    }

                    string next_state_name = state._onEvent(ev);

                    if (string.IsNullOrEmpty(next_state_name))
                    {
                        continue;
                    }
                    if (mbDestroy)
                    {
                        break;
                    }

                    EbState next_state = null;
                    if (mMapState.ContainsKey(next_state_name))
                    {
                        next_state = mMapState[next_state_name];
                    }

                    if (next_state == null)
                    {
                        break;
                    }

                    EbState p = next_state._getParentState();

                    _exitChildState(p);

                    _enterState(next_state);

                    break;
                }
            }
            mbRattleOn = false;
        }
Esempio n. 2
0
        //---------------------------------------------------------------------
        void _rattleOn()
        {
            if (mbRattleOn)
            {
                return;
            }
            mbRattleOn = true;

            while (mQueEvent.Count > 0)
            {
                IEbEvent ev = mQueEvent.Dequeue();

                for (int i = mQueCurrentState.Count - 1; i >= 0; i--)
                {
                    var it = mQueCurrentState[i];

                    EbState state = it;

                    if (!state._isBindEvent(ev.name))
                    {
                        continue;
                    }

                    string next_state_name = state._onEvent(ev);

                    EbState next_state = null;
                    if (mMapState.ContainsKey(next_state_name))
                    {
                        next_state = mMapState[next_state_name];
                    }

                    if (null == next_state)
                    {
                        break;
                    }

                    while (mQueCurrentState.Count > 0)
                    {
                        EbState s = mQueCurrentState[mQueCurrentState.Count - 1];

                        if (next_state == s)
                        {
                            break;
                        }
                        else if (_isDirectLine(s, next_state))
                        {
                            mQueTmpState.Clear();

                            EbState p = next_state;
                            do
                            {
                                mQueTmpState.Add(p);
                                p = p._getParentState();
                            } while (p != s);

                            while (mQueTmpState.Count > 0)
                            {
                                EbState q = mQueTmpState[0];
                                q.enter();
                                mQueCurrentState.Add(q);
                                mQueTmpState.RemoveAt(0);
                            }
                        }
                        else
                        {
                            s.exit();
                            mQueCurrentState.RemoveAt(mQueCurrentState.Count - 1);
                        }
                    }

                    break;
                }
            }
            mbRattleOn = false;
        }