39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UIElements;
|
|
namespace BITKit.UX
|
|
{
|
|
public class UXSlider : UXElement<Slider>, IProvider<float>
|
|
{
|
|
public UnityEvent<float> onSetValue = new();
|
|
public Provider outputValue;
|
|
public override void OnStart()
|
|
{
|
|
base.OnStart();
|
|
visualElement.RegisterValueChangedCallback(x =>
|
|
{
|
|
onSetValue.Invoke(x.newValue);
|
|
outputValue?.Set(x.newValue);
|
|
});
|
|
}
|
|
float IProvider<float>.Get()
|
|
{
|
|
return visualElement.value;
|
|
}
|
|
void IProvider<float>.Set(float t)
|
|
{
|
|
SetValue(t);
|
|
}
|
|
public void SetValue(float t)
|
|
{
|
|
visualElement.SetValueWithoutNotify(t);
|
|
}
|
|
public void SetNormalizeValue(float t)
|
|
{
|
|
var value = Mathf.Lerp(visualElement.lowValue, visualElement.highValue, t);
|
|
visualElement.SetValueWithoutNotify(value);
|
|
}
|
|
}
|
|
} |