Stingray.StateMachine
1.0.2
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Stingray.StateMachine --version 1.0.2
NuGet\Install-Package Stingray.StateMachine -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Stingray.StateMachine" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Stingray.StateMachine" Version="1.0.2" />
<PackageReference Include="Stingray.StateMachine" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Stingray.StateMachine --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Stingray.StateMachine, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Stingray.StateMachine@1.0.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Stingray.StateMachine&version=1.0.2
#tool nuget:?package=Stingray.StateMachine&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Stingray.StateMachine
A lightweight, framework-agnostic hierarchical state machine library for .NET 8.0+.
Features
- 🎯 Type-Safe: Uses C# types for state identification and transitions.
- 🔗 Decoupled: Zero dependencies. Works with any game engine or application.
- ⚡ Generic: Context-aware (
IState<TContext>) for easy state sharing. - 🎣 Event-Driven: Hooks for
StateEntered,StateExited,StateTransitioned, andCompleted.
Installation
Add the generic NuGet package to your project (ensure you have built/packed the solution):
dotnet add package Stingray.StateMachine
Usage
1. Define Your Context
The context is the shared data explicitly passed to your states. It must implement IContext.
using Stingray.StateMachine;
public class GameContext : IContext {
public int PlayerId { get; set; }
public bool IsGameOver { get; set; }
}
2. Define States
Implement IState<TContext>. Each method receives both the context and the state machine instance.
using Stingray.StateMachine;
public class IdleState : IState<GameContext> {
public void Enter(GameContext context, StateMachine<GameContext> stateMachine) {
Console.WriteLine("Entering Idle");
}
public StateResult<GameContext> Execute(GameContext context, StateMachine<GameContext> stateMachine) {
if (context.IsGameOver) {
return StateResult<GameContext>.Complete();
}
// Transition to another state by type
return StateResult<GameContext>.TransitionTo<PlayState>();
}
public void Exit(GameContext context, StateMachine<GameContext> stateMachine) {
Console.WriteLine("Exiting Idle");
}
}
public class PlayState : IState<GameContext> { ... }
3. Setup and Run
var context = new GameContext();
var fsm = new StateMachine<GameContext>();
// Register states
fsm.AddState(new IdleState())
.AddState(new PlayState());
// Set entry point
fsm.SetInitialState<IdleState>();
// Start
fsm.Start(context);
// Update loop (e.g., in your game loop)
while (fsm.IsRunning) {
fsm.Step(context);
}
API Reference
StateMachine<TContext>
AddState(IState<T> state): Registers a state instance.SetInitialState<TState>(): Sets the starting state.Start(TContext context): Enters the initial state.Step(TContext context): Executes the current state's logic. Returnstrueif completed.TransitionTo<TState>(TContext context): Forcefully transitions to a state.
StateResult<TContext>
Continue(): Stay in current state.TransitionTo<TState>(): Switch to a new state.Complete(): End the state machine execution.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|
- Remove CurrentState from IContext to improve compile time checks