56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
public class ActionView :MonoBehaviour, IView
|
|
{
|
|
public Image timerImage;
|
|
|
|
public float volumeMax;
|
|
public AudioSource source;
|
|
public AudioClip readyClip;
|
|
public UnityEvent OnChangeReady { get; private set; }
|
|
|
|
public void ChangeValue(string precent)
|
|
{
|
|
float value = float.Parse(precent);
|
|
|
|
timerImage.transform.localScale = Vector2.one * value;
|
|
|
|
source.volume = volumeMax * value;
|
|
source.pitch = 0.5f + 3.5f * value;
|
|
if(value > 0)
|
|
{
|
|
if (!source.isPlaying)
|
|
{
|
|
source.Play();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
source.Stop();
|
|
}
|
|
|
|
}
|
|
|
|
public void Initialize(string precent)
|
|
{
|
|
SetVolume();
|
|
SettingsManager.OnSettingsChanged.AddListener(SetVolume);
|
|
|
|
OnChangeReady ??= new();
|
|
OnChangeReady.AddListener(ReadySound);
|
|
|
|
ChangeValue(precent);
|
|
}
|
|
|
|
void SetVolume()
|
|
{
|
|
volumeMax = SettingsManager.GetFloat("SoundsVolume", 0.5f);
|
|
}
|
|
void ReadySound()
|
|
{
|
|
SoundManager.instance.playClip(readyClip);
|
|
}
|
|
}
|