using System; using Framework; using PhxhSDK; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using UnityEngine.Serialization; using Object = System.Object; public abstract class UIWindow : MonoBehaviour { private string mWindowName; // 是否播放默认的打开对话框的声音 public bool isPlayDefaultOpenAudio = true; // 是否播放默认的关闭对话框的声音 public bool isPlayDefaultCloseAudio = true; public string WindowName { set { mWindowName = value; } get { return mWindowName; } } [HideInInspector] public UIWindowType m_WindowType; [HideInInspector] public UIWindowLayer uiWindowLayer; [HideInInspector] public bool isOpen = false; void Awake() { //todo : it is only a i18n check, remove it.. // Text[] labels = this.transform.GetComponentsInChildren(true); // foreach (Text label in labels) // { //DebugUtil.Log("find label : /"+label.text+"/"); // if (LocalizationManager.Instance.TryGetLocalizedString(label.text.Trim(), out var result)) // { // label.text = result; // } // else // { // if (Regex.IsMatch(label.text, "[a-zA-Z]+")) // { // DebugUtil.LogError($"[{name}:{label.name}] cannot get i18n, text:[{label.text}] " + // $"if it is a local text, use locale text pro instead and add i18n"); // } // } //label.text = LocalizationManager.Instance.GetLocalizedString(label.text.Trim()); //} OnAwake(); } public void OpenWindow() { Show(); OnOpenWindow(); if (isPlayDefaultOpenAudio) { //AudioManager3.Instance.PlaySound(""); } } public void OpenWindow(object data) { Show(); OnOpenWindow(data); if (isPlayDefaultOpenAudio) { //AudioManager3.Instance.PlaySound(""); } } public void CloseWindow(bool destroy = false) { OnCloseWindow(destroy); if (isPlayDefaultCloseAudio && isOpen) { //AudioManager3.Instance.PlaySound(""); } //Global.hideZhezhao(); if (destroy) { Destroy(); } else { Hide(); } } public void CloseSelf(bool destroy = true) { UIManager.Instance.CloseWindow(WindowName, destroy); } public bool OnBack() { //AudioManager.Instance.PlaySound(SfxNameConst.button_s); return UIManager.Instance.CloseWindow(mWindowName, true); } public void ReloadWindow() { Show(); OnReloadWindow(); } public void ReloadWindow(object data) { Show(); OnReloadWindow(data); } private void Show() { isOpen = true; if (gameObject == null) { DebugUtil.Log("UI已被销毁:{0}", WindowName); } else { gameObject.SetActive(true); } } private void Hide() { isOpen = false; gameObject.SetActive(false); } private void Destroy() { isOpen = false; Destroy(gameObject); AssetManager.Instance.Unload(string.Format(UIManager.UI_PREFAB_PATH, mWindowName)); } /// /// 打开界面时调用 /// /// protected virtual void OnOpenWindow(object data) { } protected virtual void OnOpenWindow() { } /// /// 关闭界面时调用 /// protected virtual void OnCloseWindow(bool destroy = false) { } /// /// 重新加载界面时调用 /// protected virtual void OnReloadWindow(object data) { } protected virtual void OnReloadWindow() { } /// /// 私有Awake方法,会在基类Awake执行后调用 /// public abstract void OnAwake(); public GameObject BindButton(string target, Action action, bool playAudio = true) { GameObject obj = transform.Find(target)?.gameObject; if (obj != null) { Button button = obj.GetComponent