Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Shortcut for AddTriggerTransition with custom typed states #55

Open
ariok opened this issue Oct 27, 2024 · 0 comments
Open

Comments

@ariok
Copy link

ariok commented Oct 27, 2024

Hello, I have initialized my fsm with 2 custom types (AIState and AIStateEvent) instead of string type.

fsm = new StateMachine<AIState, AIStateEvent>();

I see that there are various useful shortcuts, but I can't find one to create a transition directly between custom types in AddTriggerTransition. So, I have to use:

fsm.AddTriggerTransition(AIStateEvent.PLAYER_DETECTED, new Transition<AIState>(AIState.IDLE, AIState.CHASE));

Am I correct in assuming there isn’t a shortcut like this?

fsm.AddTriggerTransition(AIStateEvent.PLAYER_DETECTED, AIState.IDLE, AIState.CHASE));

Of course, I could implement my own shortcut, but I’d prefer to use what the library provides rather than adding extra layers. :)

Something like this should work as extension:

public static void AddTriggerTransition<E, S>(this StateMachine<S, E> stateMachine, E trigger, S from, S to)
{
    stateMachine.AddTriggerTransition(trigger, new Transition<S>(from, to));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant