This commit is contained in:
SoulliesOfficial
2026-03-14 02:30:26 -04:00
parent cf86f0ee51
commit aee62cd637
2041 changed files with 246771 additions and 129128 deletions

View File

@@ -0,0 +1,36 @@
using Sirenix.OdinInspector;
using UnityEngine;
namespace SLSUtilities.General
{
public class Singleton<T> : SerializedMonoBehaviour where T : MonoBehaviour
{
protected static T instance;
public static T Instance => instance == null ? FindFirstObjectByType<T>() : instance;
protected virtual void Awake()
{
Initialize(false);
}
protected virtual void Initialize(bool dontDestroy)
{
if (dontDestroy)
{
if (instance == null)
{
instance = this as T;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
else
{
instance = this as T;
}
}
}
}