Search Results for

    Show / Hide Table of Contents

    Class FSMUtils

    Class with utility functions for state machine.

    Inheritance
    Object
    FSMUtils
    Namespace: nickmaltbie.StateMachineUnity.Utils
    Assembly: cs.temp.dll.dll
    Syntax
    public static class FSMUtils

    Methods

    CreateActionAttributeCache(Type)

    Sets up an action lookup by enumerating the State classes defined within a state machine type and getting all ActionAttribute decorators defined for each State within the class.

    Declaration
    public static Dictionary<Tuple<Type, Type>, MethodInfo> CreateActionAttributeCache(Type stateMachine)
    Parameters
    Type Name Description
    Type stateMachine

    State machine to lookup State and ActionAttribute for.

    Returns
    Type Description
    Dictionary<Tuple<Type, Type>, MethodInfo>

    A lookup table mapped as (state, actionType) -> Method

    CreateEventActionCache(Type)

    Sets up an event lookup by enumerating the State classes defined within a state machine type and getting all OnEventDoActionAttribute decorators defined for each State within the class.

    Declaration
    public static Dictionary<Tuple<Type, Type>, IEnumerable<MethodInfo>> CreateEventActionCache(Type stateMachine)
    Parameters
    Type Name Description
    Type stateMachine

    State machine to lookup State and OnEventDoActionAttribute for.

    Returns
    Type Description
    Dictionary<Tuple<Type, Type>, IEnumerable<MethodInfo>>

    A lookup table mapped as (state, event) -> [ methods ]

    CreateTransitionAttributeCache(Type)

    Sets up an transition lookup by enumerating the State classes defined within a state machine type and getting all TransitionAttribute decorators defined for each State within the class.

    Declaration
    public static Dictionary<Tuple<Type, Type>, ITransition<Type>> CreateTransitionAttributeCache(Type stateMachine)
    Parameters
    Type Name Description
    Type stateMachine

    State machine to lookup State and TransitionAttribute for.

    Returns
    Type Description
    Dictionary<Tuple<Type, Type>, ITransition<Type>>

    A lookup table mapped as (state, event) -> state

    GetActionWithName(Type, String)

    Returns the action with the specified name.

    Declaration
    public static MethodInfo GetActionWithName(Type type, string actionName)
    Parameters
    Type Name Description
    Type type
    String actionName

    Name of action to search for.

    Returns
    Type Description
    MethodInfo

    Method info for the given action.

    InitializeStateMachine(IStateMachine<Type>)

    Initialize a state machine with the initialization state and ensure all the events, transitions, and actions are cached.

    Declaration
    public static void InitializeStateMachine(IStateMachine<Type> stateMachine)
    Parameters
    Type Name Description
    IStateMachine<Type> stateMachine

    state machine to setup.

    InvokeAction(IStateMachine<Type>, Type, Type, IEvent)

    Synchronously invokes an action of a given name.

    Declaration
    public static bool InvokeAction(IStateMachine<Type> stateMachine, Type actionType, Type state, IEvent evt)
    Parameters
    Type Name Description
    IStateMachine<Type> stateMachine

    state machine to invoke method of.

    Type actionType

    Type of action to invoke.

    Type state

    State to invoke action for.

    IEvent evt

    Event that triggered state (if any).

    Returns
    Type Description
    Boolean

    True if an action was found and invoked, false otherwise.

    InvokeAction<E>(IStateMachine<Type>, Type, IEvent)

    Synchronously invokes an action of a given name.

    Declaration
    public static bool InvokeAction<E>(IStateMachine<Type> stateMachine, Type state = null, IEvent evt = null)
        where E : ActionAttribute
    Parameters
    Type Name Description
    IStateMachine<Type> stateMachine

    state machine to invoke method of.

    Type state

    State to invoke action for, if unspecified or null, will use the CurrentState.

    IEvent evt
    Returns
    Type Description
    Boolean

    True if an action was found and invoked, false otherwise.

    Type Parameters
    Name Description
    E

    Type of action to invoke.

    RaiseCachedEvent(IStateMachine<Type>, IEvent)

    Raise a synchronous event for a given state machine.
    First checks if this state machine expects any events of this type for the state machine's CurrentState. These would follow an attribute of type OnEventDoActionAttribute.
    If the state machine's CurrentState expects a transition based on the event, then this will trigger the OnExitStateAttribute of the nickmaltbie.StateMachineUnity.IStateMachine, change to the next state defined in the TransitionAttribute, then trigger the OnEnterStateAttribute of the next state.

    Declaration
    public static void RaiseCachedEvent(IStateMachine<Type> stateMachine, IEvent evt)
    Parameters
    Type Name Description
    IStateMachine<Type> stateMachine
    IEvent evt

    Event to send to this state machine.

    SetupCache(Type)

    Setup the cache for the state machine if it hasn't been done already.

    Declaration
    public static void SetupCache(Type stateMachine)
    Parameters
    Type Name Description
    Type stateMachine

    SetupTransition(Type, ITransition<Type>, Dictionary<Tuple<Type, Type>, ITransition<Type>>)

    Sets up a transition within a transition lookup.

    Declaration
    public static void SetupTransition(Type state, ITransition<Type> transition, Dictionary<Tuple<Type, Type>, ITransition<Type>> transitionLookup)
    Parameters
    Type Name Description
    Type state

    Source state for saving transition.

    ITransition<Type> transition

    Transition to add to lookup table.

    Dictionary<Tuple<Type, Type>, ITransition<Type>> transitionLookup

    Lookup to add transition to.

    In This Article
    Back to top State Machine Unity Documentation