using System; using UnityEngine; using UnityEngine.Serialization; using UnityEngine.UI; namespace TyphoonUI { /// /// UI页面 /// public abstract class UIPanel : UIComponent { /// /// 根视图 /// public CanvasGroup RootView; /// /// 面板脚本名 /// public string PanelScript { get; set; } /// /// 是否激活 /// public bool IsShow = false; /// /// 打开页面传递的数据 /// public object DataOpen = null; /// /// 关闭页面传递的数据 /// public object DataClose = null; /// /// 触发多语言变化 /// public bool TriggerLanguage { get; set; } = true; internal override void Attach(UIObject view) { RootView = view.gameObject.GetComponent(); if (RootView == null) { RootView = view.gameObject.AddComponent(); } //TODO// base.Attach(view); } /// /// 打开面板 /// /// 传入的数据 public virtual void Open(object data = null) { if (IsShow) { return; } DataOpen = data; IsShow = true; BeforeShow(); UpdateStaticLocalizeInfo(); OnShowing(); AfterShow(); OnShowDone(); //触发弹窗队列 // UIManager.OperationQueue.Enqueue(BeforeShow).Enqueue(OnShowing).Enqueue(AfterShow).Enqueue(OnShowDone) // .Run(); } /// /// 关闭面板 /// /// 传入的数据 public virtual void Close(object data = null) { if (!IsShow) { return; } DataClose = data; IsShow = false; BeforeHide(); OnHiding(); AfterHide(); OnHideDone(); // //触发关闭队列 // UIManager.OperationQueue.Enqueue(BeforeHide).Enqueue(OnHiding).Enqueue(AfterHide).Enqueue(OnHideDone) // .Run(); } /// /// 尝试更新静态文本 /// private void UpdateStaticLocalizeInfo() { if (TriggerLanguage) { LoadStaticLocalizeInfo(); TriggerLanguage = false; } } /// /// 加载静态本地化信息 /// protected virtual void LoadStaticLocalizeInfo() { } /// /// 多语言发生变化时 /// internal virtual void OnLanguageChanged() { TriggerLanguage = true; } /// /// 展示前 /// protected virtual void BeforeShow() { } /// /// 展示中 /// protected virtual void OnShowing() { RootView.alpha = 1; RootView.blocksRaycasts = true; } /// /// 显示后 /// protected virtual void AfterShow() { } /// /// 显示完毕 /// protected virtual void OnShowDone() { } /// /// 隐藏前 /// protected virtual void BeforeHide() { } /// /// 隐藏中 /// protected virtual void OnHiding() { RootView.alpha = 0; RootView.blocksRaycasts = false; } /// /// 隐藏后 /// protected virtual void AfterHide() { } /// /// 隐藏完毕 /// protected virtual void OnHideDone() { //TODO//触发消息,页面关闭 } /// /// 销毁 /// public virtual void Destroy() { UIManger.DestroyPanel(PanelScript); } /// /// 按钮点击事件 /// protected virtual void OnBtnClick(Button btn) { } } }