StaticSessionVariable
Like a static but cleanable.
// declaration
static public StaticSessionVariable<MyObject> MyStaticObject = new StaticSessionVariable<MyObject>();
...
// use with .Value
MyStaticObject.Value = new MyObject();
...
if (MyStaticObject.Value != null) {
Debug.Log(MyStaticObject.Value);
}
...
// destroy all static objects when you want
StaticSessionVariableContainer.Clear();
// or what you want
StaticSessionVariableContainer.Statics.RemoveAll(v => {
if (...)
v.ClearVar();
});
...
// Destroy Event
MyStaticObject.OnReset = () => {
Debug.Log("Argh, i'm dead");
};