mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
further cleanup of repo
This commit is contained in:
parent
4f8dcb0cd0
commit
323eb92f2e
140 changed files with 1 additions and 2430 deletions
|
@ -1,44 +0,0 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace NAK.CVRLuaToolsExtension;
|
||||
|
||||
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
private static T _instance;
|
||||
private static readonly object _lock = new();
|
||||
private static bool _isShuttingDown;
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_isShuttingDown)
|
||||
{
|
||||
Debug.LogWarning($"[Singleton] Instance of {typeof(T)} already destroyed. Returning null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
if (_instance != null) return _instance;
|
||||
_instance = (T)FindObjectOfType(typeof(T));
|
||||
if (_instance != null) return _instance;
|
||||
GameObject singletonObject = new($"{typeof(T).Name} (Singleton)");
|
||||
_instance = singletonObject.AddComponent<T>();
|
||||
DontDestroyOnLoad(singletonObject);
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
_isShuttingDown = true;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_instance == this)
|
||||
_isShuttingDown = true;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue