Not to be confused with this related question, I know Unity does Inheritance but I'd like to leverage it in the Inspector.
I'd like to be able to switch the action to be performed on-the-fly using buttons in the GUI. So, I've got a class `AbstractAction` that inherits from MonoBehaviour which has a single abstract method `DoAction`. I've written a couple of scripts that inherit from AbstractAction and override the method, and I want to assign them to specific slots in the GUI using the inspector (similarly to how I assign the `Texture2D`s for the buttons themselves).
public class MyGui : MonoBehaviour {
public Texture2D[] buttons;
public AbstractAction[] actions;
private int selectedAction;
void OnGUI() {
selectedAction = GUILayout.SelectionGrid(0, buttons, 2);
}
public void DoSelectedAction() {
actions[selectedAction].DoAction();
}
}
My problem is, the array is showing up fine in the Inspector (with elements "None (Abstract Action)"), but I cannot assign my subclasses of AbstractAction to them. Is there a way around this? I've tried using both an actual `abstract` parent, and a normal class with a `virtual` method.
Thanks in advance