TH1/Unity/Assets/Scripts/TH1_UI/Controller/Notify/UINotifyMomentController.cs
2026-02-26 02:14:18 +08:00

72 lines
2.1 KiB
C#

// 文件位置: Assets/Scripts/TH1_UI/Controller/Notify/UINotifyMomentController.cs
using TH1_Core.Events;
using TH1_UI.Controller.Base;
using TH1_UI.View.Notify;
using UnityEngine;
// 确保这里引用了View脚本的命名空间
namespace TH1_UI.Controller.Notify
{
/// <summary>
/// Moment通知界面的控制器。
/// 用于显示游戏中的特殊时刻/事件通知
/// </summary>
public class UINotifyMomentController : ViewController<UINotifyMomentView> // 泛型参数是对应的View脚本
{
/// <summary>
/// 【新增】一个空的构造函数,以满足 ViewControllerManager._CreateView 的 new() 泛型约束。
/// </summary>
public UINotifyMomentController() { }
protected override void RegisterEventCallback()
{
base.RegisterEventCallback();
if (WindowScript != null)
{
WindowScript.OnAutoClose += _OnAutoClose;
}
}
protected override void UnregisterEventCallback()
{
if (WindowScript != null)
{
WindowScript.OnAutoClose -= _OnAutoClose;
}
base.UnregisterEventCallback();
}
protected override void OnOpen()
{
base.OnOpen();
// 检查暂存的参数是否存在且类型正确
if (_openParameter is ShowUINotifyMoment evt)
{
// 使用接收到的数据设置UI内容
if (WindowScript != null)
{
WindowScript.SetContent(evt);
}
}
else
{
// 如果没有参数或参数类型不符,可以提供默认内容或打印警告
Debug.LogWarning("[UINotifyMomentController] Opened without valid parameters.");
if (WindowScript != null)
{
//WindowScript.SetContent("警告", "内容未提供");
}
}
}
void _OnAutoClose()
{
Close();
}
}
}