using System; using UnityEngine; public abstract class UIView : MonoBehaviour { //UIView名字 public string ViewName { get; set; } public abstract UIViewType ViewType { get; } public Action OnShow; public Action OnHide; public int Z_Index { get { return transform.GetSiblingIndex(); } set { transform.SetSiblingIndex(value); } } public virtual void Show() { //transform.GetSiblingIndex //没有显示的情况下才显示 if (!gameObject.activeSelf) { gameObject.SetActive(true); if (OnShow != null) { OnShow(this); } // 设置层级到最上层 transform.SetAsLastSibling(); // 刷新 Refresh(); } } public virtual void Hide() { //显示的情况下才隐藏 if (gameObject!=null&&gameObject.activeSelf) { gameObject.SetActive(false); if (OnHide != null) { OnHide(this); } } } public virtual void Refresh() { } //页面销毁是通知UIManager自己销毁了 public virtual void OnDestroy() { OnShow = null; OnHide = null; UIManager.DestroyView(ViewName); } } public enum UIViewType { Normal, Popup }