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

91 lines
1.9 KiB
C#
Raw Normal View History

2024-10-24 16:16:57 +08:00
using System;
using UnityEngine;
namespace ZC
{
[AttributeUsage(AttributeTargets.Class)]
2024-10-26 23:50:18 +08:00
class UITypeAttribute : Attribute
2024-10-24 16:16:57 +08:00
{
public UIType UIType { get; set; }
public UITypeAttribute(UIType uiType)
{
UIType = uiType;
}
}
2024-11-07 23:51:24 +08:00
public abstract class UIBase : MonoBehaviour, IUI
2024-10-24 16:16:57 +08:00
{
private bool _isPause;
private bool _isActive;
private CanvasGroup _group;
public bool isPause => _isPause;
public bool isActive => _isActive;
2024-11-07 23:51:24 +08:00
public GameObject self => this.gameObject;
2024-10-26 23:50:18 +08:00
protected GameObjectBinding _uiGameObjectBinding;
2024-10-24 16:16:57 +08:00
2024-11-07 23:51:24 +08:00
#region Mono
private void Awake()
2024-10-24 16:16:57 +08:00
{
2024-11-07 23:51:24 +08:00
_isPause = true;
_isActive = false;
_uiGameObjectBinding = GetComponent<GameObjectBinding>();
Init();
2024-10-24 16:16:57 +08:00
}
2024-11-07 23:51:24 +08:00
private void OnDestroy()
{
Dispose();
}
#endregion
2024-11-07 22:49:10 +08:00
internal T GetValue<T>(string name) where T : Component
{
return _uiGameObjectBinding.GetValue<T>(name);
}
2024-10-24 16:16:57 +08:00
public virtual void Init()
{
_isPause = false;
_isActive = true;
}
public virtual void Open()
{
2024-11-07 23:51:24 +08:00
transform.localScale = Vector3.one;
2024-10-24 16:16:57 +08:00
}
2024-11-07 23:51:24 +08:00
public virtual void OnUpdate(float dateTime)
2024-10-24 16:16:57 +08:00
{
if (_isPause) return;
}
public virtual void Close()
{
2024-11-07 23:51:24 +08:00
transform.localScale = Vector3.zero;
2024-10-24 16:16:57 +08:00
}
public virtual void Pause()
{
_isPause = true;
_group.interactable = false;
}
public virtual void Resume()
{
_isPause = false;
_group.interactable = true;
}
public virtual void Dispose()
{
_isActive = false;
_isPause = true;
}
}
}