using UnityEngine; namespace CTS { public class CTSSingleton : MonoBehaviour where T : MonoBehaviour { private static T _instance; private static object _lock = new object(); public static T Instance { get { lock (_lock) { if (_instance == null) { GameObject gameObject = new GameObject(); _instance = gameObject.AddComponent(); gameObject.name = typeof(T).ToString(); gameObject.hideFlags = HideFlags.HideAndDontSave; if (Application.isPlaying) { Object.DontDestroyOnLoad(gameObject); } } return _instance; } } } } }