using System.Collections.Generic; using UnityEngine; namespace Artngame.SKYMASTER { public class playMusicAtTimeSM : MonoBehaviour { public bool reduceOtherSounds; public List audioSourcesToPause = new List(); public float pauseSpeed = 10f; public float lowThres = 0.01f; public AudioSource audioDawn; public AudioSource audioMidday; public AudioSource audioDusk; public AudioSource audioNight; public float volumeIncreaseSpeed = 0.01f; public float maxVolumeDawn = 0.65f; public float maxVolumeMidday = 0.65f; public float maxVolumeDusk = 0.65f; public float maxVolumeNight = 0.65f; public SkyMasterManager skymanager; public bool changeWeatherPerMusic; public SkyMasterManager.Volume_Weather_types dawnWeather; public SkyMasterManager.Volume_Weather_types middayWeather = SkyMasterManager.Volume_Weather_types.Cloudy; public SkyMasterManager.Volume_Weather_types duskWeather = SkyMasterManager.Volume_Weather_types.LightningStorm; public SkyMasterManager.Volume_Weather_types nightWeather = SkyMasterManager.Volume_Weather_types.Rain; public float dawnTime = 9f; public float middayTime = 14f; public float duskTime = 20f; public float nightTime = 23.5f; public bool playOnce; private void Start() { } private void LateUpdate() { if (skymanager.Current_Time > dawnTime && skymanager.Current_Time < middayTime) { if (audioDawn.volume < maxVolumeDawn) { if (playOnce && !audioDawn.isPlaying) { audioDawn.Play(); } audioDawn.volume += volumeIncreaseSpeed * Time.deltaTime; } if (reduceOtherSounds && audioDawn.isPlaying) { for (int i = 0; i < audioSourcesToPause.Count; i++) { audioSourcesToPause[i].volume -= pauseSpeed * Time.deltaTime; if (audioSourcesToPause[i].volume <= lowThres) { audioSourcesToPause[i].volume = lowThres; } } } audioMidday.volume -= volumeIncreaseSpeed * Time.deltaTime; audioDusk.volume -= volumeIncreaseSpeed * Time.deltaTime; audioNight.volume -= volumeIncreaseSpeed * Time.deltaTime; if (playOnce) { if (audioMidday.volume < 0.01f) { audioMidday.Stop(); } if (audioDusk.volume < 0.01f) { audioDusk.Stop(); } if (audioNight.volume < 0.01f) { audioNight.Stop(); } } if (changeWeatherPerMusic) { skymanager.currentWeatherName = dawnWeather; } } if (skymanager.Current_Time >= middayTime && skymanager.Current_Time < duskTime) { audioDawn.volume -= volumeIncreaseSpeed * Time.deltaTime; if (audioMidday.volume < maxVolumeMidday) { if (playOnce && !audioMidday.isPlaying) { audioMidday.Play(); } audioMidday.volume += volumeIncreaseSpeed * Time.deltaTime; } if (reduceOtherSounds && audioMidday.isPlaying) { for (int j = 0; j < audioSourcesToPause.Count; j++) { audioSourcesToPause[j].volume -= pauseSpeed * Time.deltaTime; if (audioSourcesToPause[j].volume <= lowThres) { audioSourcesToPause[j].volume = lowThres; } } } audioDusk.volume -= volumeIncreaseSpeed * Time.deltaTime; audioNight.volume -= volumeIncreaseSpeed * Time.deltaTime; if (playOnce) { if (audioDawn.volume < 0.01f) { audioDawn.Stop(); } if (audioDusk.volume < 0.01f) { audioDusk.Stop(); } if (audioNight.volume < 0.01f) { audioNight.Stop(); } } if (changeWeatherPerMusic) { skymanager.currentWeatherName = middayWeather; } } if (skymanager.Current_Time >= duskTime && skymanager.Current_Time < nightTime) { audioDawn.volume -= volumeIncreaseSpeed * Time.deltaTime; audioMidday.volume -= volumeIncreaseSpeed * Time.deltaTime; if (audioDusk.volume < maxVolumeDusk) { if (playOnce && !audioDusk.isPlaying) { audioDusk.Play(); } audioDusk.volume += volumeIncreaseSpeed * Time.deltaTime; } if (reduceOtherSounds && audioDusk.isPlaying) { for (int k = 0; k < audioSourcesToPause.Count; k++) { audioSourcesToPause[k].volume -= pauseSpeed * Time.deltaTime; if (audioSourcesToPause[k].volume <= lowThres) { audioSourcesToPause[k].volume = lowThres; } } } audioNight.volume -= volumeIncreaseSpeed * Time.deltaTime; if (playOnce) { if (audioDawn.volume < 0.01f) { audioDawn.Stop(); } if (audioMidday.volume < 0.01f) { audioMidday.Stop(); } if (audioNight.volume < 0.01f) { audioNight.Stop(); } } if (changeWeatherPerMusic) { skymanager.currentWeatherName = duskWeather; } } if ((!(skymanager.Current_Time >= nightTime) || !(skymanager.Current_Time <= 24f)) && (!(skymanager.Current_Time >= 0f) || !(skymanager.Current_Time <= dawnTime))) { return; } audioDawn.volume -= volumeIncreaseSpeed * Time.deltaTime; audioMidday.volume -= volumeIncreaseSpeed * Time.deltaTime; audioDusk.volume -= volumeIncreaseSpeed * Time.deltaTime; if (audioNight.volume < maxVolumeNight) { if (playOnce && !audioNight.isPlaying) { audioNight.Play(); } audioNight.volume += volumeIncreaseSpeed * Time.deltaTime; } if (reduceOtherSounds && audioNight.isPlaying) { for (int l = 0; l < audioSourcesToPause.Count; l++) { audioSourcesToPause[l].volume -= pauseSpeed * Time.deltaTime; if (audioSourcesToPause[l].volume <= lowThres) { audioSourcesToPause[l].volume = lowThres; } } } if (playOnce) { if (audioDawn.volume < 0.01f) { audioDawn.Stop(); } if (audioMidday.volume < 0.01f) { audioMidday.Stop(); } if (audioDusk.volume < 0.01f) { audioDusk.Stop(); } } if (changeWeatherPerMusic) { skymanager.currentWeatherName = nightWeather; } } } }