| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| using UnityEngine.Audio; |
| using UnityEngine.Audio; |
| |
| |
| public class MusicMan : MonoBehaviour |
| public class MusicMan : MonoBehaviour |
| { |
| { |
| public static MusicMan instance |
| public static MusicMan instance |
| { |
| { |
| get |
| get |
| { |
| { |
| return MusicMan.m_instance; |
| return MusicMan.m_instance; |
| } |
| } |
| } |
| } |
| |
| |
| private void Awake() |
| private void Awake() |
| { |
| { |
| if (MusicMan.m_instance) |
| if (MusicMan.m_instance) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| MusicMan.m_instance = this; |
| MusicMan.m_instance = this; |
| GameObject gameObject = new GameObject("music"); |
| GameObject gameObject = new GameObject("music"); |
| gameObject.transform.SetParent(base.transform); |
| gameObject.transform.SetParent(base.transform); |
| this.m_musicSource = gameObject.AddComponent<AudioSource>(); |
| this.m_musicSource = gameObject.AddComponent<AudioSource>(); |
| this.m_musicSource.loop = true; |
| this.m_musicSource.loop = true; |
| this.m_musicSource.spatialBlend = 0f; |
| this.m_musicSource.spatialBlend = 0f; |
| this.m_musicSource.outputAudioMixerGroup = this.m_musicMixer; |
| this.m_musicSource.outputAudioMixerGroup = this.m_musicMixer; |
| this.m_musicSource.priority = 0; |
| this.m_musicSource.priority = 0; |
| this.m_musicSource.bypassReverbZones = true; |
| this.m_musicSource.bypassReverbZones = true; |
| this.m_randomAmbientInterval = UnityEngine.Random.Range(this.m_randomMusicIntervalMin, this.m_randomMusicIntervalMax); |
| this.m_randomAmbientInterval = UnityEngine.Random.Range(this.m_randomMusicIntervalMin, this.m_randomMusicIntervalMax); |
| MusicMan.m_masterMusicVolume = PlayerPrefs.GetFloat("MusicVolume", 1f); |
| MusicMan.m_masterMusicVolume = PlayerPrefs.GetFloat("MusicVolume", 1f); |
| this.ApplySettings(); |
| this.ApplySettings(); |
| foreach (MusicMan.NamedMusic namedMusic in this.m_music) |
| foreach (MusicMan.NamedMusic namedMusic in this.m_music) |
| { |
| { |
| foreach (AudioClip audioClip in namedMusic.m_clips) |
| foreach (AudioClip audioClip in namedMusic.m_clips) |
| { |
| { |
| if (audioClip == null || !audioClip) |
| if (audioClip == null || !audioClip) |
| { |
| { |
| namedMusic.m_enabled = false; |
| namedMusic.m_enabled = false; |
| ZLog.LogWarning("Missing audio clip in music " + namedMusic.m_name); |
| ZLog.LogWarning("Missing audio clip in music " + namedMusic.m_name); |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public void ApplySettings() |
| public void ApplySettings() |
| { |
| { |
| foreach (MusicMan.NamedMusic namedMusic in this.m_music) |
| foreach (MusicMan.NamedMusic namedMusic in this.m_music) |
| { |
| { |
| if (namedMusic.m_ambientMusic) |
| if (namedMusic.m_ambientMusic) |
| { |
| { |
| namedMusic.m_loop = Settings.ContinousMusic; |
| namedMusic.m_loop = Settings.ContinousMusic; |
| if (!Settings.ContinousMusic && this.GetCurrentMusic() == namedMusic.m_name && this.m_musicSource.loop) |
| if (!Settings.ContinousMusic && this.GetCurrentMusic() == namedMusic.m_name && this.m_musicSource.loop) |
| { |
| { |
| ZLog.Log("Stopping looping music because continous music is disabled"); |
| ZLog.Log("Stopping looping music because continous music is disabled"); |
| this.StopMusic(); |
| this.StopMusic(); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void OnDestroy() |
| private void OnDestroy() |
| { |
| { |
| if (MusicMan.m_instance == this) |
| if (MusicMan.m_instance == this) |
| { |
| { |
| MusicMan.m_instance = null; |
| MusicMan.m_instance = null; |
| } |
| } |
| } |
| } |
| |
| |
| private void Update() |
| private void Update() |
| { |
| { |
| if (MusicMan.m_instance != this) |
| if (MusicMan.m_instance != this) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| float deltaTime = Time.deltaTime; |
| float deltaTime = Time.deltaTime; |
| this.UpdateCurrentMusic(deltaTime); |
| this.UpdateCurrentMusic(deltaTime); |
| this.UpdateCombatMusic(deltaTime); |
| this.UpdateCombatMusic(deltaTime); |
| this.m_currentMusicVolMax = MusicVolume.UpdateProximityVolumes(this.m_musicSource); |
| this.m_currentMusicVolMax = MusicVolume.UpdateProximityVolumes(this.m_musicSource); |
| this.UpdateMusic(deltaTime); |
| this.UpdateMusic(deltaTime); |
| } |
| } |
| |
| |
| private void UpdateCurrentMusic(float dt) |
| private void UpdateCurrentMusic(float dt) |
| { |
| { |
| string currentMusic = this.GetCurrentMusic(); |
| string currentMusic = this.GetCurrentMusic(); |
| if (Game.instance != null) |
| if (Game.instance != null) |
| { |
| { |
| if (Player.m_localPlayer == null) |
| if (Player.m_localPlayer == null) |
| { |
| { |
| this.StartMusic("respawn"); |
| this.StartMusic("respawn"); |
| return; |
| return; |
| } |
| } |
| if (currentMusic == "respawn") |
| if (currentMusic == "respawn") |
| { |
| { |
| this.StopMusic(); |
| this.StopMusic(); |
| } |
| } |
| } |
| } |
| if (Player.m_localPlayer && Player.m_localPlayer.InIntro()) |
| if (Player.m_localPlayer && Player.m_localPlayer.InIntro()) |
| { |
| { |
| this.StartMusic("intro"); |
| this.StartMusic("intro"); |
| return; |
| return; |
| } |
| } |
| if (currentMusic == "intro") |
| if (currentMusic == "intro") |
| { |
| { |
| this.StopMusic(); |
| this.StopMusic(); |
| } |
| } |
| . | |
| float num = ((this.m_randomEventMusic == null) ? 0f : (-80f)); |
| |
| this.m_musicOnTopDuckVolume = Mathf.MoveTowards(this.m_musicOnTopDuckVolume, num, 80f * Time.deltaTime); |
| |
| this.m_musicMixer.audioMixer.SetFloat("Music_ontop_ducking", this.m_musicOnTopDuckVolume); |
| if (this.HandleEventMusic(currentMusic)) |
| if (this.HandleEventMusic(currentMusic)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.HandleLocationMusic(currentMusic)) |
| if (this.HandleLocationMusic(currentMusic)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.HandleSailingMusic(dt, currentMusic)) |
| if (this.HandleSailingMusic(dt, currentMusic)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.HandleTriggerMusic(currentMusic)) |
| if (this.HandleTriggerMusic(currentMusic)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.HandleEnvironmentMusic(dt, currentMusic); |
| this.HandleEnvironmentMusic(dt, currentMusic); |
| } |
| } |
| |
| |
| private bool HandleEnvironmentMusic(float dt, string currentMusic) |
| private bool HandleEnvironmentMusic(float dt, string currentMusic) |
| { |
| { |
| if (!EnvMan.instance) |
| if (!EnvMan.instance) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| MusicMan.NamedMusic environmentMusic = this.GetEnvironmentMusic(); |
| MusicMan.NamedMusic environmentMusic = this.GetEnvironmentMusic(); |
| string currentMusic2 = this.GetCurrentMusic(); |
| string currentMusic2 = this.GetCurrentMusic(); |
| if (environmentMusic == null || (this.m_currentMusic != null && environmentMusic.m_name != currentMusic2)) |
| if (environmentMusic == null || (this.m_currentMusic != null && environmentMusic.m_name != currentMusic2)) |
| { |
| { |
| this.StopMusic(); |
| this.StopMusic(); |
| return true; |
| return true; |
| } |
| } |
| if (environmentMusic.m_name == currentMusic2) |
| if (environmentMusic.m_name == currentMusic2) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| if (!environmentMusic.m_loop) |
| if (!environmentMusic.m_loop) |
| { |
| { |
| if (Time.time - this.m_lastAmbientMusicTime < this.m_randomAmbientInterval) |
| if (Time.time - this.m_lastAmbientMusicTime < this.m_randomAmbientInterval) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| this.m_randomAmbientInterval = UnityEngine.Random.Range(this.m_randomMusicIntervalMin, this.m_randomMusicIntervalMax); |
| this.m_randomAmbientInterval = UnityEngine.Random.Range(this.m_randomMusicIntervalMin, this.m_randomMusicIntervalMax); |
| this.m_lastAmbientMusicTime = Time.time; |
| this.m_lastAmbientMusicTime = Time.time; |
| ZLog.Log("Environment music starting at random ambient interval"); |
| ZLog.Log("Environment music starting at random ambient interval"); |
| } |
| } |
| this.StartMusic(environmentMusic); |
| this.StartMusic(environmentMusic); |
| return true; |
| return true; |
| } |
| } |
| |
| |
| private MusicMan.NamedMusic GetEnvironmentMusic() |
| private MusicMan.NamedMusic GetEnvironmentMusic() |
| { |
| { |
| string text; |
| string text; |
| if (Player.m_localPlayer && Player.m_localPlayer.IsSafeInHome()) |
| if (Player.m_localPlayer && Player.m_localPlayer.IsSafeInHome()) |
| { |
| { |
| text = "home"; |
| text = "home"; |
| } |
| } |
| else |
| else |
| { |
| { |
| text = EnvMan.instance.GetAmbientMusic(); |
| text = EnvMan.instance.GetAmbientMusic(); |
| } |
| } |
| return this.FindMusic(text); |
| return this.FindMusic(text); |
| } |
| } |
| |
| |
| private bool HandleTriggerMusic(string currentMusic) |
| private bool HandleTriggerMusic(string currentMusic) |
| { |
| { |
| if (this.m_triggerMusic != null) |
| if (this.m_triggerMusic != null) |
| { |
| { |
| this.StartMusic(this.m_triggerMusic); |
| this.StartMusic(this.m_triggerMusic); |
| this.m_triggeredMusic = this.m_triggerMusic; |
| this.m_triggeredMusic = this.m_triggerMusic; |
| this.m_triggerMusic = null; |
| this.m_triggerMusic = null; |
| return true; |
| return true; |
| } |
| } |
| if (this.m_triggeredMusic != null) |
| if (this.m_triggeredMusic != null) |
| { |
| { |
| if (currentMusic == this.m_triggeredMusic) |
| if (currentMusic == this.m_triggeredMusic) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| this.m_triggeredMusic = null; |
| this.m_triggeredMusic = null; |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| public void LocationMusic(string name) |
| public void LocationMusic(string name) |
| { |
| { |
| this.m_locationMusic = name; |
| this.m_locationMusic = name; |
| } |
| } |
| |
| |
| private bool HandleLocationMusic(string currentMusic) |
| private bool HandleLocationMusic(string currentMusic) |
| { |
| { |
| if (this.m_lastLocationMusic != null && DateTime.Now > this.m_lastLocationMusicChange + TimeSpan.FromSeconds((double)this.m_repeatLocationMusicResetSeconds)) |
| if (this.m_lastLocationMusic != null && DateTime.Now > this.m_lastLocationMusicChange + TimeSpan.FromSeconds((double)this.m_repeatLocationMusicResetSeconds)) |
| { |
| { |
| this.m_lastLocationMusic = null; |
| this.m_lastLocationMusic = null; |
| this.m_lastLocationMusicChange = DateTime.Now; |
| this.m_lastLocationMusicChange = DateTime.Now; |
| } |
| } |
| if (this.m_locationMusic == null) |
| if (this.m_locationMusic == null) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| if (currentMusic == this.m_locationMusic && !this.m_musicSource.isPlaying) |
| if (currentMusic == this.m_locationMusic && !this.m_musicSource.isPlaying) |
| { |
| { |
| this.m_locationMusic = null; |
| this.m_locationMusic = null; |
| return false; |
| return false; |
| } |
| } |
| if (currentMusic != this.m_locationMusic) |
| if (currentMusic != this.m_locationMusic) |
| { |
| { |
| this.m_lastLocationMusicChange = DateTime.Now; |
| this.m_lastLocationMusicChange = DateTime.Now; |
| } |
| } |
| if (this.StartMusic(this.m_locationMusic)) |
| if (this.StartMusic(this.m_locationMusic)) |
| { |
| { |
| this.m_lastLocationMusic = this.m_locationMusic; |
| this.m_lastLocationMusic = this.m_locationMusic; |
| } |
| } |
| else |
| else |
| { |
| { |
| ZLog.Log("Location music missing: " + this.m_locationMusic); |
| ZLog.Log("Location music missing: " + this.m_locationMusic); |
| this.m_locationMusic = null; |
| this.m_locationMusic = null; |
| } |
| } |
| return true; |
| return true; |
| } |
| } |
| |
| |
| private bool HandleEventMusic(string currentMusic) |
| private bool HandleEventMusic(string currentMusic) |
| { |
| { |
| if (RandEventSystem.instance) |
| if (RandEventSystem.instance) |
| { |
| { |
| string musicOverride = RandEventSystem.instance.GetMusicOverride(); |
| string musicOverride = RandEventSystem.instance.GetMusicOverride(); |
| if (musicOverride != null) |
| if (musicOverride != null) |
| { |
| { |
| this.StartMusic(musicOverride); |
| this.StartMusic(musicOverride); |
| this.m_randomEventMusic = musicOverride; |
| this.m_randomEventMusic = musicOverride; |
| return true; |
| return true; |
| } |
| } |
| if (currentMusic == this.m_randomEventMusic) |
| if (currentMusic == this.m_randomEventMusic) |
| { |
| { |
| this.m_randomEventMusic = null; |
| this.m_randomEventMusic = null; |
| this.StopMusic(); |
| this.StopMusic(); |
| } |
| } |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private bool HandleCombatMusic(string currentMusic) |
| private bool HandleCombatMusic(string currentMusic) |
| { |
| { |
| if (this.InCombat()) |
| if (this.InCombat()) |
| { |
| { |
| this.StartMusic("combat"); |
| this.StartMusic("combat"); |
| return true; |
| return true; |
| } |
| } |
| if (currentMusic == "combat") |
| if (currentMusic == "combat") |
| { |
| { |
| this.StopMusic(); |
| this.StopMusic(); |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private bool HandleSailingMusic(float dt, string currentMusic) |
| private bool HandleSailingMusic(float dt, string currentMusic) |
| { |
| { |
| if (this.IsSailing()) |
| if (this.IsSailing()) |
| { |
| { |
| this.m_notSailDuration = 0f; |
| this.m_notSailDuration = 0f; |
| this.m_sailDuration += dt; |
| this.m_sailDuration += dt; |
| if (this.m_sailDuration > this.m_sailMusicMinSailTime) |
| if (this.m_sailDuration > this.m_sailMusicMinSailTime) |
| { |
| { |
| . | this.StartMusic("sailing"); |
| this.StartMusic(this.GetSailingMusic()); |
| return true; |
| return true; |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_sailDuration = 0f; |
| this.m_sailDuration = 0f; |
| this.m_notSailDuration += dt; |
| this.m_notSailDuration += dt; |
| . | if (this.m_notSailDuration > this.m_sailMusicMinSailTime / 2f && currentMusic == "sailing") |
| if (this.m_notSailDuration > this.m_sailMusicMinSailTime / 2f && currentMusic == this.GetSailingMusic() && currentMusic != EnvMan.instance.GetAmbientMusic()) |
| { |
| { |
| this.StopMusic(); |
| this.StopMusic(); |
| } |
| } |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| . | |
| public string GetSailingMusic() |
| |
| { |
| |
| if (Player.m_localPlayer && Player.m_localPlayer.GetCurrentBiome() == Heightmap.Biome.AshLands) |
| |
| { |
| |
| return "sailing_ashlands"; |
| |
| } |
| |
| return "sailing"; |
| |
| } |
| |
| |
| private bool IsSailing() |
| private bool IsSailing() |
| { |
| { |
| if (!Player.m_localPlayer) |
| if (!Player.m_localPlayer) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| Ship localShip = Ship.GetLocalShip(); |
| Ship localShip = Ship.GetLocalShip(); |
| return localShip && localShip.GetSpeed() > this.m_sailMusicShipSpeedThreshold; |
| return localShip && localShip.GetSpeed() > this.m_sailMusicShipSpeedThreshold; |
| } |
| } |
| |
| |
| private void UpdateMusic(float dt) |
| private void UpdateMusic(float dt) |
| { |
| { |
| if (this.m_queuedMusic != null || this.m_stopMusic) |
| if (this.m_queuedMusic != null || this.m_stopMusic) |
| { |
| { |
| if (!this.m_musicSource.isPlaying || this.m_currentMusicVol <= 0f) |
| if (!this.m_musicSource.isPlaying || this.m_currentMusicVol <= 0f) |
| { |
| { |
| if (this.m_musicSource.isPlaying && this.m_currentMusic != null && this.m_currentMusic.m_loop && this.m_currentMusic.m_resume) |
| if (this.m_musicSource.isPlaying && this.m_currentMusic != null && this.m_currentMusic.m_loop && this.m_currentMusic.m_resume) |
| { |
| { |
| this.m_currentMusic.m_lastPlayedTime = Time.time; |
| this.m_currentMusic.m_lastPlayedTime = Time.time; |
| this.m_currentMusic.m_savedPlaybackPos = this.m_musicSource.timeSamples; |
| this.m_currentMusic.m_savedPlaybackPos = this.m_musicSource.timeSamples; |
| ZLog.Log("Stopped music " + this.m_currentMusic.m_name + " at " + this.m_currentMusic.m_savedPlaybackPos.ToString()); |
| ZLog.Log("Stopped music " + this.m_currentMusic.m_name + " at " + this.m_currentMusic.m_savedPlaybackPos.ToString()); |
| } |
| } |
| this.m_musicSource.Stop(); |
| this.m_musicSource.Stop(); |
| this.m_stopMusic = false; |
| this.m_stopMusic = false; |
| this.m_currentMusic = null; |
| this.m_currentMusic = null; |
| if (this.m_queuedMusic != null) |
| if (this.m_queuedMusic != null) |
| { |
| { |
| this.m_musicSource.clip = this.m_queuedMusic.m_clips[UnityEngine.Random.Range(0, this.m_queuedMusic.m_clips.Length)]; |
| this.m_musicSource.clip = this.m_queuedMusic.m_clips[UnityEngine.Random.Range(0, this.m_queuedMusic.m_clips.Length)]; |
| this.m_musicSource.loop = this.m_queuedMusic.m_loop; |
| this.m_musicSource.loop = this.m_queuedMusic.m_loop; |
| this.m_musicSource.volume = 0f; |
| this.m_musicSource.volume = 0f; |
| this.m_musicSource.timeSamples = 0; |
| this.m_musicSource.timeSamples = 0; |
| this.m_musicSource.Play(); |
| this.m_musicSource.Play(); |
| if (this.m_queuedMusic.m_loop && this.m_queuedMusic.m_resume && Time.time - this.m_queuedMusic.m_lastPlayedTime < this.m_musicSource.clip.length * 2f) |
| if (this.m_queuedMusic.m_loop && this.m_queuedMusic.m_resume && Time.time - this.m_queuedMusic.m_lastPlayedTime < this.m_musicSource.clip.length * 2f) |
| { |
| { |
| this.m_musicSource.timeSamples = this.m_queuedMusic.m_savedPlaybackPos; |
| this.m_musicSource.timeSamples = this.m_queuedMusic.m_savedPlaybackPos; |
| ZLog.Log("Resumed music " + this.m_queuedMusic.m_name + " at " + this.m_queuedMusic.m_savedPlaybackPos.ToString()); |
| ZLog.Log("Resumed music " + this.m_queuedMusic.m_name + " at " + this.m_queuedMusic.m_savedPlaybackPos.ToString()); |
| } |
| } |
| this.m_currentMusicVol = 0f; |
| this.m_currentMusicVol = 0f; |
| this.m_musicVolume = this.m_queuedMusic.m_volume; |
| this.m_musicVolume = this.m_queuedMusic.m_volume; |
| this.m_musicFadeTime = this.m_queuedMusic.m_fadeInTime; |
| this.m_musicFadeTime = this.m_queuedMusic.m_fadeInTime; |
| this.m_alwaysFadeout = this.m_queuedMusic.m_alwaysFadeout; |
| this.m_alwaysFadeout = this.m_queuedMusic.m_alwaysFadeout; |
| this.m_currentMusic = this.m_queuedMusic; |
| this.m_currentMusic = this.m_queuedMusic; |
| this.m_queuedMusic = null; |
| this.m_queuedMusic = null; |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| float num = ((this.m_queuedMusic != null) ? Mathf.Min(this.m_queuedMusic.m_fadeInTime, this.m_musicFadeTime) : this.m_musicFadeTime); |
| float num = ((this.m_queuedMusic != null) ? Mathf.Min(this.m_queuedMusic.m_fadeInTime, this.m_musicFadeTime) : this.m_musicFadeTime); |
| this.m_currentMusicVol = Mathf.MoveTowards(this.m_currentMusicVol, 0f, dt / num); |
| this.m_currentMusicVol = Mathf.MoveTowards(this.m_currentMusicVol, 0f, dt / num); |
| this.m_musicSource.volume = Utils.SmoothStep(0f, 1f, this.m_currentMusicVol) * this.m_musicVolume * MusicMan.m_masterMusicVolume; |
| this.m_musicSource.volume = Utils.SmoothStep(0f, 1f, this.m_currentMusicVol) * this.m_musicVolume * MusicMan.m_masterMusicVolume; |
| } |
| } |
| } |
| } |
| else if (this.m_musicSource.isPlaying) |
| else if (this.m_musicSource.isPlaying) |
| { |
| { |
| float num2 = this.m_musicSource.clip.length - this.m_musicSource.time; |
| float num2 = this.m_musicSource.clip.length - this.m_musicSource.time; |
| if (this.m_alwaysFadeout && !this.m_musicSource.loop && num2 < this.m_musicFadeTime) |
| if (this.m_alwaysFadeout && !this.m_musicSource.loop && num2 < this.m_musicFadeTime) |
| { |
| { |
| this.m_currentMusicVol = Mathf.MoveTowards(this.m_currentMusicVol, 0f, dt / this.m_musicFadeTime); |
| this.m_currentMusicVol = Mathf.MoveTowards(this.m_currentMusicVol, 0f, dt / this.m_musicFadeTime); |
| this.m_musicSource.volume = Utils.SmoothStep(0f, 1f, this.m_currentMusicVol) * this.m_musicVolume * MusicMan.m_masterMusicVolume; |
| this.m_musicSource.volume = Utils.SmoothStep(0f, 1f, this.m_currentMusicVol) * this.m_musicVolume * MusicMan.m_masterMusicVolume; |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_currentMusicVol = Mathf.MoveTowards(this.m_currentMusicVol, this.m_currentMusicVolMax, dt / this.m_musicFadeTime); |
| this.m_currentMusicVol = Mathf.MoveTowards(this.m_currentMusicVol, this.m_currentMusicVolMax, dt / this.m_musicFadeTime); |
| this.m_musicSource.volume = Utils.SmoothStep(0f, 1f, this.m_currentMusicVol) * this.m_musicVolume * MusicMan.m_masterMusicVolume; |
| this.m_musicSource.volume = Utils.SmoothStep(0f, 1f, this.m_currentMusicVol) * this.m_musicVolume * MusicMan.m_masterMusicVolume; |
| } |
| } |
| if (!Settings.ContinousMusic && num2 < this.m_musicFadeTime) |
| if (!Settings.ContinousMusic && num2 < this.m_musicFadeTime) |
| { |
| { |
| this.StopMusic(); |
| this.StopMusic(); |
| ZLog.Log("Music stopped after finishing, because continous music is disabled"); |
| ZLog.Log("Music stopped after finishing, because continous music is disabled"); |
| } |
| } |
| } |
| } |
| else if (this.m_currentMusic != null && !this.m_musicSource.isPlaying) |
| else if (this.m_currentMusic != null && !this.m_musicSource.isPlaying) |
| { |
| { |
| this.m_currentMusic = null; |
| this.m_currentMusic = null; |
| } |
| } |
| if (this.m_resetMusicTimer > 0f) |
| if (this.m_resetMusicTimer > 0f) |
| { |
| { |
| this.m_resetMusicTimer -= dt; |
| this.m_resetMusicTimer -= dt; |
| } |
| } |
| if (Terminal.m_showTests) |
| if (Terminal.m_showTests) |
| { |
| { |
| Terminal.m_testList["Music current"] = ((this.m_currentMusic == null) ? "NULL" : this.m_currentMusic.m_name); |
| Terminal.m_testList["Music current"] = ((this.m_currentMusic == null) ? "NULL" : this.m_currentMusic.m_name); |
| Terminal.m_testList["Music last started"] = ((this.m_lastStartedMusic == null) ? "NULL" : this.m_lastStartedMusic.m_name); |
| Terminal.m_testList["Music last started"] = ((this.m_lastStartedMusic == null) ? "NULL" : this.m_lastStartedMusic.m_name); |
| Terminal.m_testList["Music queued"] = ((this.m_queuedMusic == null) ? "NULL" : this.m_queuedMusic.m_name); |
| Terminal.m_testList["Music queued"] = ((this.m_queuedMusic == null) ? "NULL" : this.m_queuedMusic.m_name); |
| Terminal.m_testList["Music stopping"] = this.m_stopMusic.ToString(); |
| Terminal.m_testList["Music stopping"] = this.m_stopMusic.ToString(); |
| Terminal.m_testList["Music reset non continous"] = string.Format("{0} / {1}", this.m_resetMusicTimer, this.m_musicResetNonContinous); |
| Terminal.m_testList["Music reset non continous"] = string.Format("{0} / {1}", this.m_resetMusicTimer, this.m_musicResetNonContinous); |
| if (ZInput.GetKeyDown(KeyCode.N, true) && ZInput.GetKey(KeyCode.LeftShift, true) && this.m_musicSource != null && this.m_musicSource.isPlaying) |
| if (ZInput.GetKeyDown(KeyCode.N, true) && ZInput.GetKey(KeyCode.LeftShift, true) && this.m_musicSource != null && this.m_musicSource.isPlaying) |
| { |
| { |
| this.m_musicSource.time = this.m_musicSource.clip.length - 4f; |
| this.m_musicSource.time = this.m_musicSource.clip.length - 4f; |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void UpdateCombatMusic(float dt) |
| private void UpdateCombatMusic(float dt) |
| { |
| { |
| if (this.m_combatTimer > 0f) |
| if (this.m_combatTimer > 0f) |
| { |
| { |
| this.m_combatTimer -= Time.deltaTime; |
| this.m_combatTimer -= Time.deltaTime; |
| } |
| } |
| } |
| } |
| |
| |
| public void ResetCombatTimer() |
| public void ResetCombatTimer() |
| { |
| { |
| this.m_combatTimer = this.m_combatMusicTimeout; |
| this.m_combatTimer = this.m_combatMusicTimeout; |
| } |
| } |
| |
| |
| private bool InCombat() |
| private bool InCombat() |
| { |
| { |
| return this.m_combatTimer > 0f; |
| return this.m_combatTimer > 0f; |
| } |
| } |
| |
| |
| public void TriggerMusic(string name) |
| public void TriggerMusic(string name) |
| { |
| { |
| this.m_triggerMusic = name; |
| this.m_triggerMusic = name; |
| } |
| } |
| |
| |
| private bool StartMusic(string name) |
| private bool StartMusic(string name) |
| { |
| { |
| if (this.GetCurrentMusic() == name) |
| if (this.GetCurrentMusic() == name) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| MusicMan.NamedMusic namedMusic = this.FindMusic(name); |
| MusicMan.NamedMusic namedMusic = this.FindMusic(name); |
| return this.StartMusic(namedMusic); |
| return this.StartMusic(namedMusic); |
| } |
| } |
| |
| |
| private bool StartMusic(MusicMan.NamedMusic music) |
| private bool StartMusic(MusicMan.NamedMusic music) |
| { |
| { |
| if (music != null && this.GetCurrentMusic() == music.m_name) |
| if (music != null && this.GetCurrentMusic() == music.m_name) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| if (music == this.m_lastStartedMusic && !Settings.ContinousMusic && this.m_resetMusicTimer > 0f) |
| if (music == this.m_lastStartedMusic && !Settings.ContinousMusic && this.m_resetMusicTimer > 0f) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| this.m_lastStartedMusic = music; |
| this.m_lastStartedMusic = music; |
| this.m_resetMusicTimer = this.m_musicResetNonContinous + ((music != null && music.m_clips.Length != 0) ? music.m_clips[0].length : 0f); |
| this.m_resetMusicTimer = this.m_musicResetNonContinous + ((music != null && music.m_clips.Length != 0) ? music.m_clips[0].length : 0f); |
| if (music != null) |
| if (music != null) |
| { |
| { |
| this.m_queuedMusic = music; |
| this.m_queuedMusic = music; |
| this.m_stopMusic = false; |
| this.m_stopMusic = false; |
| ZLog.Log("Starting music " + music.m_name); |
| ZLog.Log("Starting music " + music.m_name); |
| return true; |
| return true; |
| } |
| } |
| this.StopMusic(); |
| this.StopMusic(); |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private MusicMan.NamedMusic FindMusic(string name) |
| private MusicMan.NamedMusic FindMusic(string name) |
| { |
| { |
| if (name == null || name.Length == 0) |
| if (name == null || name.Length == 0) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| foreach (MusicMan.NamedMusic namedMusic in this.m_music) |
| foreach (MusicMan.NamedMusic namedMusic in this.m_music) |
| { |
| { |
| if (namedMusic.m_name == name && namedMusic.m_enabled && namedMusic.m_clips.Length != 0 && namedMusic.m_clips[0]) |
| if (namedMusic.m_name == name && namedMusic.m_enabled && namedMusic.m_clips.Length != 0 && namedMusic.m_clips[0]) |
| { |
| { |
| return namedMusic; |
| return namedMusic; |
| } |
| } |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| public bool IsPlaying() |
| public bool IsPlaying() |
| { |
| { |
| return this.m_musicSource.isPlaying; |
| return this.m_musicSource.isPlaying; |
| } |
| } |
| |
| |
| private string GetCurrentMusic() |
| private string GetCurrentMusic() |
| { |
| { |
| if (this.m_stopMusic) |
| if (this.m_stopMusic) |
| { |
| { |
| return ""; |
| return ""; |
| } |
| } |
| if (this.m_queuedMusic != null) |
| if (this.m_queuedMusic != null) |
| { |
| { |
| return this.m_queuedMusic.m_name; |
| return this.m_queuedMusic.m_name; |
| } |
| } |
| if (this.m_currentMusic != null) |
| if (this.m_currentMusic != null) |
| { |
| { |
| return this.m_currentMusic.m_name; |
| return this.m_currentMusic.m_name; |
| } |
| } |
| return ""; |
| return ""; |
| } |
| } |
| |
| |
| private void StopMusic() |
| private void StopMusic() |
| { |
| { |
| this.m_queuedMusic = null; |
| this.m_queuedMusic = null; |
| this.m_stopMusic = true; |
| this.m_stopMusic = true; |
| } |
| } |
| |
| |
| public void Reset() |
| public void Reset() |
| { |
| { |
| this.StopMusic(); |
| this.StopMusic(); |
| this.m_combatTimer = 0f; |
| this.m_combatTimer = 0f; |
| this.m_randomEventMusic = null; |
| this.m_randomEventMusic = null; |
| this.m_triggerMusic = null; |
| this.m_triggerMusic = null; |
| this.m_locationMusic = null; |
| this.m_locationMusic = null; |
| } |
| } |
| |
| |
| private string m_triggeredMusic = ""; |
| private string m_triggeredMusic = ""; |
| |
| |
| private static MusicMan m_instance; |
| private static MusicMan m_instance; |
| |
| |
| public static float m_masterMusicVolume = 1f; |
| public static float m_masterMusicVolume = 1f; |
| |
| |
| public AudioMixerGroup m_musicMixer; |
| public AudioMixerGroup m_musicMixer; |
| |
| |
| public List<MusicMan.NamedMusic> m_music = new List<MusicMan.NamedMusic>(); |
| public List<MusicMan.NamedMusic> m_music = new List<MusicMan.NamedMusic>(); |
| |
| |
| public float m_musicResetNonContinous = 120f; |
| public float m_musicResetNonContinous = 120f; |
| |
| |
| [Header("Combat")] |
| [Header("Combat")] |
| public float m_combatMusicTimeout = 4f; |
| public float m_combatMusicTimeout = 4f; |
| |
| |
| [Header("Sailing")] |
| [Header("Sailing")] |
| public float m_sailMusicShipSpeedThreshold = 3f; |
| public float m_sailMusicShipSpeedThreshold = 3f; |
| |
| |
| public float m_sailMusicMinSailTime = 20f; |
| public float m_sailMusicMinSailTime = 20f; |
| |
| |
| [Header("Ambient music")] |
| [Header("Ambient music")] |
| public float m_randomMusicIntervalMin = 300f; |
| public float m_randomMusicIntervalMin = 300f; |
| |
| |
| public float m_randomMusicIntervalMax = 500f; |
| public float m_randomMusicIntervalMax = 500f; |
| |
| |
| private MusicMan.NamedMusic m_queuedMusic; |
| private MusicMan.NamedMusic m_queuedMusic; |
| |
| |
| private MusicMan.NamedMusic m_currentMusic; |
| private MusicMan.NamedMusic m_currentMusic; |
| |
| |
| private MusicMan.NamedMusic m_lastStartedMusic; |
| private MusicMan.NamedMusic m_lastStartedMusic; |
| |
| |
| private float m_musicVolume = 1f; |
| private float m_musicVolume = 1f; |
| |
| |
| private float m_musicFadeTime = 3f; |
| private float m_musicFadeTime = 3f; |
| |
| |
| private bool m_alwaysFadeout; |
| private bool m_alwaysFadeout; |
| |
| |
| private bool m_stopMusic; |
| private bool m_stopMusic; |
| |
| |
| private string m_randomEventMusic; |
| private string m_randomEventMusic; |
| |
| |
| private float m_lastAmbientMusicTime; |
| private float m_lastAmbientMusicTime; |
| |
| |
| private float m_randomAmbientInterval; |
| private float m_randomAmbientInterval; |
| |
| |
| private string m_triggerMusic; |
| private string m_triggerMusic; |
| |
| |
| private string m_locationMusic; |
| private string m_locationMusic; |
| |
| |
| public string m_lastLocationMusic; |
| public string m_lastLocationMusic; |
| |
| |
| private DateTime m_lastLocationMusicChange; |
| private DateTime m_lastLocationMusicChange; |
| |
| |
| public int m_repeatLocationMusicResetSeconds = 300; |
| public int m_repeatLocationMusicResetSeconds = 300; |
| |
| |
| private float m_combatTimer; |
| private float m_combatTimer; |
| |
| |
| private float m_resetMusicTimer; |
| private float m_resetMusicTimer; |
| |
| |
| private AudioSource m_musicSource; |
| private AudioSource m_musicSource; |
| |
| |
| private float m_currentMusicVol; |
| private float m_currentMusicVol; |
| |
| |
| public float m_currentMusicVolMax = 1f; |
| public float m_currentMusicVolMax = 1f; |
| |
| |
| private float m_sailDuration; |
| private float m_sailDuration; |
| |
| |
| private float m_notSailDuration; |
| private float m_notSailDuration; |
| . | |
| |
| |
| private float m_musicOnTopDuckVolume; |
| |
| |
| |
| private const string c_Duckmusic = "Music_ontop_ducking"; |
| |
| |
| [Serializable] |
| [Serializable] |
| public class NamedMusic |
| public class NamedMusic |
| { |
| { |
| public string m_name = ""; |
| public string m_name = ""; |
| |
| |
| public AudioClip[] m_clips; |
| public AudioClip[] m_clips; |
| |
| |
| public float m_volume = 1f; |
| public float m_volume = 1f; |
| |
| |
| public float m_fadeInTime = 3f; |
| public float m_fadeInTime = 3f; |
| |
| |
| public bool m_alwaysFadeout; |
| public bool m_alwaysFadeout; |
| |
| |
| public bool m_loop; |
| public bool m_loop; |
| |
| |
| public bool m_resume; |
| public bool m_resume; |
| |
| |
| public bool m_enabled = true; |
| public bool m_enabled = true; |
| |
| |
| public bool m_ambientMusic; |
| public bool m_ambientMusic; |
| |
| |
| [NonSerialized] |
| [NonSerialized] |
| public int m_savedPlaybackPos; |
| public int m_savedPlaybackPos; |
| |
| |
| [NonSerialized] |
| [NonSerialized] |
| public float m_lastPlayedTime; |
| public float m_lastPlayedTime; |
| } |
| } |
| } |
| } |
| |
| |