Globals pattern implementation (service locator).
Tested on unity 2020.3 (not dependent on it) and contains assembly definition for compiling to separate assembly file for performance reason.
This repository can be installed as unity module directly from git url. In this way new line should be added to Packages/manifest.json
:
"com.leopotam.globals": "https://github.com/Leopotam/globals.git",
By default last released version will be used. If you need trunk / developing version then develop
name of branch should be added after hash:
"com.leopotam.globals": "https://github.com/Leopotam/globals.git#develop",
If you can't / don't want to use unity modules, code can be downloaded as sources archive from Releases
page.
Service locator pattern support.
class PlayerSession {
public int Rank;
}
// init instance.
Service<PlayerSession>.Set (new PlayerSession ());
// ...
// request instance.
Service<PlayerSession>.Get ().Rank = 10;
// ...
// cleanup.
Service<PlayerSession>.Set (null);
class PlayerSession {
public int Rank;
}
// request instance. if not exists - will be created through default constructor.
Service<PlayerSession>.Get(true).Rank = 10;
// ...
// cleanup.
Service<PlayerSession>.Set (null);
The software is released under the terms of the MIT license.
No personal support or any guarantees.