Files
Continentis/Assets/Scripts/ScriptExtensions/General/Singleton.cs
SoulliesOfficial 9b1b5ca93f initial
2025-10-03 00:02:43 -04:00

36 lines
866 B
C#

using Sirenix.OdinInspector;
using UnityEngine;
namespace SoulliesFramework.General
{
public class Singleton<T> : SerializedMonoBehaviour where T : SerializedMonoBehaviour
{
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;
}
}
}
}