How to write a Story Event System with ScriptableObjects?
I'm trying to write an "event system tool" for my game where I can just have a list of "commands", like "Show message box with some message" or "Wait for 0.3 seconds before the next command".
My initial idea is to have a ScriptableObject that holds a list of these commands, so I can just go through it and execute the commands during gameplay somewhere.
So I have something like this:
[CreateAssetMenu(menuName="Narrative/FantasyEvent")]
public class FantasyEvent : ScriptableObject {
public List<NarrativeCommand> commands;
}
And my commands all derive from the abstract class "NarrativeCommand", like this:
[System.Serializable]
public abstract class NarrativeCommand{
public abstract void execute();
public abstract string GetCommandName();
}
[System.Serializable]
public class NarrativeDebugLogCommand : NarrativeCommand{
public string message;
public override void execute (){
Debug.log(message);
}
public override string GetCommandName (){
return "DebugLog Command";
}
}
The problem is that I can't have a polymorphic List in Unity to hold many different events derived from the NarrativeCommand base class.
I tried ReorderableLists, but I'm not sure how it could work with a polymorphic list like mine. Also, maybe my approach to this is completely wrong, as well. Could it be that building a custom inspector solve this problem and, if so, where should I start?