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

namespace Arugula.Audio
{
    [RequireComponent(typeof(Slider))]
    public class PhonicUISlider : PhonicHandlerBase
    {
        [PhonicSound] public string onValueChanged;

        [Header("Settings")]
        public float dragLoopDelay = 0.25f;
        float nextDragTime = 0;

        private void Awake() => GetComponent<Slider>().onValueChanged.AddListener((x) => Play(onValueChanged));

        void OnValueChanged(float value)
        {
            if (Time.time > nextDragTime)
            {
                nextDragTime = Time.time + dragLoopDelay;
                Play(onValueChanged);
            }
        }
    }

}
