Esempio n. 1
0
    public void StartState(BaseState stateToSwitchTo, EventStateLinking e, bool doAnOverride)
    {
        // if state already running override or cancel
        if (activeStates.ContainsKey(stateToSwitchTo))
        {
            if (doAnOverride)
            {
                EndState(stateToSwitchTo);
            }
            else
            {
                return;
            }
        }


        activeStates[stateToSwitchTo] = new ActiveLinking()
        {
            links = (stateLinkers.LinksByState.ContainsKey(stateToSwitchTo) ?
                     stateLinkers.LinksByState[stateToSwitchTo] : new List <EventStateLinking>())
                    .Concat(GetLinkersForTags(stateToSwitchTo.tags, stateLinkers.LinksByTag)),

            linkingProperties = new Dictionary <string, object>(),
            timeStarted       = Time.time,
            state             = stateToSwitchTo
        };

        //start state that will fill the linkingProperties
        stateToSwitchTo.Enter(this, e?.eventResponse, activeStates[stateToSwitchTo]);

        AfterEnter(activeStates[stateToSwitchTo]);

        //give linking properties to each events to convert to event properties
        foreach (var link in activeStates[stateToSwitchTo].links)
        {
            link.triggeredOn.Init(activeStates[stateToSwitchTo]);
        }
    }
Esempio n. 2
0
    private void ExecuteEventAction(BaseState fromState, EventStateLinking e)
    {
        switch (e.action.actionType)
        {
        case EventActionType.TRANSITION:
        case EventActionType.TRANSITION_OVERRIDE:

            EndState(fromState);

            if (e.action.transitionToState != null)
            {
                StartState(e.action.transitionToState, e, e.action.actionType == EventActionType.TRANSITION_OVERRIDE);
            }

            foreach (var s in e.action.addStates)
            {
                StartState(s, e, e.action.actionType == EventActionType.TRANSITION_OVERRIDE);
            }
            break;

        case EventActionType.REMOVE:
            EndState(fromState);
            break;

        case EventActionType.ADD:
        case EventActionType.ADD_OVERRIDE:

            if (e.action.transitionToState != null)
            {
                StartState(e.action.transitionToState, e, e.action.actionType == EventActionType.ADD_OVERRIDE);
            }
            foreach (var s in e.action.addStates)
            {
                StartState(s, e, e.action.actionType == EventActionType.ADD_OVERRIDE);
            }
            break;
        }
    }