using System.Collections; using System.Collections.Generic; using UnityEngine; public class MonoSingleton : MonoBehaviour where T : MonoSingleton { public static T Instance { get; private set; } [Header("Singleton Settings")] public bool SetSingletonOnAwake; public bool isPersistant; protected virtual void Awake() { if (SetSingletonOnAwake) SetAsSingleton(); } private void SetAsSingleton() { if (Instance != null && Instance != this) Destroy(this); else Instance = (T)this; if (isPersistant) DontDestroyOnLoad(transform.root); } } public class Singleton where T : Singleton, new() { private static T instance; public static T Instance { get { if (instance == null) instance = new T(); return instance; } private set { } } }