/// <summary>
        /// 开始流程。
        /// </summary>
        /// <typeparam name="T">要开始的流程类型。</typeparam>
        public void StartProcedure <T>() where T : ProcedureBase
        {
            if (m_ProcedureFSM == null)
            {
                throw new Exception("You must initialize procedure first.");
            }

            m_ProcedureFSM.Start <T>();
        }
        public Boolean CallFSM(SafeID tID, String tReturnID, params Object[] tArgs)
        {
            if (!this.Available)
            {
                return(false);
            }
            else if (!this.IsActive)
            {
                return(false);
            }

            lock (m_Locker)
            {
                State tTarget = m_FreeStateSet.Find(tID);
                if (null != tTarget)
                {
                    if (!tTarget.Available)
                    {
                        return(false);
                    }


                    if (tTarget.IsFSM)
                    {
                        IFSM tFSM = tTarget as IFSM;
                        if (null == tFSM)
                        {
                            return(false);
                        }
                        m_FreeStateSet.Remove(tID);
                        m_ActiveFSMSet.Add(tTarget);
                        tFSM.Reset();
                        do
                        {
                            miniFSM tminiFSM = tFSM as miniFSM;
                            if (null == tminiFSM)
                            {
                                break;
                            }
                            tminiFSM.m_ReturnStateID = tReturnID;
                        }while (false);

                        tFSM.Start(tArgs);
                    }
                    else
                    {
                        m_FreeStateSet.Remove(tID);
                        m_ActiveStateSet.Add(tTarget);
                    }
                }
            }

            m_StateChanged = true;

            RefreshState();

            return(true);
        }
示例#3
0
        // Use this for initialization
        void Start()
        {
            ModuleManager.Instance.Init("LarkFramework.FSM.Example");

            TickManager.Instance.Init();

            FSMManager.Instance.Init();

            fsm = FSMManager.Instance.CreateFsm("Testfsm", this, new FSMA(), new FSMB());

            fsm.Start <FSMA>();
        }
        public Boolean Start(params Object[] tArgs)
        {
            if ((m_Status != Status.FSM_IDLE) || (0 == m_FreeStateSet.Count))
            {
                return(false);
            }

            lock (m_Locker)
            {
                State tFirstState = m_FreeStateSet.Items[0];
                if (!tFirstState.Available)
                {
                    return(false);
                }
                if (tFirstState.IsFSM)
                {
                    IFSM tFSM = tFirstState as IFSM;
                    if (null == tFSM)
                    {
                        return(false);
                    }
                    else if (tFSM.Reset())
                    {
                        return(false);
                    }
                    else if (!tFSM.Start(tArgs))
                    {
                        return(false);
                    }
                    m_ActiveFSMSet.Add(tFirstState);
                }
                else
                {
                    m_ActiveStateSet.Add(tFirstState);
                }
                m_Args   = tArgs;
                m_Status = Status.FSM_STARTING;

                if (null != FSMStarted)
                {
                    try
                    {
                        FSMStarted.Invoke(this, m_Args);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(true);
        }
        public Boolean TriggerFSM(SafeID tID, params Object[] tArgs)
        {
            if (!this.Available)
            {
                return(false);
            }
            else if (!this.IsActive)
            {
                return(false);
            }

            lock (m_Locker)
            {
                State tTarget = m_FreeStateSet.Find(tID);
                if (null != tTarget)
                {
                    if (!tTarget.Available)
                    {
                        return(false);
                    }


                    if (tTarget.IsFSM)
                    {
                        IFSM tFSM = tTarget as IFSM;
                        if (null == tFSM)
                        {
                            return(false);
                        }
                        m_FreeStateSet.Remove(tID);
                        m_ActiveFSMSet.Add(tTarget);
                        tFSM.Reset();
                        tFSM.Start(tArgs);
                    }
                    else
                    {
                        m_FreeStateSet.Remove(tID);
                        m_ActiveStateSet.Add(tTarget);
                    }
                }
            }

            m_StateChanged = true;

            RefreshState();

            return(true);
        }