Skip to content
microlith57 edited this page Aug 3, 2024 · 3 revisions

Everest has an API to add custom states to StateMachines; this is most useful to add new Player states. This should be done after the relevant StateMachine component is created, and it's important that you add states to every relevant StateMachine instance — eg. when adding a Player state, you have to add the state to every player that's created. In practice that means you should use an event or hook to add the states.

Everest has some events you can use for this purpose:

  • Everest.Events.Player.OnRegisterStates(Player player)
  • Everest.Events.Seeker.OnRegisterStates(Seeker seeker)
  • Everest.Events.AngryOshiro.OnRegisterStates(AngryOshiro oshiro)

For example, to add a Player state:

// in your EverestModule:
public override void Load() {
  Everest.Events.Player.OnRegisterStates += RegisterPlayerState;
}

public override void Unload() {
  Everest.Events.Player.OnRegisterStates -= RegisterPlayerState;
}

// adding the state:
public static int StYourState; // store the state index so you can reference it
internal static void RegisterPlayerState(Player player) {
  StYourState = player.AddState(
    "YourState",
    YourStateUpdate,
    // these are optional:
    YourStateCoroutine,
    YourStateBegin,
    YourStateEnd
  );
}

// state implementation:
internal static int YourStateUpdate(Player player) { /* your implementation; returns the state to transition to */ }
internal static IEnumerator YourStateCoroutine(Player player) {  }
internal static void YourStateBegin(Player player) {  }
internal static void YourStateEnd(Player player) {  }

For more information about AddState, see its implementation in the StateMachine patch class. Note that for convenience, Player, Seeker, and AngryOshiro also have AddState methods that simply call their StateMachine's AddState.

Clone this wiki locally