#RxFSM — Free & Open-Source Unity FSM library that reads like a game design document

1 messages · Page 1 of 1 (latest)

broken olive
#

Visit the link for more info: https://github.com/YoruYomix/RxFSM

You can code just like writing a game design document.

public readonly struct Damaged {  // The event "Damaged"
    public readonly float amount;   // must have an amount,
    public readonly Element element;  // an element type,
    public readonly Vector3 direction;  // and a direction.
// Looks just like a design spec, doesn't it?

      public Damaged(float amount, Element element, Vector3 direction) {
        this.amount = amount;
        this.element = element;
        this.direction = direction; }
}

// Trigger a new "Damaged" event: 50 damage, Fire element, from the hit direction.
sm.Trigger(new Damaged(50f, Element.Fire, hitDir));

sm.AddTransitionFromAny<Damaged> // When the "Damaged" event is triggered
(
      _ => !invincible, // if not invincible,
      to: CharState.Hit  // transition to the Hit state.
)

// Upon receiving damage // and entering the Hit state:
sm.EnterState<Damaged>(State.Hit, (prev, trg) =>
{
    PlayAnimation("Hit");  // Play Hit animation,
    switch (trg.element)  // Depending on the damage element,
    {   // play Fire, Ice, or Dark effects in that direction,
        case Element.Fire: SpawnFireEffect(trg.direction); break;
        case Element.Ice:  SpawnIceEffect(trg.direction);  break;
        case Element.Dark: SpawnDarkEffect(trg.direction); break;
    }
    hp -= trg.amount;  // and reduce HP by the damage amount.
});

Can’t you just visualize the in-game scene just by looking at the code?

Install via Package Manager → Add package from git URL:
https://github.com/YoruYomix/RxFSM.git?path=com.yoruyomix.rxfsm

A star on GitHub will help a lot ⭐

GitHub

Unity FSM that reads like a design document — not code - YoruYomix/RxFSM