A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date. Images, audio, models and binaries go through Git LFS (.gitattributes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
using UnityEngine;
|
|
|
|
namespace GrassCutter
|
|
{
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
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;
|
|
}
|
|
Sfx.Music(WeatherFx.Storm > 0.5f ? "music_storm_loop" : _night ? Nights[_dark] : Days[_day], 4f);
|
|
}
|
|
}
|
|
}
|