75 lines
2.6 KiB
C#
Raw Normal View History

2025-01-02 12:15:45 +08:00
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<Transform>(true);
foreach (Transform tf in childs)
{
if (tf.name.EndsWith("_N"))
{
UIBehaviours tfBehav =tf.gameObject.AddComponent<UIBehaviours>();
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<UIBehaviours>().SetText(msg);
}
#region
protected void AddEventListener(string wedageName, UIEventType type, UnityAction callback)
{
GameObject obj = GetWedage(wedageName);
obj.GetComponent<UIBehaviours>().AddEventListener(type, callback);
}
protected void AddEventListener(string wedageName, UIEventType type, UnityAction<bool> callback)
{
GameObject obj = GetWedage(wedageName);
obj.GetComponent<UIBehaviours>().AddEventListener(type, callback);
}
protected void AddEventListener(string wedageName, UIEventType type, UnityAction<string> callback)
{
GameObject obj = GetWedage(wedageName);
obj.GetComponent<UIBehaviours>().AddEventListener(type, callback);
}
protected void AddEventListener(string wedageName, UIEventType type, UnityAction<int> callback)
{
GameObject obj = GetWedage(wedageName);
obj.GetComponent<UIBehaviours>().AddEventListener(type, callback);
}
protected void AddEventListener(string wedageName, UIEventType type, UnityAction<float> callback)
{
GameObject obj = GetWedage(wedageName);
obj.GetComponent<UIBehaviours>().AddEventListener(type, callback);
}
#endregion
protected virtual void OnDestroy()
{
UI_Manage.Instance.UnRegisterAllWedgeInPanel(name);
UI_Manage.Instance.UnRegisterUIPanel(name);
}
}
}