I'm trying to solve what seems to be (or should be) a very simple problem. I'd like to sequence several steps in a GameManager class with some time delay between them. In my case, I'd like to clear the screen of objects, then ask my UIManager class to display a "Starting Level" message for 3 seconds, then spawn all the objects I need. This sequence should be repeatable unless a event that the GameManager subscribed to is triggered.
I'm trying to do this in the most generic, flexible and elegant way I can find. This is not a technical, "whatever works" question. I can do this with coroutines. I can do this with the GameManager calling an Action delegate to which UIManager is subscribed, then make the UIManager call an event that the GameManager is subscribed to when the displaying is done. But all these solutions seems convoluted to me.
I've started a thread on Unity Answers with some example code about this, which has generated a small discussion. In posting here I am hoping to find some new ideas, maybe generic to C# and not specific to Unity, on how to sequence a chain of methods. How would you achieve this?
To make this clearer, imagine a more complex sequence inside a GameSequence method:
- Initialize variables (level, difficulty etc).
- When done, play an introductory animation to that level, which can be of varying lengths depending on the level.
- Show a "Get ready" message for 3 seconds.
- Spawn the level and let it play.
- If the level ends successfully, animate some sort of cutscene (which can be of any duration).
- If the level doesn't end successfully, trigger a GameOverManager or something to that effect.
I hope I'm being clear in my question. Thank you for your help.