Beispiel #1
0
        public virtual void ChangeToState(HFSMState toState, bool isForce = false, params object[] args)
        {
            HFSM      rootHFSM  = this.GetRootHFSM();
            HFSMState fromState = rootHFSM.GetCurrentState();

            if (fromState == toState)
            {
                return;
            }

            if (!isForce && fromState != null && !fromState.IsCanChangeToState(toState, args))
            {
                return;
            }

            HFSM nearestSameParentHFSM = toState.GetNearestSameParentHFSM(fromState);

            if (fromState != null)
            {
                this.Broadcast(rootHFSM.eventDispatchers, HFSMEventNameConst.Pre_State_Exit, fromState);
                fromState.ExitLoopTo(nearestSameParentHFSM);
                this.Broadcast(rootHFSM.eventDispatchers, HFSMEventNameConst.Post_State_Exit, fromState);
            }

            this.Broadcast(rootHFSM.eventDispatchers, HFSMEventNameConst.Pre_State_Enter, toState);
            nearestSameParentHFSM.EnterLoopTo(toState, args);
            this.Broadcast(rootHFSM.eventDispatchers, HFSMEventNameConst.Post_State_Enter, toState);

            previousState = fromState;
            this.Broadcast(rootHFSM.eventDispatchers, HFSMEventNameConst.State_Change_Finish, fromState, toState);
        }
Beispiel #2
0
        public HFSM AddSubDirectHFSM(string key, Type subDirectHFSMType, params object[] initArgs)
        {
            HFSM subDirectHFSM = AddSubDirectHFSMWithoutInit(key, subDirectHFSMType);

            subDirectHFSM.InvokeMethod("Init", true, initArgs);
            subDirectHFSM.PostInit();
            return(subDirectHFSM);
        }
Beispiel #3
0
        //////////////////////////////////////////////////////////////////////
        // Add
        //////////////////////////////////////////////////////////////////////
        public HFSM AddSubDirectHFSMWithoutInit(string key, Type subDirectHFSMType)
        {
            HFSM subDirectHFSM = base.AddChildWithoutInit(key, subDirectHFSMType) as HFSM;

            subDirectHFSM.parentHFSM = this;
            this.subDirectHFSMDict[subDirectHFSM.key] = subDirectHFSM;
            return(subDirectHFSM);
        }
Beispiel #4
0
        public virtual void ExitLoopTo(HFSM toHFSM, params object[] args)
        {
            this.Exit();
            var hfsm = parentHFSM;

            while (hfsm != toHFSM)
            {
                hfsm.Exit(args);
                hfsm = hfsm.parentHFSM;
            }
        }
Beispiel #5
0
        public virtual void ChangeToHFSM(string key, bool isForce = false, params object[] args)
        {
            HFSM toHFSM = this.GetRootHFSM().GetSubHFSM(key, true);

            while (toHFSM.defaultSubDirectHFSM != null)
            {
                toHFSM = toHFSM.defaultSubDirectHFSM;
            }
            HFSMState toState = toHFSM.defaultSubDirectState;

            this.ChangeToState(toState, isForce, args);
        }
Beispiel #6
0
        public HFSM GetRootHFSM()
        {
            HFSM rootHFSM = this.cache.GetOrAddDefault("root_hfsm", () =>
            {
                HFSM hfsm = this;
                while (hfsm.parentHFSM != null)
                {
                    hfsm = hfsm.parentHFSM;
                }
                return(hfsm);
            });

            return(rootHFSM);
        }
Beispiel #7
0
        //////////////////////////////////////////////////////////////////////
        // Get
        //////////////////////////////////////////////////////////////////////
        public HFSM GetSubHFSM(string key, bool isLoopSubHFSMDict)
        {
            if (this.subDirectHFSMDict.ContainsKey(key))
            {
                return(this.subDirectHFSMDict[key]);
            }
            if (isLoopSubHFSMDict)
            {
                foreach (var subDirectHFSM in this.subDirectHFSMDict.Values)
                {
                    HFSM instance = subDirectHFSM.GetSubHFSM(key, true);
                    if (instance != null)
                    {
                        return(instance);
                    }
                }
            }

            return(null);
        }
Beispiel #8
0
 //////////////////////////////////////////////////////////////////////
 // Set
 //////////////////////////////////////////////////////////////////////
 public void SetDefaultSubDirectHFSM(string key)
 {
     this.defaultSubDirectHFSM = subDirectHFSMDict[key];
 }