Files

51 lines
1.2 KiB
C#
Raw Permalink Normal View History

2026-01-09 10:43:40 +09:00
using System;
using AZTECHWB.Extensions;
2026-01-09 10:43:40 +09:00
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AZTECHWB.UI
2026-01-09 10:43:40 +09:00
{
public class SliderInputField : MonoBehaviour
2026-01-09 10:43:40 +09:00
{
private bool isUpdating = false;
public TextMeshProUGUI Value;
2026-01-09 10:43:40 +09:00
public Slider Slider;
public void SetSliderInputField()
{
transform.TryGetComponentInChildren(nameof(Value), out Value);
2026-01-09 10:43:40 +09:00
Slider = transform.GetComponentInChildren<Slider>(true);
Slider.onValueChanged.AddListener(OnSliderValueChanged);
}
public void SetText(string value)
{
if (isUpdating) return;
isUpdating = true;
Value.text = value;
if (float.TryParse(value, out float v))
Slider.SetValueWithoutNotify(v);
2026-01-09 10:43:40 +09:00
isUpdating = false;
}
void OnSliderValueChanged(float value)
2026-01-09 10:43:40 +09:00
{
if (isUpdating) return;
var newValue = Math.Truncate(value * 10f) / 10f;
2026-01-09 10:43:40 +09:00
isUpdating = true;
Value.text = newValue.ToString("0.#");
2026-01-09 10:43:40 +09:00
isUpdating = false;
}
public string GetValue()
{
return Value.text;
}
2026-01-09 10:43:40 +09:00
}
}