using System; using UnityEngine.UI; namespace UnityEngine.Rendering.UI { /// /// DebugUIHandler for progress bar widget. /// public class DebugUIHandlerProgressBar : DebugUIHandlerWidget { /// Name of the progress bar. public Text nameLabel; /// Value of the progress bar. public Text valueLabel; /// Rectangle representing the progress bar. public RectTransform progressBarRect; DebugUI.ProgressBarValue m_Value; float m_Timer; /// /// OnEnable implementation. /// protected override void OnEnable() { m_Timer = 0f; } internal override void SetWidget(DebugUI.Widget widget) { base.SetWidget(widget); m_Value = CastWidget(); nameLabel.text = m_Value.displayName; UpdateValue(); } /// /// OnSelection implementation. /// /// True if the selection wrapped around. /// Previous widget. /// True if the selection is allowed. public override bool OnSelection(bool fromNext, DebugUIHandlerWidget previous) { nameLabel.color = colorSelected; return true; } /// /// OnDeselection implementation. /// public override void OnDeselection() { nameLabel.color = colorDefault; } void Update() { if (m_Timer >= m_Value.refreshRate) { UpdateValue(); m_Timer -= m_Value.refreshRate; } m_Timer += Time.deltaTime; } void UpdateValue() { float value = (float)m_Value.GetValue(); valueLabel.text = m_Value.FormatString(value); Vector3 scale = progressBarRect.localScale; scale.x = value; progressBarRect.localScale = scale; } } }