One of the most powerful part of Mad Level Manager is how it can manage level loading. You defined earlier your levels using the Configurator. Now you can take fully advantage of it.

Common Workflow

There is only one class that you need to know about: MadLevel (click to check out the detailed class documentation). This class is defined in MadLevelManager namespace so don’t forget to put this at the top of your C# file:

using MadLevelManager;

Loading the first level of your game

Let’s say that you’ve named your first level as First Level. Loading this level is quite straightforward:

MadLevel.LoadLevelByName("First Level");

It will work but you need to know the level name here. If this is first level of type Level in your level configuration, then you can make it much better:

MadLevel.LoadFirst(MadLevel.Type.Level);

Now you don’t need to know the name of first level. This code will work in any projects with level configuration and with at least one level defined. How cool is that?

Loading next level

Player has just finished his level and wants to go to the next one. No problem at all!

MadLevel.LoadNext(MadLevel.Type.Level);

LoadNext looks for next level with type Level and loads it. It is just that easy! But what if this is the last level of your game? Then you can do the following:

if (MadLevel.HasNext(MadLevel.Type.Level)) {
    MadLevel.LoadNext(MadLevel.Type.Level);
} else {
    MadLevel.LoadLevelByName("Game Finished");
}

This code will check if there’s any other level that can be loaded. If not, Game Finished level is loaded which should be of type Other. In this way you complete setup of your level workflow!

Going back

Do you want to go back to the previous level? LoadNext() has its opposite:

MadLevel.LoadPrevious(MadLevel.Type.Level);

Maybe you want to restart your whole game? Then you want to load the very first level of any type that is defined in your configuration. Here’s how to do it:

MadLevel.LoadFirst();

Which configuration is active?

You can easily get the current configuration name:

var configurationName = MadLevel.activeConfiguration.name;

In this way you can change your game behavior in the runtime based on the configuration name. Let’s assume that you have two configurations named like this:

  • My Game
  • My Game Demo
It’s good practice to call your configurations with the same convention. Using ‘Demo’ postfix for demo configurations will help you a lot!

Now you can create a condition:

var configurationName = MadLevel.activeConfiguration.name;

if (configurationName.EndsWith("Demo")) {
	Debug.Log("This is a demo version");
} else {
	Debug.Log("This is a full version");
}

More info

You probably will be interested in looking at full MadLevel API and maybe MadLevelConfiguration API which is available as field MadLevel.activeConfiguration.