Ejemplo n.º 1
0
        public void SendEvent(ExternalEvent evt, bool checkDependencies)
        {
            if (!stateMachines.ContainsKey(evt.Target))
            {
                if (!stateMachineProxies.ContainsKey(evt.Target))
                {
                    throw new Exception("State machine of name, " + evt.Target + ", was not found in StateMachineContext: " + base.gameObject.name);
                }
                if (stateMachineProxies[evt.Target] != null)
                {
                    stateMachineProxies[evt.Target].AddEvent(evt.Event);
                    return;
                }
                stateMachineProxies.Remove(evt.Target);
            }
            StateMachine stateMachine = stateMachines[evt.Target];

            if (checkDependencies)
            {
                CoroutineRunner.StopAllForOwner(stateMachine);
                CoroutineRunner.Start(stateMachine.CheckEventDependencies(evt), stateMachine, "Check event dependencies");
            }
            else
            {
                stateMachine.SendEvent(evt.Event);
            }
        }
Ejemplo n.º 2
0
        public IEnumerator CheckEventDependencies(ExternalEvent evt)
        {
            if (!base.isActiveAndEnabled)
            {
                yield break;
            }
            string stateName = currentState.GetTargetStateName(evt.Event);

            if (stateName != null)
            {
                State state = Definition.GetState(stateName);
                if (state == null)
                {
                    throw new Exception($"Could not get a state by the name {stateName} in state machine {base.name}");
                }
                IList <string> eventTargets = getOnEntryTargets(state.OnEntryEvents);
                int            count        = dependentStateMachineCount(eventTargets);
                while (eventTargets.Count > count)
                {
                    yield return(null);

                    count = dependentStateMachineCount(eventTargets);
                }
                context.SendEvent(evt);
            }
        }
Ejemplo n.º 3
0
        public void SendEvent(ExternalEvent evt)
        {
            if (stateChanging)
            {
                throw new Exception($"FSM '{base.name}' is trying to send external event {evt.Target}.{evt.Event} during a state change to {currentState.Name}");
            }
            switch (evt.Target)
            {
            case "parent":
                sendEventToParent(evt.Event);
                break;

            case "ancestors":
                sendEventToAncestors(evt.Event);
                break;

            case "siblings":
                sendEventToSiblings(evt.Event);
                break;

            case "children":
                sendEventToChildren(evt.Event);
                break;

            case "descendants":
                sendEventToDescendants(evt.Event);
                break;

            default:
                context.SendEvent(evt);
                break;
            }
        }
Ejemplo n.º 4
0
 public void SendEvent(ExternalEvent evt)
 {
     SendEvent(evt, checkDependencies: false);
 }