using AibisDream.Kit; using TMPro; using UnityEngine; using UnityEngine.UI; namespace AibisDream.UI { public class InfoPanel : MonoBehaviour, IUIPanel { [SerializeField] private DemoTimer demoTimer; [SerializeField] private GameObject loading; [SerializeField] private GameObject messageBox; private IActionController _messageActionController; public void SetTimerActive(bool isOpen) { demoTimer.gameObject.SetActive(isOpen); } public void SetTimerDuration(int time) { demoTimer.totalTimeInSeconds = time; } public void ShowLoading() { loading?.SetActive(true); } public void HideLoading() { loading?.SetActive(false); } /// /// 显示消息,并在指定时间后自动隐藏 /// /// 要显示的消息内容 /// 显示持续时间(秒),默认2秒 public void ShowMessage(string message, float duration = 2f) { // 如果之前有消息正在显示,先取消之前的延时动作 if (_messageActionController != null) { _messageActionController.Deinit(); _messageActionController = null; } if (messageBox != null) { messageBox.GetComponentInChildren().text = message; messageBox.SetActive(true); // 使用ActionKit创建延时动作 _messageActionController = ActionKit.Delay(duration, () => { HideMessage(); _messageActionController = null; }).Start(this); } } public void HideMessage() { // 如果消息正在显示,取消延时动作 if (_messageActionController != null) { _messageActionController.Deinit(); _messageActionController = null; } if (messageBox != null) { messageBox.SetActive(false); } } public void Show() { gameObject.SetActive(true); } public void Hide() { gameObject.SetActive(false); } public bool IsOpen => gameObject.activeSelf; public bool IsCloseable => false; } }