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

namespace MPStudio
{

    public class BtnClick : MonoBehaviour
    {

        public string audioName;

        public float scaleOffset = 0.15f;
        public float animationCost = 0.1f;
        
        private Button _btn;

      
        
        private Vector3 initScale;
        private void Awake()
        {
            _btn = GetComponent<Button>();
 
             initScale = transform.localScale;
        }

        // Start is called before the first frame update
        void Start()
        {
            _btn.onClick.AddListener(() =>
            {
                if(String.IsNullOrEmpty(this.audioName)==false)
                    AudioManager.Inst.EffectPlay(this.audioName);
                
                StartCoroutine(TweenManager.Inst.ByFloat(initScale.x, -scaleOffset, animationCost, (f) =>
                {
                    _btn.transform.localScale = initScale * (float)f;
                }, () =>
                {
                   StartCoroutine( TweenManager.Inst.ByFloat(initScale.x-scaleOffset, scaleOffset, animationCost, (f) =>
                    {
                        _btn.transform.localScale = initScale * (float)f;
                    }));
                }));
            });
        }

        // Update is called once per frame
        void Update()
        {

        }
    }
}