• Stars
    star
    220
  • Rank 180,422 (Top 4 %)
  • Language
    C#
  • Created over 12 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dead simple, lightweight "states as objects" system

StateKit

Lightweight and simple to use state machine implementing the "states as objects" system. The idea is to create a state machine for some target object (could be a player, NPC, overall game, menu system, etc) that allows you to separate all the states into separate classes while retaining access to the original target object. Setup is made as simple as possible. Assuming the target object is of class SomeClass any states made should inherit from SKState<SomeClass>. Changing state is just a matter of calling the changeState method and providing the class name of the state to change to. All states must implement 3 methods: begin, update and end. That's all there is to it. The rest is left up to the implementor.

Simple usage example:

// create a state machine that will work with an object of type SomeClass as the focus with an initial state of PatrollingState
var machine = new SKStateMachine<SomeClass>( someClass, new PatrollingState() );

// we can now add any additional states
_machine.addState( new AttackState() );
_machine.addState( new ChaseState() );

// this method would typically be called in an Update/FixedUpdate of an object
machine.update( Time.deltaTime );

// change states. the state machine will automatically create and cache an instance of the class (in this case ChasingState)
machine.changeState<ChasingState>();

StateKit now has big brother: SKMecanimStateKit. This is a StateKit state machine that is tailored to work with Mecanim. See the demo scene and comments for more info.

StateKitLite

StateKitLite is an even simpler, single class FSM. To use StateKitLite, you just subclass the StateKitLite class and provide an enum to satifsy the generic constraint (for example class YourClass : StateKitLite<SomeEnum>). The enum is then used to control the state machine. The naming conventions for the methods are best shown with an example. See below:

enum SomeEnum
{
	Walking,
	Idle
}

public class YourClass : StateKitLite<SomeEnum>()
{
	void Start()
	{
		initialState = SomeEnum.Idle;
	}

	void Walking_Enter() {}
	void Walking_Tick() {}
	void Walking_Exit() {}

	void Idle_Enter() {}
	void Idle_Tick() {}
	void Idle_Exit() {}
}

All state methods are optional. StateKitLite will cache the methods that you implemented at startup. You can change states at any time by setting the currentState property (for example currentState = SomeEnum.Walking). There are a few simple rules that you must follow in your subclass to make sure StateKitLite can function:

  • if you implement Awake in your subclass you must call base.Awake()
  • in either Awake or Start the initialState must be set
  • if you implement Update in your subclass you must call base.Update()

License

Attribution-NonCommercial-ShareAlike 3.0 Unported with simple explanation with the attribution clause waived. You are free to use StateKit in any and all games that you make. You cannot sell StateKit directly or as part of a larger game asset.

More Repositories

1

Nez

Nez is a free 2D focused framework that works with MonoGame and FNA
C#
1,799
star
2

CharacterController2D

C#
1,032
star
3

TouchKit

Gestures and input handling made sane for Unity
C#
896
star
4

GoKit

Lightweight tween library for Unity
C#
583
star
5

RecyclerKit

Object pool manager for Unity
C#
363
star
6

TransitionKit

Modular, extensible transitions in scene and between scenes
C#
300
star
7

SpriteLightKit

Blended lighting system for Unity that works with standard Sprites
C#
227
star
8

ZestKit

Tween library for Unity. The best of GoKit and GoKitLite combined in an easy to use API
C#
156
star
9

Nez-Samples

Samples and demos of various Nez features
C#
148
star
10

zig-ecs

Zig
144
star
11

P31UnityAddOns

Mostly defunct. Features were added and components broken out in the *Kit repositories.
C#
142
star
12

zig-upaya

Zig-based framework for creating game tools and helper apps
Zig
124
star
13

MessageKit

Decoupled message sending system meant as a replacement for SendMessage and its variants.
C#
122
star
14

zig-gamekit

Companion repo for zig-renderkit for making 2D games
Zig
103
star
15

CameraKit2D

Framework for creating 2D camera systems
C#
95
star
16

zig-renderkit

Zig
54
star
17

zig-flecs

C
51
star
18

GoKitLite

A super duper lightweight tweening library for Unity
C#
51
star
19

SoundKit

C#
45
star
20

Unity-Ripgrep-Search-Tool

C#
42
star
21

P31TaskManager

General purpose task manager that provides a lot more control and power than a standard coroutine
C#
35
star
22

via

V 2D game library
V
29
star
23

UnityCgShaderTutorials

Source code for the Unity Cg Shaders tutorial series on YouTube: http://www.youtube.com/playlist?list=PLb8LPjN5zpx1tauZfNE1cMIIPy15UlJNZ
C#
27
star
24

V-C-Wrapper-Generator

Helper for generating Odin and V wrapper code from C source
C#
19
star
25

Simple-ECS-Sharp

C#
18
star
26

ecs-lua

A simple, hybrid ECS
Lua
17
star
27

zig-miniaudio

Zig
17
star
28

SpriteKit

DEFUNCT: Unity now has 2D tools built in. This is now not maintained.
C#
15
star
29

PaletteKit

Helpful editor classes for importing and displaying color palettes
JavaScript
12
star
30

LearningUnits

C#
10
star
31

Odin-Sublime-Text-Plugin

Python
9
star
32

ImGuiGL-Renderer

C#
9
star
33

zig-vulkan

C++
5
star
34

egui_curve_tool

Rust
4
star
35

zig-aya

Zig
4
star
36

App-Engine-Task-Manager

Python
3
star
37

Odin-Libs

C
3
star
38

v-temp-modules

V
3
star
39

zig-fmod

Zig
2
star
40

Hugo-Helper

macOS app for managing a Hugo website
C#
2
star
41

prime31.github.io

HTML
2
star
42

fips-flecs

fipsified version of the Flecs ECS
CMake
1
star