using System; using UnityEngine; public abstract class SingletonMonoBehaviour : MonoBehaviour, ISingletonMonoBehaviour where T : MonoBehaviour { public static T Instance { get { return UnitySingleton.GetSingleton(true, true); } } public virtual bool isSingletonObject { get { return true; } } public static T DoesInstanceExist() { return UnitySingleton.GetSingleton(false, false); } public static void ActivateSingletonInstance() { UnitySingleton.GetSingleton(true, true); } public static void SetSingletonAutoCreate(GameObject autoCreatePrefab) { UnitySingleton._autoCreatePrefab = autoCreatePrefab; } public static void SetSingletonType(Type type) { UnitySingleton._myType = type; } protected virtual void Awake() { if (isSingletonObject) { UnitySingleton._Awake(this as T); } } protected virtual void OnDestroy() { if (isSingletonObject) { UnitySingleton._Destroy(); } } }