public void SwitchMusic(AudioManager.ListenerInfo info) { Debug.Log("[CSLMusic] Switching music ..."); List <MusicEntry> entries = MusicManager.EnabledMusicEntries; if (entries.Count == 0) { Debug.Log("... cannot do this! There is no available music!"); return; } //Store previous music entry if (_currentMusic != null) { _previousMusic = _currentMusic; } //Set current music entry _currentMusic = _switchMusic_Requested_Music == null?GetNextMusic(entries) : _switchMusic_Requested_Music; _switchMusic_Requested_Music = null; //Reset requested //_switchMusic_Requested = false; UpdateMusic(info); Debug.Log("Now always enforcing " + _currentMusic.BaseName); }
private void UpdateAmbient(AudioManager.ListenerInfo listenerInfo, float listenerHeight) { if (!Singleton <LoadingManager> .instance.m_currentlyLoading && this.m_properties != null && this.m_properties.m_ambients != null && this.m_properties.m_ambients.Length != 0 && this.m_ambientGroup.m_totalVolume >= 0.01f) { float num = Mathf.Clamp01(listenerHeight * 0.001f) - 1f; num *= num; float num2 = Singleton <NaturalResourceManager> .instance.CalculateForestProximity(listenerInfo.m_position, 500f - num * 400f); float num3 = 0f; float num4 = Singleton <TerrainManager> .instance.CalculateWaterProximity(listenerInfo.m_position, 400f - num * 300f, out num3); Singleton <BuildingManager> .instance.CalculateServiceProximity(listenerInfo.m_position, 400f - num * 300f, this.m_serviceProximity, this.m_subServiceProximity); float volume = 1f - num; float volume2 = (num2 + this.m_subServiceProximity[6]) / (1f + listenerHeight * 0.002f); float volume3 = num4 * (1f - num3) / (1f + listenerHeight * 0.003f); float volume4 = num4 * num3 / (1f + listenerHeight * 0.003f); float volume5 = (this.m_subServiceProximity[5] + this.m_subServiceProximity[8] + this.m_subServiceProximity[9]) / (1f + listenerHeight * 0.004f); float volume6 = (this.m_serviceProximity[17] + this.m_serviceProximity[12]) / (1f + listenerHeight * 0.004f); float volume7 = (this.m_subServiceProximity[1] + this.m_subServiceProximity[3]) / (1f + listenerHeight * 0.004f); float volume8 = (this.m_subServiceProximity[2] + this.m_subServiceProximity[4] + this.m_serviceProximity[8]) / (1f + listenerHeight * 0.004f); float volume9 = this.m_subServiceProximity[7] / (1f + listenerHeight * 0.004f); this.m_ambientGroup.AddPlayer(0, this.m_properties.m_ambients[0], volume); this.m_ambientGroup.AddPlayer(1, this.m_properties.m_ambients[1], volume2); this.m_ambientGroup.AddPlayer(2, this.m_properties.m_ambients[2], volume3); this.m_ambientGroup.AddPlayer(3, this.m_properties.m_ambients[3], volume4); this.m_ambientGroup.AddPlayer(4, this.m_properties.m_ambients[4], volume5); this.m_ambientGroup.AddPlayer(5, this.m_properties.m_ambients[5], volume6); this.m_ambientGroup.AddPlayer(6, this.m_properties.m_ambients[6], volume7); this.m_ambientGroup.AddPlayer(7, this.m_properties.m_ambients[7], volume8); this.m_ambientGroup.AddPlayer(8, this.m_properties.m_ambients[8], volume9); } this.m_ambientGroup.UpdatePlayers(listenerInfo, (!this.m_muteAll) ? this.m_masterVolume : 0f); }
public override bool TagApplies(UnityEngine.GameObject gameObject, AudioManager.ListenerInfo info) { SettingsManager.Options ModOptions = gameObject.GetComponent <SettingsManager>().ModOptions; int finalHappiness = (int)Singleton <DistrictManager> .instance.m_districts.m_buffer[0].m_finalHappiness; return(finalHappiness < ModOptions.MoodDependentMusic_MoodThreshold); }
protected override void Awake() { base.Awake(); this.m_audioLocation = Path.Combine(DataLocation.gameContentPath, "Audio"); this.m_currentMusicFile = null; this.m_previousMusicFile = null; this.m_streamCrossFade = 0; this.m_listenerInfo = new AudioManager.ListenerInfo(); this.m_defaultGroup = new AudioGroup(3, new SavedFloat(Settings.uiAudioVolume, Settings.gameSettingsFile, DefaultSettings.uiAudioVolume, true)); this.m_ambientGroup = new AudioGroup(3, new SavedFloat(Settings.ambientAudioVolume, Settings.gameSettingsFile, DefaultSettings.ambientAudioVolume, true)); this.m_serviceProximity = new float[21]; this.m_subServiceProximity = new float[20]; this.m_eventBuffer = new FastList <AudioManager.SimulationEvent>(); this.m_mainAudioVolume = new SavedFloat(Settings.mainAudioVolume, Settings.gameSettingsFile, DefaultSettings.mainAudioVolume, true); this.m_musicAudioVolume = new SavedFloat(Settings.musicAudioVolume, Settings.gameSettingsFile, DefaultSettings.musicAudioVolume, true); this.m_tempBuffer1 = new byte[16384]; this.m_tempBuffer2 = new byte[16384]; this.m_streamBuffer = new float[65536]; this.m_streamLock = new object(); this.m_streamThread = new Thread(new ThreadStart(this.StreamThread)); this.m_streamThread.Name = "Music Stream"; this.m_streamThread.Priority = ThreadPriority.AboveNormal; this.m_streamThread.Start(); if (!this.m_streamThread.IsAlive) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Audio stream thread failed to start!"); } GameObject gameObject = new GameObject("Audio Listener"); Object.DontDestroyOnLoad(gameObject); this.m_audioListener = gameObject.AddComponent <AudioListener>(); this.m_audioListener.enabled = false; gameObject.AddComponent <MusicFilter>(); }
public void PlayAudio(AudioManager.ListenerInfo listenerInfo) { //Disable while loading if (!Singleton <LoadingManager> .instance.m_loadingComplete) { //May be annoying (stuttering while loading), so it can be disabled if (!ModOptions.MusicWhileLoading) { SwitchMusicToFile(null); } /////debug //SwitchMusicToFile(MusicManager.GetEntryByName("Pekka Kana 2 - Pekka Kana (256 kbit_s)").TagSongs[""][0]); return; } //After loading finished, switch only once if (!_firstTimeSwitched) { Debug.Log("[CSLMusic] Initial Music switch."); SwitchMusic(listenerInfo); _firstTimeSwitched = true; //Yay chirp //GameObject.GetComponent<MusicUI>().ChirpNowPlaying(_currentMusic); } //If user requests switch if (_switchMusic_Requested) { //MusicEntry _cur = _currentMusic; Debug.Log("[CSLMusic] User requested switch"); SwitchMusic(listenerInfo); _switchMusic_Requested = false; //Yay chirp //if (_currentMusic != _cur && _switchMusic_Requested_useChirpy) // GameObject.GetComponent<MusicUI>().ChirpNowPlaying(_currentMusic); } /** * CSL usually changes the music by mood and camera height. * Camera height can be easily dealt with (no problem) * * The problem is that there's no real "randomness" * * We are watching the current stream if available and if it reaches the end, we will replace * the current music file * */ UpdateAudioPlayer(listenerInfo); UpdateMusic(listenerInfo); }
private void UpdateAudioPlayer(AudioManager.ListenerInfo info) { /*if (CurrentMusicStream != null) * { * Debug.Log("Stream pos: " + CurrentMusicStream.Position + " / " + CurrentMusicStream.Length); * }*/ //Dont care if there is no 'should be' file if (String.IsNullOrEmpty(_currentMusic_File)) { return; } //Check if the requested music file is the current music file //Do nothing if this is not applying! if (_currentMusic_File != Singleton <AudioManager> .instance.m_currentMusicFile) { return; } //Do nothing while crossfading if (Singleton <AudioManager> .instance.m_previousMusicFile != null) { return; } //OK, CSLAudioWatcher and AudioManager are now synchronized if (CurrentMusicStream != _stream) { Debug.Log("[CSLMusic] Streams are different. Applying values."); //If the stream changed, apply the known values MessageManager.instance.QueueMessage(null); _stream = CurrentMusicStream; _streamLastKnownMaxPosition = _stream.Position; } else { //If the stream did not change, but jumped back, switch to new track //Otherwise update current position long pos = CurrentMusicStream.Position; if (pos < _streamLastKnownMaxPosition) { Debug.Log("[CSLMusic] Switch because stream " + pos + "/" + CurrentMusicStream.Length + " lk " + _streamLastKnownMaxPosition + " has restarted"); SwitchMusic(info); } else if (pos >= CurrentMusicStream.Length - ModOptions.MusicStreamSwitchTime) { Debug.Log("[CSLMusic] Switch because stream " + pos + "/" + CurrentMusicStream.Length + " lk " + _streamLastKnownMaxPosition + " is ending"); SwitchMusic(info); } else { _streamLastKnownMaxPosition = pos; } } }
protected override void PlayAudioImpl(AudioManager.ListenerInfo listenerInfo) { this.m_defaultGroup.UpdatePlayers(listenerInfo, this.m_masterVolume); float listenerHeight; if (this.m_properties != null && Singleton <LoadingManager> .instance.m_loadingComplete) { listenerHeight = Mathf.Max(0, listenerInfo.m_position.y - Singleton <TerrainManager> .instance.SampleRawHeightSmoothWithWater(listenerInfo.m_position, true, 0)); } else { listenerHeight = 0; } this.UpdateAmbient(listenerInfo, listenerHeight); this.UpdateMusic(listenerInfo, listenerHeight); }
private void UpdateAmbient(AudioManager.ListenerInfo listenerInfo, float listenerHeight) { if (!Singleton <LoadingManager> .instance.m_currentlyLoading && this.m_properties != null && this.m_properties.m_ambients != null && this.m_properties.m_ambients.Length != 0 && this.m_ambientGroup.m_totalVolume >= 0, 01) { float num = Mathf.Clamp01(listenerHeight * 0, 001) - 1; num *= num; float num2 = Singleton <NaturalResourceManager> .instance.CalculateForestProximity(listenerInfo.m_position, 500 - num * 400); float num3 = 0; float num4 = Singleton <TerrainManager> .instance.CalculateWaterProximity(listenerInfo.m_position, 400 - num * 300, out num3); Singleton <BuildingManager> .instance.CalculateServiceProximity(listenerInfo.m_position, 400 - num * 300, this.m_serviceProximity, this.m_subServiceProximity); float volume = 1 - num; float volume2 = (num2 + this.m_subServiceProximity[6]) / (1 + listenerHeight * 0, 002); float volume3 = num4 * (1 - num3) / (1 + listenerHeight * 0, 003); float volume4 = num4 * num3 / (1 + listenerHeight * 0, 003); float volume5 = (this.m_subServiceProximity[5] + this.m_subServiceProximity[8] + this.m_subServiceProximity[9]) / (1 + listenerHeight * 0, 004); float volume6 = (this.m_serviceProximity[17] + this.m_serviceProximity[12]) / (1 + listenerHeight * 0, 004); float volume7 = (this.m_subServiceProximity[1] + this.m_subServiceProximity[3]) / (1 + listenerHeight * 0, 004); float volume8 = (this.m_subServiceProximity[2] + this.m_subServiceProximity[4] + this.m_serviceProximity[8]) / (1 + listenerHeight * 0, 004); float volume9 = this.m_subServiceProximity[7] / (1 + listenerHeight * 0, 004); float volume10 = this.m_subServiceProximity[18] / (1 + listenerHeight * 0, 004); float volume11 = this.m_subServiceProximity[19] / (1 + listenerHeight * 0, 004); AudioInfo[] array; if (Singleton <SimulationManager> .instance.m_isNightTime && this.m_properties.m_ambientsNight != null && this.m_properties.m_ambientsNight.Length != 0) { array = this.m_properties.m_ambientsNight; } else { array = this.m_properties.m_ambients; } this.m_ambientGroup.AddPlayer(0, array[0], volume); this.m_ambientGroup.AddPlayer(1, array[1], volume2); this.m_ambientGroup.AddPlayer(2, array[2], volume3); this.m_ambientGroup.AddPlayer(3, array[3], volume4); this.m_ambientGroup.AddPlayer(4, array[4], volume5); this.m_ambientGroup.AddPlayer(5, array[5], volume6); this.m_ambientGroup.AddPlayer(6, array[6], volume7); this.m_ambientGroup.AddPlayer(7, array[7], volume8); this.m_ambientGroup.AddPlayer(8, array[8], volume9); this.m_ambientGroup.AddPlayer(9, array[9], volume10); this.m_ambientGroup.AddPlayer(10, array[10], volume11); } this.m_ambientGroup.UpdatePlayers(listenerInfo, (!this.m_muteAll) ? this.m_masterVolume : 0); }
private float GetListenerHeight(AudioManager.ListenerInfo listenerInfo) { if (listenerInfo == null) { return(0f); } float listenerHeight; if (Singleton <AudioManager> .instance.m_properties != null && Singleton <LoadingManager> .instance.m_loadingComplete) { listenerHeight = Mathf.Max(0f, listenerInfo.m_position.y - Singleton <TerrainManager> .instance.SampleRawHeightSmoothWithWater(listenerInfo.m_position, true, 0f)); } else { listenerHeight = 0f; } return(listenerHeight); }
public void UpdateMusic(AudioManager.ListenerInfo info) { if (_currentMusic == null) { return; } //Determine the actual music file String musicFile = _currentMusic.GetMatchingMusic(info); if (musicFile != null) { SwitchMusicToFile(musicFile); } else { //The music file does not contain anything interesting, so switch to the next music RequestSwitchMusic(); } }
virtual void PlayAudio(AudioManager.ListenerInfo listenerInfo) { base.PlayAudio(listenerInfo); }
public override bool TagApplies(UnityEngine.GameObject gameObject, AudioManager.ListenerInfo info) { return(Singleton <SimulationManager> .instance.m_isNightTime); }
public override bool TagApplies(UnityEngine.GameObject gameObject, AudioManager.ListenerInfo info) { return(true); }
public override void PlayEffect(InstanceID id, SpawnArea area, Vector3 velocity, float acceleration, float magnitude, AudioManager.ListenerInfo listenerInfo, AudioGroup audioGroup) { if (velocity.magnitude >= m_params.m_minSpeed && velocity.magnitude <= m_params.m_maxSpeed) { area.m_matrix = area.m_matrix * Matrix4x4.TRS(m_params.m_position, Quaternion.LookRotation(m_params.m_direction), Vector3.one); m_wrappedEffect.PlayEffect(id, area, velocity, acceleration, magnitude, listenerInfo, audioGroup); } }
public override void PlayEffect(InstanceID id, SpawnArea area, Vector3 velocity, float acceleration, float magnitude, AudioManager.ListenerInfo listenerInfo, AudioGroup audioGroup) { this.velocity = velocity.magnitude; if (velocity.magnitude >= m_params.m_minSpeed && velocity.magnitude <= m_params.m_maxSpeed) { base.PlayEffect(id, area, velocity, acceleration, magnitude, listenerInfo, audioGroup); } }
public override bool TagApplies(UnityEngine.GameObject gameObject, AudioManager.ListenerInfo info) { SettingsManager.Options ModOptions = gameObject.GetComponent <SettingsManager>().ModOptions; return(GetListenerHeight(info) > ModOptions.HeightDependentMusic_HeightThreshold); }
private void UpdateMusic(AudioManager.ListenerInfo listenerInfo, float listenerHeight) { if (!Singleton <LoadingManager> .instance.m_currentlyLoading) { if (this.m_musicVolume < 0, 01) { this.m_musicFile = null; } else { if (this.m_musicFiles != null && this.m_musicFiles.Length != 0) { string[] array = this.m_musicFiles; AudioManager.MusicType musicType = AudioManager.MusicType.Worst; if (this.isAfterDarkMenu) { musicType = AudioManager.MusicType.Normal; } if (this.isShowingCredits) { musicType = AudioManager.MusicType.Bad; } if (Singleton <LoadingManager> .instance.m_loadingComplete) { if (Singleton <SimulationManager> .instance.m_isNightTime && this.m_musicFilesNight != null && this.m_musicFilesNight.Length != 0) { array = this.m_musicFilesNight; } int finalHappiness = (int)Singleton <DistrictManager> .instance.m_districts.m_buffer[0].m_finalHappiness; if (finalHappiness < 25) { musicType = AudioManager.MusicType.Worst; } else { if (finalHappiness < 40) { musicType = AudioManager.MusicType.Bad; } else { if (finalHappiness < 55) { musicType = AudioManager.MusicType.Normal; } else { if (finalHappiness < 70) { musicType = AudioManager.MusicType.Good; } else { if (finalHappiness < 85) { musicType = AudioManager.MusicType.VeryWell; } else { if (finalHappiness < 95) { musicType = AudioManager.MusicType.NearWonder; } else { musicType = AudioManager.MusicType.AlmostWonder; } } } } } } if (listenerHeight > 1400) { musicType += 7; } } int num = Mathf.Min((int)musicType, array.Length - 1); this.m_musicFile = array[num]; } } }
private void UpdateMusic(AudioManager.ListenerInfo listenerInfo, float listenerHeight) { if (!Singleton <LoadingManager> .instance.m_currentlyLoading) { if (this.m_musicVolume < 0.01f) { this.m_musicFile = null; } else { if (this.m_musicFiles != null && this.m_musicFiles.Length != 0) { AudioManager.MusicType musicType = (!this.isShowingCredits) ? AudioManager.MusicType.Worst : AudioManager.MusicType.Bad; if (Singleton <LoadingManager> .instance.m_loadingComplete) { int finalHappiness = (int)Singleton <DistrictManager> .instance.m_districts.m_buffer[0].m_finalHappiness; if (finalHappiness < 25) { musicType = AudioManager.MusicType.Worst; } else { if (finalHappiness < 40) { musicType = AudioManager.MusicType.Bad; } else { if (finalHappiness < 55) { musicType = AudioManager.MusicType.Normal; } else { if (finalHappiness < 70) { musicType = AudioManager.MusicType.Good; } else { if (finalHappiness < 85) { musicType = AudioManager.MusicType.VeryWell; } else { if (finalHappiness < 95) { musicType = AudioManager.MusicType.NearWonder; } else { musicType = AudioManager.MusicType.AlmostWonder; } } } } } } if (listenerHeight > 1400f) { musicType += 7; } } int num = Mathf.Min((int)musicType, this.m_musicFiles.Length - 1); this.m_musicFile = this.m_musicFiles[num]; } } } }
/** * Gets the best matching music according to selection algorithm * */ public String GetMatchingMusic(AudioManager.ListenerInfo info) { String song = null; bool sel_and = GameObject.GetComponent <SettingsManager>().ModOptions.MusicSelectionAlgorithm == SettingsManager.Options.MusicSelectionType.AND; { var all_tags = GameObject.GetComponent <MusicManager>().MusicTagTypes.Values; //Determine which tags are now applicable foreach (var tag in all_tags) { if (tag.TagApplies(GameObject, info)) { __applicableTags[tag.Name] = true; } else { __applicableTags[tag.Name] = false; } } //Determine the score of each tag var tag_priority = GameObject.GetComponent <SettingsManager>().ModOptions.MusicTagTypePriority; for (int i = 0; i < tag_priority.Count; i++) { var tagname = tag_priority[i]; __tagScore[tagname] = tag_priority.Count - i + 1; } //Find all songs that apply according to selection type // Find with most priority score int best_score = 0; foreach (var kv in SongTags) { var applicable = true; var currentsong = kv.Key; foreach (var tagname in kv.Value) { if (sel_and) { applicable &= __applicableTags[tagname]; } else { applicable |= __applicableTags[tagname]; } } if (applicable) { // Determine the score; if better -> set to new song int score = 0; foreach (var tag in kv.Value) { score += __tagScore[tag]; } if (score > best_score) { song = currentsong; best_score = score; } } } } if (song != null) { return(song); } //Select the "default" tag song if available if (TagSongs.ContainsKey("") && TagSongs[""].Count != 0) { return(TagSongs[""][0]); } return(null); }
/** * Returns if this tag applies to the current game situation * */ public abstract bool TagApplies(GameObject gameObject, AudioManager.ListenerInfo info);