Files
Cielonos/Assets/Scripts/SLSFramework/General/Singleton.cs

35 lines
812 B
C#
Raw Normal View History

2025-11-25 08:19:33 -05:00
using UnityEngine;
namespace SLSFramework.General
{
public class Singleton<T> : MonoBehaviour 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;
}
}
}
}