55 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BoolView : MonoBehaviour, ISettingView
{
[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)
{
this.Value = setting.BoolValue;
this.CachedSetting = setting;
Display();
}
public void TakeInput(int direction)
{
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.PlayUi(sound);
}
private void OnDestroy()
{
StopAllCoroutines();
}
}