What are extensions?

Extensions (feature introduced in Mad Level Manager 2.0.0) is an easy way to define extra scene(s) that should be loaded before, or/and after a level. You can define an extension once and assign it to any number of levels.

Here’s a simple example of how the extension may work:

Before and After scenes are scenes defined in a extension, but Level is a variable. This means that when you assign an extension to all your levels, when entering a level first you will see Before scene, then Level scene, finally After scene. Of course it is up to you if there is a Before or After. An extension can consist only of the scene that is before, or the scene that is after.

Extensions in real-life

So, what extensions can be used for? The simplest possible extension is a loading screen. The loading screen can be a scene set as Before. The only thing it will do is displaying a loading message. We will get to that example a little later.

More advanced example may consist of avatar select screen before each level, and scores screen after playing a level.

Editing extensions

Extensions can be edited using the tool called Extension Editor. Extensions are bound to a level configuration so an extension created for one configuration will not be available for the another.

You can open extension editor from the main menu Tools → Mad Level Manager → Extension Editor, or by using the Open Extension Editor button in level configuration inspector window:

Note that when you open Extension Editor form the main menu, it will edit extensions for currently active level configuration.

Extension Editor main window

Here’s what Extension Editor window looks like when no extensions are created. You can find there an information for which configuration extension are edited. By clicking on the blue button with configuration name you will be redirected to this configuration.

To create a new extension, click on the Create New Extension button.

A dialog will appear asking you for an extension name. We will create a loading screen extension in this example.

Extension Editor window looks now differently. You can now Remove the existing extension, and you’re able to Add scenes Before Level and After Level. This is the setup that I was talking about before.

In order to add a loading screen, we need to create a scene loaded before. Click on the left Add button.

An empty field will appear. You have to locate your scene file in the Project view, and drag in into this field. You can find an example loading a scene in Mad Level Manager / Assets / Examples / Scenes.

Now the extension is ready to use. You can close the Extension Editor window using the X button on the title bar, or the Close button.

Now when an extension is created, you can assign this extension to any level in your level configuration. Just select a level from the Level List and choose a newly created extension from the Extension list.

(1) Note that after creating extensions you may need to synchronize your configuration. Extension scenes may need to be added to your build configuration.

When extension is assigned to a level, a little star icon will appear next to the level icon. This is a marker of an extended level.

The API

There are some API additions to support extensions. First you need to know that when a level with an extension is loaded (using MadLevel.LoadLevelByName() for instance) and it has a before extension scene, then this scene will be loaded first.

Scenes that are extension scenes are required to use MadLevel API to push forward level loading procedure. For instance loading screen is obligated to load the level that is extended by it. This is how to do it.

MadLevel.hasExtension

This property will tell if we’re currently in an extension. When the level is extended, then this property will return true in before scenes, level, and after scenes.

MadLevel.CanContinue()

This method should be used only in an extension. It will return true only if the extension can continue (there’s a scene that is waiting to be loaded after this one), or is finished (this is the last scene of this extension).

MadLevel.Continue()

This method should be used only in an extension. When the extension can be continued, this method will load a next scene in order.

Wrapping it altogether

This is an example code of how it all can be used:

if (MadLevel.hasExtension && MadLevel.CanContinue()) {
	// if still in a extension, continue it
    MadLevel.Continue();
} else {
	// not in a extension, or end of extension - load next level
	if (MadLevel.HasNext(MadLevel.Type.Level)) {
    	MadLevel.LoadNext(MadLevel.Type.Level);
    }
    // MadLevel.LoadLevelByName("Any Level");
}

Working example

You can look at the working example of loading screen extension in Mad Level Manager package. Just load any example level select scene and hit the play button!