Inspiaaa / UnityHFSM

A simple yet powerful class-based hierarchical finite state machine for Unity
MIT License
1.12k stars 124 forks source link

More Samples/Explaination On Class-based architecture #40

Open LaoBowen opened 8 months ago

LaoBowen commented 8 months ago

Hi~ Can we have more samples and explaination on Class-based architectures? Like:

Using Class-based architecture to rebuild the GuardAI Example.

Derived from StateBase/ActionState/State and their difference

How te create Custom Actions in such class instead of ".AddAction("OnFixedUpdate", () => { })"

Thank you!

jarrednorrisdev commented 6 months ago

I also am struggling to figure out how to elequontly implement an OnFixedLogic action in a state that inherits StateBase without changing the implementation of the package source.

EDIT: Upon further exploration of the code I found the ActionState class which may be what i was looking for. It might be worth adding mention of this to the Class architecture section of the documentation/readme.

Here is my understanding of how I might be able to do this. Are there any reasons why this might be a good or bad way to implement this functionality?

public abstract class ActionStateWithFixed : ActionState
{
    protected ActionStateWithFixed(bool needsExitTime, bool isGhostState = false)
        : base(needsExitTime, isGhostState)
    {
        AddAction("OnFixedLogic", OnFixedLogic);
    }

    public abstract void OnFixedLogic();
}
public void FixedUpdate()
    {
        MovementStateMachine.OnAction("OnFixedLogic");
    }

PS This asset is super cool, thank you for sharing!

TheGabmeister commented 1 month ago

Thanks for this information. I was trying to figure out the exact same thing. Hopefully more examples are added in the Class-based architecture section.