using System;
using System.Collections;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

public class MainGameDebugParameter : MonoBehaviour
{
    [SerializeField] private Text text;
    [SerializeField] private InputField inputField;
    [SerializeField] private Slider slider;

    [SerializeField] private float minValue;
    [SerializeField] private float maxValue;

    public IObservable<float> OnValueChange => slider.OnValueChangedAsObservable()
        .Merge(inputField.OnEndEditAsObservable().Select(float.Parse))
        .TakeUntilDestroy(this);

    void Awake()
    {
        slider.minValue = minValue;
        slider.maxValue = maxValue;
        // text.text = paramName;
        OnValueChange.Subscribe(x =>
        {
            inputField.text = $"{x:0.######}";
            SetValue(x);
        }).AddTo(this);
    }

    public void SetValue(float value)
    {
        // maxValueを超えた値が来た場合そちらを優先する
        slider.maxValue = Mathf.Max(slider.maxValue, value);
        slider.value = value;
    }
}
