using System.Collections; using System.Collections.Generic; using UnityEngine; using System; namespace Bansonic { /// /// 全局通知系统入口 /// 使用方式:gNotice.message.display("内容"); /// public static class gNotice { // --- 事件定义:用于通知 UI 层 --- /// /// 当任何通知被显示时触发 /// 参数1:类型前缀(如 [Info]) /// 参数2:消息内容 /// public static event Action OnNoticeDisplay; /// /// 当任何通知被中断显示时触发 /// public static event Action OnNoticeInterrupt; // --- 静态实例定义 (直接注入行为,无需枚举) --- /// 普通消息 public static readonly NoticeChannel message = new NoticeChannel("[Info]", Debug.Log); /// 建议 public static readonly NoticeChannel recommendation = new NoticeChannel("[Recommendation]", Debug.Log); /// 警告 public static readonly NoticeChannel warning = new NoticeChannel("[Warning]", Debug.LogWarning); /// 错误 public static readonly NoticeChannel error = new NoticeChannel("[Error]", Debug.LogError); /// 警报 public static readonly NoticeChannel alarm = new NoticeChannel("[Alarm]", Debug.LogWarning); // --- 内部核心实现 --- /// /// 通知通道类:封装了通用的 display 和 interrupt 逻辑 /// public class NoticeChannel { private readonly string _prefix; private readonly Action _logAction; /// /// 构造函数 /// /// 日志前缀,如 [Info] /// 具体的日志输出方法,如 Debug.Log internal NoticeChannel(string prefix, Action logAction) { _prefix = prefix; _logAction = logAction; } /// /// 显示消息 /// public void display(object message, float? waitTime = null, float? fadeTotalTime = null) { string content = message?.ToString() ?? "null"; content = LocalizationService.LocalizeLiteral(content); _logAction($"{_prefix} {content}"); // 触发 UI 事件 OnNoticeDisplay?.Invoke(_prefix, content, waitTime, fadeTotalTime); } /// /// 立即终止当前正在展示的全部警告prefab /// public void interrupt() { // 触发 UI 事件 OnNoticeInterrupt?.Invoke(); } } } }