using System; using UnityEngine.UI; namespace UnityEngine.Rendering.UI { /// /// DebugUIHandler for indirect float widget. /// public class DebugUIHandlerIndirectFloatField : DebugUIHandlerWidget { /// Name of the indirect float field. public Text nameLabel; /// Value of the indirect float field. public Text valueLabel; /// /// Getter function for this indirect widget. /// public Func getter; /// /// Setter function for this indirect widget. /// public Action setter; /// /// Getter function for the increment step of this indirect widget. /// public Func incStepGetter; /// /// Getter function for the increment step multiplier of this indirect widget. /// public Func incStepMultGetter; /// /// Getter function for the number of decimals of this indirect widget. /// public Func decimalsGetter; /// /// Initialize the indirect widget. /// public void Init() { UpdateValueLabel(); } /// /// 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; valueLabel.color = colorSelected; return true; } /// /// OnDeselection implementation. /// public override void OnDeselection() { nameLabel.color = colorDefault; valueLabel.color = colorDefault; } /// /// OnIncrement implementation. /// /// True if incrementing fast. public override void OnIncrement(bool fast) { ChangeValue(fast, 1); } /// /// OnDecrement implementation. /// /// Trye if decrementing fast. public override void OnDecrement(bool fast) { ChangeValue(fast, -1); } void ChangeValue(bool fast, float multiplier) { float value = getter(); value += incStepGetter() * (fast ? incStepMultGetter() : 1f) * multiplier; setter(value); UpdateValueLabel(); } void UpdateValueLabel() { if (valueLabel != null) valueLabel.text = getter().ToString("N" + decimalsGetter()); } } }