StateMachines

Description

The StateMachines module implements a universal state management mechanism used across different parts of the project.

This module:

  • defines base interfaces and abstractions for states

  • manages transitions between states

  • provides a unified state lifecycle (Enter / Exit / Update)

StateMachines serve as a foundation for game-level, system-level, and entity-level states, ensuring a consistent and extensible approach to logic control.

Implementation path: KrolStudio/SwipeGunner/Scripts/Runtime/Infrastructure/StateMachines/Common

⚠️ Recommendation: It is not recommended to modify the source files located in the Common folder. This code represents core infrastructure and is intended to be reused without direct modification. Functional extensions should be implemented through inheritance or by creating new implementations.


Built-in StateMachine Implementations

Implementation path: KrolStudio/SwipeGunner/Scripts/Runtime/Infrastructure/StateMachines/...

Each state machine is responsible for a specific level of logic and has a clearly defined scope.

The template includes the following state machine implementations:

1. GameStateMachine

GameStateMachine manages the global states of the application.

It is responsible for:

  • handling the application entry point

  • initializing and loading application data

  • transitioning between the main application modes

2. GameplayStateMachine

GameplayStateMachine manages states related to the core gameplay flow.

It is used to organize the gameplay lifecycle and control transitions between gameplay phases.

3. PlayerStateMachine

PlayerStateMachine is responsible for managing player states based on the current gameplay context.

4. TentacleStateMachine

TentacleStateMachine manages the states of the Tentacle entity.

Each Tentacle entity uses its own instance of a state machine.

5. EnemyStateMachine

EnemyStateMachine manages the states of the Enemy entity.

Each Enemy entity uses its own instance of a state machine.

How to Add a New StateMachine

To create a new state machine:

  1. Define a new class

  2. Inherit it from the base StateMachine class

In most cases, this class does not require additional implementation. Overriding base methods or extending functionality is only necessary when custom behavior is required.

  1. Register your state machine in the Zenject container using an appropriate installer. For details on how to create an installer and register a state machine, see: [link]

  2. Create and register the required states for the state machine. For details on how to create a state and register it within a state machine, see: [link]

  3. In the required class, request a reference to your state machine and define a method that performs a transition to the specified state.

Last updated