Commit b3996c68 authored by Gerard Gascón's avatar Gerard Gascón
Browse files

feat: close game fade

parent 091f7686
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ PluginImporter:
  - first:
      Standalone: Win64
    second:
      enabled: 1
      enabled: 0
      settings: {}
  userData: 
  assetBundleName: 
+1 −0
Original line number Diff line number Diff line
@@ -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;
+38 −1
Original line number Diff line number Diff line
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
			Application.Quit();
		}

#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
	}
}
 No newline at end of file