using UnityEngine; public abstract class UserBaseUI : MonoBehaviour where T : MonoBehaviour { private static T instance; private static object lockObj = new object(); public static T Instance { get { if (instance == null) { instance = (T)FindObjectOfType(typeof(T)); if (instance == null) { lock (lockObj) { if (instance == null) { GameObject singleton = new GameObject(); instance = singleton.AddComponent(); singleton.name = "(Singleton) " + typeof(T).Name; DontDestroyOnLoad(singleton); } } } } return instance; } } // Start is called before the first frame update public virtual void Awake() { this.transform.parent = GameScene.Instance.transform; this.transform.localPosition = Vector3.zero; this.transform.localEulerAngles = Vector3.zero; this.transform.localScale = Vector3.one; GameScene.Instance.UIList.Add(Instance.gameObject); this.gameObject.SetActive(false); } public virtual void show() { int ct =GameScene.Instance.UIList.Count; for (int i = 0; i < ct; i++) { GameScene.Instance.UIList[i].gameObject.SetActive(false); } this.gameObject.SetActive(true); } public virtual void hide() { } }