UnityHFSM icon indicating copy to clipboard operation
UnityHFSM copied to clipboard

More Samples/Explaination On Class-based architecture

Open LaoBowen opened this issue 2 years ago • 2 comments

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!

LaoBowen avatar Feb 24 '24 14:02 LaoBowen

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!

jarrednorrisdev avatar May 11 '24 23:05 jarrednorrisdev

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.

TheGabmeister avatar Oct 13 '24 09:10 TheGabmeister