UniState provides extension methods for Reflex's ContainerBuilder.
Preparation
If Reflex is installed via UPM, no preparation is needed. If installed manually, add the UNISTATE_REFLEX_SUPPORT define symbol in Player Settings -> Player -> Scripting Define Symbols.
Registration
Use RegisterStateMachine and RegisterState on the ContainerBuilder.
RegisterState(typeof(MyState)) registers the state as itself and all its implemented interfaces.- Use the two-parameter overload to explicitly expose an additional abstract/base contract.
- Use
Lifetime.Singleton when a singleton lifetime is required.
Usage
Resolve the IStateMachine from the Reflex container and call Execute.
// Registration
private void RegisterStates(ContainerBuilder builder)
{
// Recommended usage
builder.RegisterStateMachine(typeof(StateMachine), typeof(IStateMachine));
builder.RegisterState(typeof(BarState));
builder.RegisterState(typeof(BarState), typeof(BarBaseState));
// Singleton version (use cautiously)
builder.RegisterStateMachine(typeof(StateMachine), typeof(IStateMachine), Lifetime.Singleton);
builder.RegisterState(typeof(BarState), Lifetime.Singleton);
builder.RegisterState(typeof(BarState), typeof(BarBaseState), Lifetime.Singleton);
}
// Usage
public class DiceEntryPoint
{
private readonly IStateMachine _stateMachine;
public DiceEntryPoint(IStateMachine stateMachine) => _stateMachine = stateMachine;
public void Start()
{
_stateMachine.Execute<StartGameState>(CancellationToken.None).Forget();
}
}