using UnityEngine;
using UnityEngine.EventSystems;
public class UGUISlideBar : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
[SerializeField] private RectTransform FillRT;
[SerializeField] private TMPro.TextMeshProUGUI PercentTMP;
[SerializeField] private bool InitOnPointerUp = false;
private RectTransform rt;
private float MaxWidth;
private Camera uiCamera;
private bool checkable = false;
public System.Action OnValueChanged;
public bool Controlable { get; set; } = true;
/// Normalized Value. 0 ~ 1
public float Value
{
get
{
float result = Mathf.Clamp(FillRT.sizeDelta.x / MaxWidth, 0f, 1f);
return result;
}
set
{
FillRT.sizeDelta = new Vector2(Mathf.Clamp(value * MaxWidth, 0, MaxWidth), FillRT.sizeDelta.y);
if (PercentTMP != null)
PercentTMP.text = (FillRT.sizeDelta.x / MaxWidth * 100f).ToString("N1") + "%";
OnValueChanged?.Invoke();
}
}
private void Awake()
{
rt = this.GetComponent();
MaxWidth = rt.rect.width;
uiCamera = this.transform.root.Find("PopupCanvas").GetComponent