A downloadable Script/C# File

An Open-Source Finite State Machine written in C#. It was designed for MonoGame, however should work in any game engine that uses C# for scripting (For Example: Duality, Unity, and some CryEngine C# Projects*).


Check out the product on GitHub: https://github.com/duphusdigital/finitestatemachine


Example:

using Dupus.FSM;

namespace YourNamespace

{

public enum EnumState

{

StateOne,

StateTwo,

StateThree

}


public class ExampleClass

{

private FiniteStateMachine fsm;


public ExampleClass()

{

fsm = new FiniteStateMachine(EnumState.StateTwo, new State(EnumState.StateOne, StateOne, "State No. 1"), new State(EnumState.StateTwo, StateTwo, "State No. 2"), new State(EnumState.StateThree, StateThree, "State No. 3"));

}


public bool StateOne()

{

Console.WriteLine(fsm.GetState().name); fsm.SetState(EnumState.StateThree);

return true; //We handled this state callback

}


public bool StateTwo()

{

Console.WriteLine(fsm.GetState().name);

fsm.SetState(EnumState.StateOne);

return true; //We handled this state callback

}

public bool StateThree()

{

Console.WriteLine(fsm.GetState().name);

fsm.SetState(EnumState.StateTwo);

return true; //We handled this state callback

}

}

}


*Not all CryEngine Projects use C#, most use C++

Leave a comment

Log in with itch.io to leave a comment.