feat: close game fade

This commit is contained in:
Gerard Gascón 2024-04-20 20:34:45 +02:00
parent 091f7686cd
commit b3996c6831
3 changed files with 40 additions and 2 deletions

View file

@ -27,7 +27,7 @@ PluginImporter:
- first:
Standalone: Win64
second:
enabled: 1
enabled: 0
settings: {}
userData:
assetBundleName:

View file

@ -10,6 +10,7 @@ namespace View {
AppWindowUtility.AlwaysOnTop = true;
AppWindowUtility.FrameVisibility = false;
AppWindowUtility.Transparent = true;
AppWindowUtility.SetWindowOpacity(0xFF);
Vector2Int displaySize = new(Screen.currentResolution.width, Screen.currentResolution.height);
const float aspect = 10f / 15f;

View file

@ -1,3 +1,9 @@
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;
@ -5,16 +11,47 @@ 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
Application.Quit();
}
}
}