By now you probably have a game running, but it might be a bit monotonous. Always the same thing happening, maybe faster and faster, but not much change. That’s where scenarios come in! They’ll allow you to trigger scenario events (which can be anything you want) at certain times or based on a certain score.
This class is meant to be extended, and its Scenario() method overridden to describe your own level’s scenario. Do not add it directly in your game, it wouldn’t do much. This class is responsible for handling a list of scenario events, adding time or score events to it, and evaluating these scenario events at runtime, at the frequency specified in its inspector. Depending on how many events are in your scenario, this can be heavy on performance, so you might want to space the evaluations more. Additionnally, you can also choose to use the MMEventManager class to propagate events outside of this class.
Creating your own scenario
To create your own scenario, you need to create a new class that extends ScenarioManager.
Now all there is to do is override the Scenario() method to describe your own scenario. In it you can trigger events based on elapsed time, or the current score.
Adding a time based event is done like this:
// this will call the DoSomething() method after one second of game AddTimeEvent("00:00:01:000",()=> DoSomething());
You can also add score based events :
// this will call the DoSomething() method if the score reaches 150 AddScoreEvent(150f,()=> DoSomething());
In these, DoSomething() is a method of your choice, that can of course take arguments. Once you’ve added elements to your Scenario method, you need to add that new extended ScenarioManager to an object in your scene, and at runtime, your scenario events will be evaluated periodically, and if the conditions are met, the corresponding methods will be called. The methods you call can be in that same class, or you can call methods from other classes. You can even trigger events to catch them elsewhere!
There’s an example of that in the ExampleScenario class, or you can check out the AlbatrossScenario class, from the FlightOfTheAlbatross demo.