using UnityEngine; namespace UFS3.Management { public class SceneSingleton : MonoBehaviour where T : MonoBehaviour { private static T _instance; private static readonly object _lock = new object(); public static T Instance { get { if (_instance == null) { lock (_lock) { if (_instance == null) { _instance = Object.FindObjectOfType(); if (_instance == null) { _instance = new GameObject(typeof(T).Name).AddComponent(); } } } } return _instance; } } protected virtual void Awake() { if (_instance != null && _instance != this) { Debug.Log("Copy of Singleton Instance already exists, destroying new one."); Object.Destroy(base.gameObject); } else { _instance = this as T; } } } }