Hey,
I wanted to try out Scriptable enums; that is, using ScrObj’s in lieu of enums. The problem with enums is that they’re essentially hard-coded; they’re ill-suited for situations in which the amount of potential values is likely to expand (e.g. elemental types). They’re okay when the amount of potential values is essentially set (e.g. cardinal directions), but even then dealing with them usually involve convoluted code such as over-lengthy switch statements. With ScrObj’s, the behavior is actually contained within those.
So I had that idea: I’m gonna use GameState ScrObj’s instead of relying on a GameState enum. My GameState class would have two methods (TransitionTo and TransitionFrom) which would be called whenever the ScrObj is set and is replaced, respectively. And those methods would call UnityEvents, so the code would be very loosely coupled; and you could basically define what to do directly in the inspector (enabling/disabling objects, displaying/hiding interfaces, swapping input maps, playing effects, etc) which is great for designers.
Sounded great on paper. But here’s the problem: ScrObj’s can’t take references from the hierarchy. They reside in Assets, not the Scene; so I actually can’t drag’n’drop anything in those UnityEvents. And I was wondering: Is my approach fundamentally flawed, or was I onto something? Is there a way to achieve what I described with ScrObj’s? I’d love to know.
Cheers!