89 lines
1.9 KiB
C#
89 lines
1.9 KiB
C#
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(Animator), typeof(CanvasGroup))]
|
|
public abstract class UIBase : MonoBehaviour
|
|
{
|
|
public bool IsShow => gameObject.activeSelf;
|
|
|
|
|
|
private const string panelFadeIn = "Panel In";
|
|
private const string panelFadeOut = "Panel Out";
|
|
private Animator _anim;
|
|
public Animator PanelAnimator { get => _anim; private set => _anim = value; }
|
|
|
|
public virtual void Init(object[] pageData)
|
|
{
|
|
if (_anim == null)
|
|
_anim = transform.GetComponent<Animator>();
|
|
}
|
|
|
|
public virtual void Destroy()
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public virtual void OnShow()
|
|
{
|
|
transform.GetComponent<RectTransform>().anchorMin = Vector2.zero;
|
|
transform.GetComponent<RectTransform>().anchorMax = Vector2.one;
|
|
transform.GetComponent<RectTransform>().offsetMin = Vector2.zero;
|
|
transform.GetComponent<RectTransform>().offsetMax = Vector2.zero;
|
|
|
|
gameObject.SetActive(true);
|
|
gameObject.GetComponent<CanvasGroup>().alpha = 0;
|
|
|
|
if (PanelAnimator == null)
|
|
PanelAnimator = GetComponent<Animator>();
|
|
PanelAnimator.enabled = true;
|
|
PanelAnimator.Play(panelFadeIn);
|
|
}
|
|
|
|
public virtual void OnEnter()
|
|
{
|
|
OnShow();
|
|
}
|
|
|
|
public virtual void OnPause()
|
|
{
|
|
OnHide();
|
|
}
|
|
|
|
public virtual void OnHide()
|
|
{
|
|
gameObject.SetActive(true);
|
|
_anim.Play(panelFadeOut);
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public virtual void HideDelay(float time)
|
|
{
|
|
if (!gameObject.activeSelf)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (time < 0)
|
|
{
|
|
OnHide();
|
|
return;
|
|
}
|
|
|
|
Invoke("Hide", time);
|
|
}
|
|
|
|
public virtual void OnResume()
|
|
{
|
|
|
|
}
|
|
|
|
public virtual void OnExit()
|
|
{
|
|
|
|
}
|
|
|
|
public virtual void MaskHide()
|
|
{
|
|
OnHide();
|
|
}
|
|
}
|