using System; using UnityEngine; namespace SchoenLogger { public abstract class Singleton : MonoBehaviour where T : MonoBehaviour { private static readonly Lazy LazyInstance = new Lazy(CreateSingleton); public static T Instance => LazyInstance.Value; private static T CreateSingleton() { var ownerObject = new GameObject($"{typeof(T).Name} (singleton)"); var instance = ownerObject.AddComponent(); DontDestroyOnLoad(ownerObject); return instance; } } }