1
This commit is contained in:
39
Unity/Scripts/UX/Core/UXSlider.cs
Normal file
39
Unity/Scripts/UX/Core/UXSlider.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user