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

81 lines
1.8 KiB
C#

using System;
using UnityEngine;
namespace ZC
{
[AttributeUsage(AttributeTargets.Class)]
class UITypeAttribute : Attribute
{
public UIType UIType { get; set; }
public UITypeAttribute(UIType uiType)
{
UIType = uiType;
}
}
public abstract class UIBase : IUI
{
private bool _isPause;
private bool _isActive;
private GameObject _self;
private CanvasGroup _group;
public bool isPause => _isPause;
public bool isActive => _isActive;
public GameObject self => _self;
protected GameObjectBinding _uiGameObjectBinding;
public void SetGameObject(GameObject gameObject, bool isPause = true, bool isActive = false)
{
this._self = gameObject;
_uiGameObjectBinding = _self.GetComponent<GameObjectBinding>();
}
internal T GetValue<T>(string name) where T : Component
{
return _uiGameObjectBinding.GetValue<T>(name);
}
public virtual void Init()
{
_isPause = false;
_isActive = true;
}
public virtual void Open()
{
_self.SetActive(true);
}
public void Update(float dateTime)
{
if (_isPause) return;
}
public virtual void Close()
{
_self.SetActive(false);
}
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;
}
}
}