I’m currently looking into how CodeMonkey implemented the accuracy system in the Xcom prototype he made, and was surprised to see an interface called IUnitAction. Within, it contained a few functions and a enum list of every action type. I also noticed that it did not replace the BaseAction class in the prototype, but that class contains lot less code than the BaseAction class on this course, presumably because the interface does a lot of the work instead.
The hit percent UI on units (which tells the player the chance to hit them with a shoot action) is enabled through the UnitWorldUI script when the shoot action is selected, by checking the action type through the IUnitAction interface and then running the necessary code if it’s a shootAction. I could just copy that code from the IUnitAction script, but I’d like to understand why it was done that way and the advantages of it. Could I not just have the BaseAction get the action type, in the same way it gets a string for the action name to apply to the action buttons, making the IUnitAction script unnecessary?
I wondered whether it has been done this way because it allows future expansion on the actions. For example, I was wondering how I might expand the grenade action in future to support multiple types of grenades. I expected I would be making a BaseGrenadeAction, so that each grenade extends BaseGrenadeAction, which in turn extends BaseAction, but could/should I use an interface like this to set up a bunch of different types of grenades, which are all routed through the grenade action?
ShootAction could presumably be expanded with the an interface for a bunch of shooting abilities (examples from Xcom like rapid fire, suppression, double-tap, flush, close encounters etc) and allowing the HitChanceText to be correctly displayed for each of them, or ShootAction could be turned into BaseShootAction with all the variant abilities fed through it before going through BaseAction.
Hopefully I’m making sense. Is one of these two options a better approach in this project (particularly, is one more performant than the other) or is it a personal preference thing?