Files
Cielonos/Assets/Scripts/SLSFramework/General/Singleton.cs
SoulliesOfficial 33b1795c1f 更新
2026-01-03 18:19:39 -05:00

36 lines
851 B
C#

using Sirenix.OdinInspector;
using UnityEngine;
namespace SLSFramework.General
{
public class Singleton<T> : SerializedMonoBehaviour where T : MonoBehaviour
{
protected static T instance;
public static T Instance => 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;
}
}
}
}