Exemplo n.º 1
0
        public IEnumerator IEChangeToState(CoroutineHFSMState toState, bool isForce = false, params object[] args)
        {
            CoroutineHFSM      rootHFSM  = this.GetRootHFSM() as CoroutineHFSM;
            CoroutineHFSMState fromState = rootHFSM.GetCurrentState() as CoroutineHFSMState;

            if (fromState == toState)
            {
                yield break;
            }

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

            CoroutineHFSM nearestSameParentHFSM = toState.GetNearestSameParentHFSM(fromState) as CoroutineHFSM;

            if (fromState != null)
            {
                this.Broadcast(rootHFSM.eventDispatchers, CoroutineHFSMEventNameConst.Pre_State_Exit, fromState);
                yield return(fromState.IEExitLoopTo(nearestSameParentHFSM));

                this.Broadcast(rootHFSM.eventDispatchers, CoroutineHFSMEventNameConst.Post_State_Exit, fromState);
            }

            this.Broadcast(rootHFSM.eventDispatchers, CoroutineHFSMEventNameConst.Pre_State_Enter, toState);
            yield return(nearestSameParentHFSM.IEEnterLoopTo(toState, args));

            this.Broadcast(rootHFSM.eventDispatchers, CoroutineHFSMEventNameConst.Post_State_Enter, toState);

            previousState = fromState;
            this.Broadcast(rootHFSM.eventDispatchers, CoroutineHFSMEventNameConst.State_Change_Finish, fromState, toState);
        }
Exemplo n.º 2
0
        public virtual IEnumerator IEExitLoopTo(CoroutineHFSM toHFSM, params object[] args)
        {
            yield return(IEExit());

            var hfsm = parentHFSM as CoroutineHFSM;

            while (hfsm != toHFSM)
            {
                yield return(hfsm.IEExit(args));

                hfsm = hfsm.parentHFSM as CoroutineHFSM;
            }
        }