Files
aibis-dream/Assets/Scripts/Utility/Singleton.cs
T
2024-09-13 19:39:22 +00:00

32 lines
643 B
C#

using UnityEngine;
namespace AibisDream
{
public class Singleton<T> : MonoBehaviour where T : Singleton<T>
{
public static T Instance { get; private set; }
protected virtual void Awake()
{
if (Instance != null)
{
Destroy(gameObject);
}
else
{
Instance = (T)this;
}
}
public static bool IsInitialized => Instance != null;
protected virtual void OnDestroy()
{
if (Instance == this)
{
Instance = null;
}
}
}
}