123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using UnityEngine;
- public abstract class UserBaseUI<T> : 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<T>();
- 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()
- {
- }
- }
|