Understanding Types and Generic methods (specifically for Prime31's StateKit, but general help needed)
I'm using and loving Prime 31's StateKit. But it seems I've reached a dead-end in my understanding of types and functions with generics (i.e. changeState<>).
I've made characters that use SKStates as abilities. When I needed to add more parameters to abilities, I made ScriptableObjects for them (e.g. mana cost, target type, etc).
Now I'm having trouble associating states with the SKStates as types.
For example, consider this non-working code:
var type = System.Type.GetType(chosenAbility.name); // maybe I'll grab the type by string?
_machine.changeState<type>(); // but this doesn't compile - generics don't take actual types?
It's everywhere in my code, and I'd love to be able to replace all my sloppy string checks with something simple and type safe. For e.g.:
if (chosenAbility.name == "Dodge")
_machine.changeState<Dodge>();
else if (chosenAbility.name == "Block")
_machine.changeState<Block>();
else if (chosenAbility.name == "RangedAttack")
_machine.changeState<RangedAttack>();
(where chosenAbility is an Ability : ScriptableObject)
How might I do this in just two lines? Something to the effect of:
_machine.changeState<chosenAbility>();
or
_machine.changeState<chosenAbility.stateTypeThingySomething?>();
Any help or pointers would be greatly appreciated! Thanks so much!