Mad Level Manager save subsystem is using PlayerPrefs as its storage backend. It’s the easiest way of storing and loading data, but it has some drawbacks:

  • The data is not secured in any way (stored in plain text)
  • For WebPlayer there’s a data limit of 1 MB

For most cases these two issues are not so important. If the game is a single player game without online rankings, hacking the game is not a big issue for the developer. What’s more, WebPlayer will be no longer supported when HTML5 player is stable enough, and it won’t have this kind of limit.

Still there are cases when you may want to secure or simply have a better control over how your data is stored and loaded.

Changing the backend

To change your current backend, open Settings from the menu: Tools → Mad Level Manager → Settings. The settings file will be opened (or created if it doesn’t exist).

The default backend is the mentioned before PlayerPrefs-based backend. To change your current backend, just select a different one from the list.

Backends often have additional configuration fields. These can be Required or Optional based on how current backend is implemented. You have to fill Required fields or your backend will fail to initialize.

If you find yourself in trouble understanding what those fields are for, use the Open Documentation Page button.

Provided backends

Currently there are two (not including the default one) backends provided that are using 3rd-party tools. Backends can be used only after unpacking the backend code. These are stored inside separate unitypackage files in Mad Level Manager/Backends directory for not to cause compile errors for those users who do not own 3rd-party tools that these backedns are written for.

Easy Save 2 Backend

Easy Save 2 (Asset Store link) is a well known leading Save and Load solution for the Unity3D engine.

Easy Save 2 backend currently provides only basic offline-storage backend. Web storage backend is under development.

Anti-Cheat Toolkit Backend

Anti-Cheat Toolkit (Asset Store link) was created to help you protect your Unity3D applications from cheaters & hackers.

Anti-Cheat Backend is making heavy use of ObscuredPrefs feature.

Writing your own backend

It’s really simple to write your own backend. You can do it by:

Implementing IMadLevelProfileBackend interface

Implementing the IMadLevelProfileBackend interface is pretty simple. Interface documentation can be found here. Here’s how the default backend is implemented.

[DisplayedName("Default")]
public class DefaultBackend : IMadLevelProfileBackend {
    public void Start() {
        // do nothing
    }

    public string LoadProfile(string profileName) {
        return PlayerPrefs.GetString(profileName + "_" + KeyLevels, "");
    }

    public void SaveProfile(string profileName, string @value) {
        PlayerPrefs.SetString(profileName + "_" + KeyLevels, @value);
    }

    public void Flush() {
        PlayerPrefs.Save();
    }

    public bool CanWorkInEditMode() {
        return true;
    }
}

Each backend can have public fields. Public fields can be annotated with [Required] or [Optional] attributes:

[Required] public string path;
[Optional] public string tagPrefix;

These attributes will be displayed in the inspector similarly to how Unity3D properties are displayed. Currently supported types are string, int, float, bool, and enum.

When your backend is implemented and compiled without errors, you will be able to see it on the backend list without any further steps.

Implementing MadLevelProfileBufferedBackend abstract class

MadLevelProfileBufferedBackend is an abstract implementation of the interface above. It creates an abstraction layer between user save requests and the actual storage code by delaying its execution. Simply talking buffered backend is good for scenarios when saving your data may be an expensive operation.

When the game changes persistent data, the save timer will be invoked and the data stored in the memory for the time being. By default it will wait for 15 seconds for more data to come. Finally the Flush() method is executed, which should immediately save all the data to a persistent storage holder (e.g. hard drive).

Buffered backend is also aware of suspended application or shutdown events. It will Flush() the data immediately when these will occur.

Also from the buffered backend you have the access to the object called profileWatcher. The profile watcher is a MonoBehaviour that exists hidden on all your scenes and cannot be destroyed. It is a receiver of events mentioned before, but it can be used as a coroutine owner. For the example you can use it that way:

profileWatcher.StartCoroutine(DoSomethingInBackground());