Files
Cielonos/Assets/Scripts/SLSUtilities/General/Singleton.cs
SoulliesOfficial 9a9e48f8a5
2026-06-27 12:52:03 -04:00

36 lines
865 B
C#

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 ?? FindFirstObjectByType<T>();
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;
}
}
}
}