Exemple #1
0
        /// <summary>
        /// Instantly changes to the target state
        /// </summary>
        /// <param name="name">The name / identifier of the active state</param>
        void ChangeState(string name)
        {
            State <T> newState = GetState(name);

            ActiveState?.Exit();
            PreviousState = ActiveState?.name ?? "";

            ActiveState = newState;
            ActiveState.Enter();

            if (fromToTransitions.TryGetValue(name, out List <FromToTransition <T> > newActiveTransitions))
            {
                activeStateTransitions = newActiveTransitions;
                foreach (FromToTransition <T> transition in activeStateTransitions)
                {
                    transition.OnEnterFromState();
                }
            }
            else
            {
                activeStateTransitions = System.Array.Empty <Transition <T> >();
            }
        }