// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖 using System; using FairyGUI; using UnityEngine; using NBC; using UIPanel = NBC.UIPanel; namespace NBF { public partial class MessageBox : UIPanel { private static string _confirmText; private static string _cancelText; private static string _title; private static string _content; private static Action _callback; private static int _style; public static void Show(string msg, Action callback, string title = "", int style = 0, string confirm = "", string cancel = "") { if (string.IsNullOrEmpty(title)) { title = "TEXT_NOTE"; } if (string.IsNullOrEmpty(confirm)) { confirm = "TEXT_CONFIRM"; } if (string.IsNullOrEmpty(cancel)) { cancel = "TEXT_CANCEL"; } _confirmText = confirm; _cancelText = cancel; _callback = callback; _content = msg; _title = title; _style = style; Show(); } protected override void OnInit() { this.AutoAddClick(OnClick); // HideAnim = this.HideCenterScaleBig; // ShowAnim = this.ShowCenterScaleBig; IsModal = true; IsDontBack = true; InputManager.OnUICanceled += OnUICanceled; } protected override void OnShow() { // TextTitle.SetLanguage(_title); BtnConfirm.SetLanguage(_confirmText); BtnCancel.SetLanguage(_cancelText); TextTitle.SetLanguage(_content); MessageStyle.selectedIndex = _style; } private void OnUICanceled(string action) { if (!IsShowing) return; if (!IsTop) return; if (action == InputDef.UI.Enter) { OnClick(BtnConfirm); } else if (action == InputDef.UI.Back) { OnClick(BtnCancel); } } protected override void OnDestroy() { base.OnDestroy(); InputManager.OnUICanceled -= OnUICanceled; } private void OnClick(GComponent btn) { _callback?.Invoke(btn == BtnConfirm); Hide(); } } }