API.Util.FSM - JuDelCo/Core GitHub Wiki

Namespace: Ju.FSM

FSM

State CurrentState;
int StateFrameCounter;
float StateTimer;

void AddState(State state);
void AddState(int stateId, State state);
void AddState(string stateName, State state);

void SetState(int stateId);
void SetState(string stateName);
void SetState(State state);

int GetStateId(string stateName);
void Tick(float deltaTime);
void FixedTick();

State

bool Condition();

void OnEnter();
void OnTick();
void OnFixedTick();
void OnExit();

bool IsAllow();
bool IsCurrent();

State Extensions

These extensions can be used inside of a state method.

You only need to add using Ju.Services.Extensions; and you're ready.

void EventSubscribe<T>(Action<T> action, int priority = 0);
void EventSubscribe<T>(Action action, int priority = 0);
void EventSubscribe<T>(Action<T> action, Func<T, bool> filter, int priority = 0);
void EventSubscribe<T>(Action action, Func<T, bool> filter, int priority = 0);
void EventSubscribe<T>(byte channel, Action<T> action, int priority = 0);
void EventSubscribe<T>(byte channel, Action action, int priority = 0);
void EventSubscribe<T>(byte channel, Action<T> action, Func<T, bool> filter, int priority = 0);
void EventSubscribe<T>(byte channel, Action action, Func<T, bool> filter, int priority = 0);

Coroutine CoroutineStart(IEnumerator routine);

IPromise WaitUntil(Func<bool> condition);
IPromise WaitWhile(Func<bool> condition);
IPromise WaitForSeconds<T>(float seconds) where T : ITimeDeltaEvent;
IPromise WaitForSeconds(float seconds);
IPromise WaitForTicks<T>(int ticks) where T : ITimeEvent;
IPromise WaitForNextUpdate();
IPromise WaitForNextFixedUpdate();

IClock NewClock<T>() where T : ITimeDeltaEvent;
IClock NewClock<T>(float elapsedSeconds) where T : ITimeDeltaEvent;
ITimer NewTimer<T>(float seconds, Action onCompleted) where T : ITimeDeltaEvent;
IFrameTimer NewFrameTimer<T>(int frames, Action onCompleted) where T : ITimeEvent;

void NodeSubscribe(JNode node, Action<JNode, JNodeEvent> action);
void NodeSubscribe(JNode node, JNodeEvent eventFilter, Action<JNode> action);
void NodeSubscribe<T>(JNode node, JNodeEvent eventFilter, Action<T> action) where T : JNode;
void NodeSubscribe(JNode node, Action action);
void NodeSubscribe(JNode node, JNodeEvent eventFilter, Action action);
void DataSubscribe<T>(JData<T> node, Action<JData<T>> action);
Action<T> DataBind<T>(JData<T> node, Action<JData<T>> action);
Action<TRemote> DataBind<T, TRemote>(JData<T> node, Action<JData<T>> action, Func<TRemote, T> converter);

SimpleFSM

Simplified FSM to create state logic without creating new classes per state.

Tick will change the state automatically if there are registered states with conditions. They are checked in the order the states were added to the FSM.

int StateTickCounter;
float StateTimer;

void AddState(Action state);
void AddState(int stateId, Action state);
void AddState(string stateName, Action state);
void AddState(Func<bool> condition, Action state);
void AddState(int stateId, Func<bool> condition, Action state);
void AddState(string stateName, Func<bool> condition, Action state);

void SetState(int stateId);
void SetState(string stateName);

int GetStateId(string stateName);

void Tick();
⚠️ **GitHub.com Fallback** ⚠️