I am looking to implement the example you talked about of having the generic TakeAction method take BaseParameters as one of its parameters.
To do this I got it working by writing my HandleSelectedAction method as follows:
private bool HandleSelectedAction() {
if (!Input.GetMouseButtonDown(0)) return false;
var mouseGridPos = LevelGrid.instance.GetGridPosition(MouseWorld.GetPosition());
BaseParameters param = _selectedAction switch {
MoveAction moveAction => new MoveParameters() { targetPosition = mouseGridPos },
SpinAction spinAction => new SpinParameters(),
_ => throw new ArgumentOutOfRangeException()
};
if (_selectedAction.IsValidGridPosition(mouseGridPos)) {
IsBusy();
_selectedAction.TakeAction(param, NotBusy);
return true;
}
return false;
}
However, I do not like using the switch to specify the parameter class to use since that means that I will need to change the code every time I want to add a new action. Is there a way of selecting the parameter class to use depending on what out selectedAction is without doing this?