using UnityEngine; namespace GrassCutter { /// /// Wind by day and crickets by night where the camera is, and music that follows them: five tunes in turn by day, two quiet /// ones in the dark, and a tense one while a storm is on. /// public class Soundscape : MonoBehaviour { const float Loud = 0.32f, TuneLength = 200f, Every = 2f; AudioSource _wind, _crickets; float _next, _tuneEnds; bool _night; int _day, _dark; static readonly string[] Days = { "music_game_loop", "music_game3_loop", "music_game2_loop", "music_game4_loop", "music_game5_loop" }; static readonly string[] Nights = { "music_night_loop", "music_night2_loop" }; AudioSource Make(string clip) { var s = Sfx.Loop(clip, transform, 0f); if (s) s.spatialBlend = 0f; return s; } void Update() { if (!_wind) { if (!AssetBank.I) return; _wind = Make("wind_meadow_loop"); _crickets = Make("night_crickets_loop"); if (!_wind) { enabled = false; return; } } float dark = DayNight.Dark; _wind.volume = Loud * (1f - dark) * Sfx.SfxVolume; if (_crickets) _crickets.volume = Loud * dark * Sfx.SfxVolume; if (Time.time < _next || !UIRoot.I || !UIRoot.I.InGame) return; _next = Time.time + Every; if (_night ? dark < 0.3f : dark > 0.7f) _night = !_night; if (Time.time >= _tuneEnds) { _tuneEnds = Time.time + TuneLength; if (_night) _dark = (_dark + 1) % Nights.Length; else _day = (_day + 1) % Days.Length; } // the ending plays its own tune under the planet if (EndingCinematic.Running) return; Sfx.Music(WeatherFx.Storm > 0.5f ? "music_storm_loop" : _night ? Nights[_dark] : Days[_day], 4f); } } }