npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

com.amanotes.statemachine

v1.1.0

Published

Generic state machine implementation for Unity

Readme

StateMachine

Package: com.amanotes.statemachine
Version: 1.0.0

Generic type-safe state machine for Unity with enum-based states and transition validation.


Features

  • 🎮 Type-safe state management with generics
  • 🎯 Automatic transition validation
  • 🎨 Enter/Exit callbacks per state
  • 🚀 Fluent API for state registration
  • 🔧 State change event notifications

Documentation

Complete API inline in this README (mini-package: 2 classes).


Installation

Add the package to your Unity project via Packages/manifest.json:

{
  "dependencies": {
    "com.amanotes.statemachine": "1.0.0"
  },
  "scopedRegistries": [
    {
      "name": "npmjs",
      "url": "https://registry.npmjs.org/",
      "scopes": [
        "com.amanotes.statemachine"
      ]
    }
  ]
}

Quick Start

public enum GameState { Menu, Playing, Paused }

public class GameStateMachine : StateMachine<GameState>
{
    public GameStateMachine() : base(GameState.Menu)
    {
        RegisterState(GameState.Menu)
            .WithTransitionTo(GameState.Playing);
        
        RegisterState(GameState.Playing)
            .WithTransitionTo(GameState.Paused);
        
        RegisterState(GameState.Paused)
            .WithTransitionTo(GameState.Playing);
    }
}

var sm = new GameStateMachine();
sm.OnEnter(GameState.Playing, () => Debug.Log("Game started"));
sm.Reset();
sm.TransitionTo(GameState.Playing);

API Reference

Key Classes

StateMachine

  • Purpose: Generic state machine with transition validation
  • Key methods: RegisterState(), TransitionTo(), OnEnter(), OnExit()
  • Key properties: CurrentState, PreviousState, IsStarted

StateInfo

  • Purpose: State metadata and transition builder
  • Key methods: WithTransitionTo()

StateMachine

Properties:

  • TKey CurrentState - Current active state
  • TKey PreviousState - Previously active state
  • bool IsStarted - Whether state machine has been started
  • string CurrentStateName - Name of current state
  • Action<TKey, TKey> OnStateChanged - Event fired on state transitions

Lifecycle:

  • StateMachine() - Constructor without initial state
  • StateMachine(TKey initialState) - Constructor with initial state
  • void Start(TKey state) - Start state machine at specific state
  • void Reset() - Reset to initial state (if provided)
  • bool TransitionTo(TKey key) - Transition to new state (validates transition)
  • void Clear() - Clear current state without resetting

Registration:

  • StateInfo<TKey> RegisterState(TKey key, string name = null) - Register state
  • void AddTransition(TKey from, TKey to) - Add valid transition

Callbacks:

  • void OnEnter(TKey key, Action callback) - Add enter callback
  • void OnExit(TKey key, Action callback) - Add exit callback
  • void RemoveOnEnter(TKey key, Action callback) - Remove enter callback
  • void RemoveOnExit(TKey key, Action callback) - Remove exit callback
  • void AddOnStateChanged(Action<TKey, TKey> callback) - Add state change listener

Queries:

  • bool IsState(TKey key) - Check if currently in state
  • bool HasState(TKey key) - Check if state is registered
  • string GetStateName(TKey key) - Get state name

StateInfo

Properties:

  • TKey Key - State key
  • int Id - Internal state ID
  • string Name - State name
  • Action OnEnter - Enter callback
  • Action OnExit - Exit callback
  • StateMachine<TKey> StateMachine - Parent state machine

Methods:

  • StateInfo<TKey> WithTransitionTo(TKey to) - Add transition (fluent API)

Dependencies

  • Unity 2021.3+

Version History

See CHANGELOG.md