Hey all. After coming back to this class after a few months. I got the generic parameters for TakeAction working and figured I would share.
Here is what I did.
In BaseAction I added the following (some of my method and variable names are different than CMs due to my own preferences)
public abstract class BaseAction : MonoBehaviour
{
public partial class ActionArgs {}
public abstract ActionArgs GenerateParameters();
...snip...
}
In each Action I define its own kind of ActionArgs and GenerateParameters method. For example, in the MoveAction I have
public class MoveAction : BaseAction
{
public class MoveArgs : ActionArgs
{
public GridPosition targetPosition;
}
public override ActionArgs GenerateParameters() {
var mousePos = LevelGrid.instance.GetGridPosition(MouseWorld.GetPosition());
return new MoveArgs() { targetPosition = mousePos };
}
...snip...
public override void TakeAction(ActionArgs parameters, Action onActionComplete) {
var moveParameters = (MoveArgs)parameters;
_targetPos = LevelGrid.instance.GetWorldPosition(moveParameters.targetPosition);
...snip...
}
}
and in the UnitActionSystem this is used in the HandleSelectedAction as follows:
private bool HandleSelectedAction() {
...snip...
var param = _selectedAction.GenerateParameters();
SetBusy();
_selectedAction.TakeAction(param, NotBusy);
...snip...
}