using UnityEngine; using UnityEngine.Events; /// /// 面板基类 /// public class UIBaseClass : MonoBehaviour { /// /// 关闭回调 /// private UnityAction hideCallback; /// /// 节点画布组 /// private CanvasGroup nodeCG; /// /// 动效动画状态机 /// protected Animation showHideAnimation; /// /// 动效动画状态机 /// protected Animator showHideAnimator; protected virtual void Awake() { Init(); } /// /// 打开 /// public virtual void OnShow() { } /// /// 关闭 /// public virtual void OnHide() { } /// /// 删除 /// public virtual void OnDelete() { } /// /// 初始化 /// private void Init() { nodeCG = transform.Find("Node").GetComponent(); GetComponent().worldCamera=UIManager.Instance.uICamera; if (transform.TryGetComponent(out Animation animation)) { this.showHideAnimation = animation; } if (transform.TryGetComponent(out Animator animator)) { this.showHideAnimator = animator; } } /// /// 全部失效或开启 /// public void AllLapseInitiate(bool isAllLapse) { nodeCG.interactable = isAllLapse; } /// /// 关闭自己 /// protected void HideMe() { UIManager.Instance.HideUI(this.name); } /// /// 删除自己 /// protected void DeleteMe() { UIManager.Instance.DeleteUI(this.name); } /// /// 打开面板动画 /// public virtual void ShowPanelAnimation() { if (showHideAnimation != null) { showHideAnimation.Play("ShowUI"); } if(showHideAnimator!=null) { showHideAnimator.Play("ShowUI"); } } /// /// 关闭面板 /// /// 关闭后干什么事 public virtual void HidePanel(UnityAction hideCallback) { this.hideCallback= hideCallback; if (showHideAnimation == null&&showHideAnimator==null) { this.hideCallback?.Invoke(); } else { if (showHideAnimation != null) { showHideAnimation.Play("HideUI"); } if(showHideAnimator!=null) { showHideAnimator.Play("HideUI"); } } } /// /// 关闭回调 /// public void HideCallback() { this.hideCallback?.Invoke(); } }