Roses/Assets/Scripts/View/UI/CloseButton.cs
2024-04-20 20:34:45 +02:00

57 lines
No EOL
1.2 KiB
C#

using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using FMOD.Studio;
using FMODUnity;
using SatorImaging.AppWindowUtility;
using UnityEngine;
using UnityEngine.UI;
namespace View.UI {
public class CloseButton : MonoBehaviour {
private Button _button;
#if !UNITY_EDITOR
private float _volume = 1f;
private float _opacity = 1f;
private Bus _musicBus;
private Bus _sfxBus;
#endif
private void Start() {
_button = GetComponent<Button>();
_button.onClick.AddListener(CloseClicked);
#if !UNITY_EDITOR
_musicBus = RuntimeManager.GetBus("bus:/Music");
_sfxBus = RuntimeManager.GetBus("bus:/SFX");
#endif
}
private void CloseClicked() {
#if UNITY_EDITOR
Debug.Log("Quit");
#else
DOTween.To(GetOpacity, SetOpacity, 0f, 1f).onComplete += Application.Quit;
DOTween.To(GetVolume, SetVolume, 0f, 1f);
#endif
}
#if !UNITY_EDITOR
private float GetVolume() => _volume;
private void SetVolume(float volume) {
_volume = volume;
_musicBus.setVolume(volume);
_sfxBus.setVolume(volume);
}
private float GetOpacity() => _opacity;
private void SetOpacity(float opacity) {
_opacity = opacity;
byte op = (byte)(int)(opacity * 255);
AppWindowUtility.SetWindowOpacity(op);
}
#endif
}
}