51 lines
1.2 KiB
C#

using UnityEngine;
public class BoolView : BaseSettingView
{
[Header("Layout ссылки")]
[SerializeField] GameObject EnabledImage;
[SerializeField] GameObject DisabledImage;
[Header("Звуки")]
[SerializeField] private AudioClip EnableSound;
[SerializeField] private AudioClip DisableSound;
public bool Value { get; private set; }
public SettingDTO CachedSetting { get; private set; }
public void Initialize(SettingDTO setting)
{
base.Initialize(setting);
Value = setting.BoolValue;
CachedSetting = setting;
Display();
}
public override void TakeInput(int direction, bool _)
{
if (direction == 0) return;
bool newValue = direction > 0;
if (newValue == Value) return;
Value = newValue;
CachedSetting.BoolValue = Value;
Display();
}
private void Display()
{
EnabledImage.SetActive(Value);
DisabledImage.SetActive(!Value);
var sound = Value ? EnableSound : DisableSound;
SoundManager.instance.playClip(sound);
}
private void OnDestroy()
{
StopAllCoroutines();
}
}