Framework_YooAsset_HybridCLR/Assets/DemoGame/GameScript/Hotfix/UI/UIBase.cs

71 lines
1.6 KiB
C#
Raw Normal View History

2024-11-12 16:57:51 +08:00
using UnityEngine;
2024-07-19 10:51:48 +08:00
namespace ZC
{
2024-11-12 16:57:51 +08:00
public abstract class UIBase : MonoBehaviour, IUI
2024-07-19 10:51:48 +08:00
{
private bool _isPause;
private bool _isActive;
private CanvasGroup _group;
2024-11-12 16:57:51 +08:00
private GameObjectBinding _uiGameObjectBinding;
2024-07-19 10:51:48 +08:00
public bool isPause => _isPause;
public bool isActive => _isActive;
2024-11-12 16:57:51 +08:00
public GameObject self => gameObject;
public GameObjectBinding uiGameObjectBinding => _uiGameObjectBinding;
private void Awake()
{
_group = GetComponent<CanvasGroup>();
_uiGameObjectBinding = GetComponent<GameObjectBinding>();
}
2024-07-19 10:51:48 +08:00
2024-11-12 16:57:51 +08:00
internal T GetValue<T>(string name) where T : Component
2024-07-19 10:51:48 +08:00
{
2024-11-12 16:57:51 +08:00
return _uiGameObjectBinding.GetValue<T>(name);
2024-07-19 10:51:48 +08:00
}
2024-11-12 16:57:51 +08:00
public virtual void OnInit()
2024-07-19 10:51:48 +08:00
{
_isPause = false;
_isActive = true;
}
2024-11-12 16:57:51 +08:00
public virtual void OnOpen()
2024-07-19 10:51:48 +08:00
{
2024-11-12 16:57:51 +08:00
gameObject.SetActive(true);
2024-07-19 10:51:48 +08:00
}
2024-11-12 16:57:51 +08:00
public void OnUpdate(float dateTime)
2024-07-19 10:51:48 +08:00
{
if (_isPause) return;
}
2024-11-12 16:57:51 +08:00
public virtual void OnClose()
2024-07-19 10:51:48 +08:00
{
2024-11-12 16:57:51 +08:00
gameObject.SetActive(false);
2024-07-19 10:51:48 +08:00
}
2024-11-12 16:57:51 +08:00
public virtual void OnPause()
2024-07-19 10:51:48 +08:00
{
_isPause = true;
_group.interactable = false;
}
2024-11-12 16:57:51 +08:00
public virtual void OnResume()
2024-07-19 10:51:48 +08:00
{
_isPause = false;
_group.interactable = true;
}
2024-11-12 16:57:51 +08:00
public virtual void OnDispose()
2024-07-19 10:51:48 +08:00
{
_isActive = false;
_isPause = true;
2024-11-12 16:57:51 +08:00
GameObject.Destroy(this.gameObject);
2024-07-19 10:51:48 +08:00
}
}
}