89 lines
2.3 KiB
C#
89 lines
2.3 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using DG.Tweening;
|
||
using System.Threading.Tasks;
|
||
|
||
public class BaseUI :Base
|
||
{
|
||
[Header("父类自动的panel,按需要给,在生成的时候自动有动画")]
|
||
public GameObject _panel;
|
||
|
||
public List<Button> BTNs = new List<Button>();
|
||
public virtual async Task showPanel(GameObject panel)
|
||
{
|
||
if (panel == null)
|
||
{
|
||
Debug.LogError("panel==null");
|
||
return;
|
||
}
|
||
panel.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
|
||
panel.transform.DOScale(1f, 0.5f);
|
||
await Task.Delay(500);
|
||
}
|
||
|
||
public void addEventPopUp(string Details, float time = 5f)//添加弹窗
|
||
{
|
||
GameObject prefab = Resources.Load<GameObject>("base/EventPopUp");
|
||
prefab.GetComponent<EventPopUp>().time = time;
|
||
Canvas canvas = GetComponentInParent<Canvas>();
|
||
prefab.GetComponent<EventPopUp>().text = Details;
|
||
Instantiate(prefab, canvas.transform);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 注册按钮并设置响应事件
|
||
/// </summary>
|
||
/// <param name="btn">按钮</param>
|
||
/// <param name="action">事件</param>
|
||
public void RegisterButton(Button btn, UnityEngine.Events.UnityAction action)
|
||
{
|
||
if (btn != null && action != null)
|
||
{
|
||
btn.onClick.AddListener(action);
|
||
BTNs.Add(btn); // 将按钮加入到按钮组
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("Button or action is null!");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 注销按钮响应事件
|
||
/// </summary>
|
||
/// <param name="btn">按钮</param>
|
||
/// <param name="action">事件</param>
|
||
public void UnregisterButton(Button btn, UnityEngine.Events.UnityAction action)
|
||
{
|
||
if (btn != null && action != null)
|
||
{
|
||
btn.onClick.RemoveListener(action);
|
||
BTNs.Remove(btn); // 从按钮组中移除按钮
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 注销所有按钮的响应事件并清空按钮组
|
||
/// </summary>
|
||
public void UnregisterAllButtons()
|
||
{
|
||
foreach (Button btn in BTNs)
|
||
{
|
||
if (btn != null)
|
||
{
|
||
// 取消所有事件监听
|
||
btn.onClick.RemoveAllListeners();
|
||
}
|
||
}
|
||
|
||
// 清空按钮组
|
||
BTNs.Clear();
|
||
}
|
||
|
||
|
||
//public
|
||
}
|