Inspiaaa / UnityHFSM

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

Implement a StateBase interface? #12

Open Invertex opened 2 years ago

Invertex commented 2 years ago

Is there a reason for not implementing StateBase as an interface so states can be used as protected types such as MonoBehaviour and ScriptableObject? It seems like the only concrete part of the class is the exitTime constructor, but that seems like something that doesn't need to be. Implementing classes can simply choose to provide constructors that override that internal value or not and the interface can have a property for it.

Inspiaaa commented 6 months ago

Hi @Invertex, Thanks for the feature request! Using interfaces for states and transitions instead of common base classes generally seems like a good idea. I will consider it for future versions of UnityHFSM.

Such a change would entail significant refactoring and changes to documentation. Furthermore, the possible negative impact on performance should be carefully investigated.

Currently, it is already possible to show custom state classes in the inspector by marking them as Serializable. In the upcoming 2.1 release, the serialization error due to Time.time will be fixed, meaning that this will become a viable option.

Invertex commented 6 months ago

Great to hear you might consider it, hope it works out!

And that's great to hear about the fix :)