using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.UI; namespace CG.Framework { public class UIBase : MonoBehaviour { protected virtual void Awake() { if (name.Contains("(Clone)")) { name = name.Substring(0, name.Length - 7); } Transform[] childs = transform.GetComponentsInChildren(true); foreach (Transform tf in childs) { if (tf.name.EndsWith("_N")) { UIBehaviours tfBehav =tf.gameObject.AddComponent(); tfBehav.AwakeCustom(); } } UI_Manage.Instance.RegisterUIPanel(name, gameObject); } protected GameObject GetWedage(string wedageName) { return UI_Manage.Instance.GetWedget(name, wedageName); } public void SetText(string wedageName, string msg) { GameObject obj = GetWedage(wedageName); obj.GetComponent().SetText(msg); } #region 事件监听 protected void AddEventListener(string wedageName, UIEventType type, UnityAction callback) { GameObject obj = GetWedage(wedageName); obj.GetComponent().AddEventListener(type, callback); } protected void AddEventListener(string wedageName, UIEventType type, UnityAction callback) { GameObject obj = GetWedage(wedageName); obj.GetComponent().AddEventListener(type, callback); } protected void AddEventListener(string wedageName, UIEventType type, UnityAction callback) { GameObject obj = GetWedage(wedageName); obj.GetComponent().AddEventListener(type, callback); } protected void AddEventListener(string wedageName, UIEventType type, UnityAction callback) { GameObject obj = GetWedage(wedageName); obj.GetComponent().AddEventListener(type, callback); } protected void AddEventListener(string wedageName, UIEventType type, UnityAction callback) { GameObject obj = GetWedage(wedageName); obj.GetComponent().AddEventListener(type, callback); } #endregion protected virtual void OnDestroy() { UI_Manage.Instance.UnRegisterAllWedgeInPanel(name); UI_Manage.Instance.UnRegisterUIPanel(name); } } }