Browse Source

Add ability to auto-create `Singleton`

Add an optional parameter that allows to auto-spawn
`Singleton` with `GetInstance()` call.
develop
Anton Tarasenko 4 years ago
parent
commit
e3f3296c2d
  1. 13
      sources/Core/Singleton.uc

13
sources/Core/Singleton.uc

@ -32,12 +32,19 @@ var private Singleton activeInstance;
// Only a default value is ever used.
var protected bool blockSpawning;
public final static function Singleton GetInstance()
public final static function Singleton GetInstance(optional bool spawnIfMissing)
{
if (default.activeInstance != none && default.activeInstance.bPendingDelete)
return none;
local bool instanceExists;
instanceExists = default.activeInstance != none
&& !default.activeInstance.bPendingDelete;
if (instanceExists) {
return default.activeInstance;
}
if (spawnIfMissing) {
return class'Acedia'.static.GetInstance().Spawn(default.class);
}
return none;
}
public final static function bool IsSingletonCreationBlocked()
{

Loading…
Cancel
Save