83 lines
1.9 KiB
C#
83 lines
1.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace HK
|
|
{
|
|
[RequireComponent(typeof(CanvasGroup))]
|
|
public abstract class UIBase : MonoBehaviour, IUI
|
|
{
|
|
[SerializeField] private bool isAutoHide = false;
|
|
private bool _isPause;
|
|
private bool _isActive;
|
|
private CanvasGroup _group;
|
|
private GameObjectBinding _uiGameObjectBinding;
|
|
|
|
public bool isPause => _isPause;
|
|
|
|
public bool isActive => _isActive;
|
|
|
|
public Transform self => gameObject.transform;
|
|
|
|
public GameObjectBinding uiGameObjectBinding => _uiGameObjectBinding;
|
|
|
|
private void Awake()
|
|
{
|
|
_group = GetComponent<CanvasGroup>();
|
|
_uiGameObjectBinding = GetComponent<GameObjectBinding>();
|
|
OnInit();
|
|
}
|
|
|
|
internal T GetValue<T>(string name) where T : Component
|
|
{
|
|
return _uiGameObjectBinding.GetValue<T>(name);
|
|
}
|
|
|
|
public virtual void OnInit()
|
|
{
|
|
_isPause = false;
|
|
_isActive = !isAutoHide;
|
|
_group.alpha = isAutoHide ? 0 : 1;
|
|
}
|
|
|
|
public virtual void OnOpen()
|
|
{
|
|
_group.alpha = 1;
|
|
_group.interactable = true;
|
|
}
|
|
|
|
public void OnUpdate(float dateTime)
|
|
{
|
|
if (_isPause) return;
|
|
}
|
|
|
|
public virtual void OnClose()
|
|
{
|
|
_group.alpha = 0;
|
|
_group.interactable = false;
|
|
}
|
|
|
|
public virtual void OnPause()
|
|
{
|
|
_isPause = true;
|
|
_group.interactable = false;
|
|
}
|
|
|
|
public virtual void OnResume()
|
|
{
|
|
_isPause = false;
|
|
_group.interactable = true;
|
|
}
|
|
|
|
public virtual void OnDispose()
|
|
{
|
|
if (gameObject.activeSelf)
|
|
{
|
|
OnClose();
|
|
}
|
|
|
|
_isActive = false;
|
|
_isPause = true;
|
|
GameObject.Destroy(this.gameObject);
|
|
}
|
|
}
|
|
} |