예제 #1
0
        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);
        }
예제 #2
0
        public void RequestSwitchMusic(MusicEntry entry)
        {
            Debug.Log("[CSLMusic] Requested to switch music.");

            _switchMusic_Requested       = true;
            _switchMusic_Requested_Music = entry;
            //_switchMusic_Requested_useChirpy = chirp;
        }
예제 #3
0
        private void __Playback(String file, MusicEntry entry)
        {
            if (_currentFile == file)
            {
                return;
            }

            ensureAudioSources();

            _currentFile   = file;
            _previousEntry = _currentEntry;
            _currentEntry  = entry;

            Debug.Log("[CSLMusicMod] BackgroundMusicPlayer got " + file);

            _requestedClip = null;
            StartCoroutine(_GetAudioClip(file, new Action <AudioClip>((clip) =>
            {
                Debug.Log("... " + clip.samples + " samples are in AudioClip");

                _requestedClip = null;

                if (_currentClip == null)
                {
                    StopAndPlay(clip);
                }
                else
                {
                    if (_previousEntry == _currentEntry && (ModOptions.IgnoreCrossfadeLimit || Math.Abs(_currentClip.samples - clip.samples) <= ModOptions.CrossfadeLimit))
                    {
                        CrossfadeTo(clip, true);
                    }
                    else
                    {
                        StopAndPlay(clip);
                    }
                }
            })));

            /*var clip = GetAudioClip(file);
             *
             * Debug.Log("... " + clip.samples + " samples are in AudioClip");
             *
             * _requestedClip = null;
             *
             * if (_currentClip == null || Math.Abs(_currentClip.samples - clip.samples) > 1024)
             * {
             *  //New track
             *  StopAndPlay(clip);
             *  //CrossfadeTo(clip, true);
             * }
             * else
             * {
             *  //Xover track
             *  CrossfadeTo(clip, true);
             * }*/
        }
예제 #4
0
        public void Playback(String file, MusicEntry entry)
        {
            if (_currentFile == file)
            {
                return;
            }

            _playback_req       = file;
            _playback_req_entry = entry;
        }
예제 #5
0
        private bool AddUnknownMusicFiles(String folder, ref bool mood_entries_not_found)
        {
            bool foundsomething = false;

            /**
             *
             * Note: Must convert before running!
             *
             * update 4: added option to directly play ogg vorbis
             *
             * */

            Debug.Log("[CSLMusic] Fetching unknown music files from " + folder + " ...");

            foreach (String file in Directory.GetFiles(folder))
            {
                if (!ModOptions.PlayWithoutConvert && Path.GetExtension(file) != ".raw")
                {
                    continue;
                }
                if (Path.GetExtension(file) != ".raw" && !ModOptions.SupportedNonRawFileFormats.Contains(Path.GetExtension(file)))
                {
                    continue;
                }
                if (MusicFileKnown(file))
                {
                    continue;
                }

                String baseName = GetCustomMusicBaseName(file);

                // If necessary create the entry
                MusicEntry entry = GetEntryByName(baseName);

                if (entry == null)
                {
                    entry = new MusicEntry(true, gameObject, baseName);
                    MusicEntries.Add(entry);

                    foundsomething = true;
                }

                entry.AddSong(file);
            }

            Debug.Log("... done");

            return(foundsomething);
        }
예제 #6
0
        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);
        }
예제 #7
0
        public void RequestSwitchMusic(MusicEntry entry)
        {
            Debug.Log("[CSLMusic] Requested to switch music.");

            _switchMusic_Requested = true;
            _switchMusic_Requested_Music = entry;
            //_switchMusic_Requested_useChirpy = chirp;
        }
예제 #8
0
        private void __Playback(String file, MusicEntry entry)
        {
            if (_currentFile == file)
                return;

            ensureAudioSources();

            _currentFile = file;
            _previousEntry = _currentEntry;
            _currentEntry = entry;

            Debug.Log("[CSLMusicMod] BackgroundMusicPlayer got " + file);

            _requestedClip = null;
            StartCoroutine(_GetAudioClip(file, new Action<AudioClip>((clip) =>
                        {
                            Debug.Log("... " + clip.samples + " samples are in AudioClip");

                            _requestedClip = null;

                            if (_currentClip == null)
                            {
                                StopAndPlay(clip);

                            }
                            else
                            {
                                if (_previousEntry == _currentEntry && (ModOptions.IgnoreCrossfadeLimit || Math.Abs(_currentClip.samples - clip.samples) <= ModOptions.CrossfadeLimit))
                                {
                                    CrossfadeTo(clip, true);
                                }
                                else
                                {
                                    StopAndPlay(clip);
                                }
                            }
                        })));

            /*var clip = GetAudioClip(file);

            Debug.Log("... " + clip.samples + " samples are in AudioClip");

            _requestedClip = null;

            if (_currentClip == null || Math.Abs(_currentClip.samples - clip.samples) > 1024)
            {
                //New track
                StopAndPlay(clip);
                //CrossfadeTo(clip, true);
            }
            else
            {
                //Xover track
                CrossfadeTo(clip, true);
            }*/
        }
예제 #9
0
        public void Update()
        {
            if (_mainAudioSource == null || _helperAudioSource == null)
                return;

            switch (CurrentState)
            {
                case State.Playing:
                    // Increase or decrease volume until it is the same
                    if (_mainAudioSource.volume < FinalVolume)
                    {
                        var volume2 = Math.Min(FinalVolume, _mainAudioSource.volume + VolumeModifier_Switch);
                        _mainAudioSource.volume = volume2;

                        if (volume2 < FinalVolume)
                            Debug.Log("[CSLMusicMod] Increasing volume of Playing state to " + volume2);
                    }
                    else
                    {
                        var volume2 = Math.Max(FinalVolume, _mainAudioSource.volume - VolumeModifier_Switch);
                        _mainAudioSource.volume = volume2;

                        if (volume2 < FinalVolume)
                            Debug.Log("[CSLMusicMod] Decreasing volume of Playing state to " + volume2);
                    }

                    //Is the music finished?
                    if (!_mainAudioSource.isPlaying)
                    {
                        Debug.Log("[CSLMusicMod] Playback finished.");
                        ImmediatelyStopPlayback();

                        if (_playback_req == null)
                        {
                            AudioWatcher.RequestSwitchMusic();
                        }
                        else
                        {
                            Debug.Log("[CSLMusicMod] Playback finished. Not requesting a new song as a song is in queue.");
                        }
                    }

                    if (_playback_req != null)
                    {
                        __Playback(_playback_req, _playback_req_entry);
                        _playback_req_entry = null;
                        _playback_req = null;
                    }

                    break;
                case State.Stopping:

                    // Decrease main audio volume and go to "stopped" if volume is 0
                    var volume = Math.Max(0f, _mainAudioSource.volume - VolumeModifier_Switch);

                    _mainAudioSource.volume = volume;

                    if (volume <= 0)
                    {
                        _currentClip = null;
                        CurrentState = State.Stopped;
                        Debug.Log("[CSLMusicMod] Stopping finished.");
                    }

                    break;
                case State.Stopped:

                    // If stopping has ended, play the requested clip
                    if (_requestedClip != null)
                    {
                        StopAndPlay(_requestedClip);
                    }
                    else if (_playback_req != null)
                    {
                        __Playback(_playback_req, _playback_req_entry);
                        _playback_req = null;
                        _playback_req_entry = null;
                    }

                    break;

                case State.Crossfading:

                    // Decrease main audio volume and go to "stopped" if volume is 0
                    {
                        var volume1 = Math.Max(0f, _helperAudioSource.volume - VolumeModifier_Crossover);
                        _helperAudioSource.volume = volume1;
                        var volume2 = Math.Min(FinalVolume, _mainAudioSource.volume + VolumeModifier_Crossover);
                        _mainAudioSource.volume = volume2;

                        //x-fade into "Playing" state
                        if (volume1 <= 0 && volume2 >= FinalVolume)
                        {
                            CurrentState = State.Playing;
                            Debug.Log("[CSLMusicMod] Crossfading finished.");
                        }
                    }
                    break;
            }
        }
예제 #10
0
        public void Playback(String file, MusicEntry entry)
        {
            if (_currentFile == file)
                return;

            _playback_req = file;
            _playback_req_entry = entry;
        }
예제 #11
0
        public void Update()
        {
            if (_mainAudioSource == null || _helperAudioSource == null)
            {
                return;
            }

            switch (CurrentState)
            {
            case State.Playing:
                // Increase or decrease volume until it is the same
                if (_mainAudioSource.volume < FinalVolume)
                {
                    var volume2 = Math.Min(FinalVolume, _mainAudioSource.volume + VolumeModifier_Switch);
                    _mainAudioSource.volume = volume2;

                    if (volume2 < FinalVolume)
                    {
                        Debug.Log("[CSLMusicMod] Increasing volume of Playing state to " + volume2);
                    }
                }
                else
                {
                    var volume2 = Math.Max(FinalVolume, _mainAudioSource.volume - VolumeModifier_Switch);
                    _mainAudioSource.volume = volume2;

                    if (volume2 < FinalVolume)
                    {
                        Debug.Log("[CSLMusicMod] Decreasing volume of Playing state to " + volume2);
                    }
                }

                //Is the music finished?
                if (!_mainAudioSource.isPlaying)
                {
                    Debug.Log("[CSLMusicMod] Playback finished.");
                    ImmediatelyStopPlayback();

                    if (_playback_req == null)
                    {
                        AudioWatcher.RequestSwitchMusic();
                    }
                    else
                    {
                        Debug.Log("[CSLMusicMod] Playback finished. Not requesting a new song as a song is in queue.");
                    }
                }

                if (_playback_req != null)
                {
                    __Playback(_playback_req, _playback_req_entry);
                    _playback_req_entry = null;
                    _playback_req       = null;
                }

                break;

            case State.Stopping:

                // Decrease main audio volume and go to "stopped" if volume is 0
                var volume = Math.Max(0f, _mainAudioSource.volume - VolumeModifier_Switch);

                _mainAudioSource.volume = volume;

                if (volume <= 0)
                {
                    _currentClip = null;
                    CurrentState = State.Stopped;
                    Debug.Log("[CSLMusicMod] Stopping finished.");
                }

                break;

            case State.Stopped:

                // If stopping has ended, play the requested clip
                if (_requestedClip != null)
                {
                    StopAndPlay(_requestedClip);
                }
                else if (_playback_req != null)
                {
                    __Playback(_playback_req, _playback_req_entry);
                    _playback_req       = null;
                    _playback_req_entry = null;
                }

                break;

            case State.Crossfading:

                // Decrease main audio volume and go to "stopped" if volume is 0
            {
                var volume1 = Math.Max(0f, _helperAudioSource.volume - VolumeModifier_Crossover);
                _helperAudioSource.volume = volume1;
                var volume2 = Math.Min(FinalVolume, _mainAudioSource.volume + VolumeModifier_Crossover);
                _mainAudioSource.volume = volume2;

                //x-fade into "Playing" state
                if (volume1 <= 0 && volume2 >= FinalVolume)
                {
                    CurrentState = State.Playing;
                    Debug.Log("[CSLMusicMod] Crossfading finished.");
                }
            }
            break;
            }
        }
예제 #12
0
        private bool AddUnknownVanillaMusicFiles(ref bool mood_entries_not_found)
        {
            bool foundsomething = false;
            mood_entries_not_found = false;

            String audioFileLocation = ReflectionHelper.GetPrivateField<String>(
                                           Singleton<AudioManager>.instance, "m_audioLocation");

            Debug.Log("[CSLMusic] Fetching unknown vanilla music files ...");

            //Get good music
            foreach (String file in Directory.GetFiles(audioFileLocation))
            {
                if (Path.GetExtension(file) != ".raw") //Vanilla music is always *.raw
                    continue;
                if (MusicFileKnown(file))
                    continue;

                String baseName = GetVanillaMusicBaseName(file);

                Debug.Log("[CSLMusicMod] Vanilla music base name: \"" + baseName + "\" <- " + file);

                //After Dark Music
                bool after_dark = false;
                if (baseName.StartsWith("After Dark") && baseName != "After Dark Menu")
                {
                    after_dark = true;
                    baseName = baseName.Replace("After Dark", "Colossal Style");

                    Debug.Log("[CSLMusicMod] AfterDark override: " + baseName + " to Colossal Style#night");
                    baseName = baseName.Replace("After Dark", "Colossal Style");
                }

                // Translate names to OST original names
                switch (baseName)
                {
                    case "Colossal Menu":
                        baseName = "Cities: Skylines - Main Theme";
                        break;
                    case "After Dark Menu":
                        baseName = "Cities: Skylines - Main Theme (After Dark)";
                        break;
                    case "Colossal Style 1":
                        baseName = "Cities: Skylines - Stern Berger";
                        break;
                    case "Colossal Style 2":
                        baseName = "Cities: Skylines - Burned Bean Coffee";
                        break;
                    case "Colossal Style 3":
                        baseName = "Cities: Skylines - AUKIO";
                        break;
                    case "Colossal Style 4":
                        baseName = "Cities: Skylines - Itsy Bitsy Critter";
                        break;
                    case "Colossal Style 5":
                        baseName = "Cities: Skylines - Dino Oil";
                        break;
                }

                MusicEntry entry = GetEntryByName(baseName);

                if (entry == null)
                {
                    if (baseName == "Cities: Skylines - Main Theme" || baseName == "Cities: Skylines - Main Theme (After Dark)")
                        entry = new MusicEntry(false, gameObject, baseName);
                    else
                        entry = new MusicEntry(true, gameObject, baseName);

                    MusicEntries.Add(entry);
                }

                //Add the vanilla music according to the vanilla annotation
                String file_noext = Path.GetFileNameWithoutExtension(file);

                if (after_dark)
                {
                    //This is afterdark music: add it as #night
                    if (file_noext.EndsWith("b"))
                        entry.AddSong(file, "bad", "night");
                    else if (file_noext.EndsWith("s"))
                        entry.AddSong(file, "sky", "night");
                    else
                        entry.AddSong(file, "night");
                }
                else
                {
                    if (file_noext.EndsWith("b"))
                        entry.AddSong(file, "bad");
                    else if (file_noext.EndsWith("s"))
                        entry.AddSong(file, "sky");
                    else
                        entry.AddSong(file, "");
                }

                foundsomething = true;
            }

            Debug.Log("... done");

            return foundsomething;
        }
예제 #13
0
        private bool AddUnknownMusicFiles(String folder, ref bool mood_entries_not_found)
        {
            bool foundsomething = false;

            /**
             *
             * Note: Must convert before running!
             *
             * update 4: added option to directly play ogg vorbis
             *
             * */

            Debug.Log("[CSLMusic] Fetching unknown music files from " + folder + " ...");

            foreach (String file in Directory.GetFiles(folder))
            {
                if (!ModOptions.PlayWithoutConvert && Path.GetExtension(file) != ".raw")
                    continue;
                if (Path.GetExtension(file) != ".raw" && !ModOptions.SupportedNonRawFileFormats.Contains(Path.GetExtension(file)))
                    continue;
                if (MusicFileKnown(file))
                    continue;

                String baseName = GetCustomMusicBaseName(file);

                // If necessary create the entry
                MusicEntry entry = GetEntryByName(baseName);

                if (entry == null)
                {
                    entry = new MusicEntry(true, gameObject, baseName);
                    MusicEntries.Add(entry);

                    foundsomething = true;
                }

                entry.AddSong(file);
            }

            Debug.Log("... done");

            return foundsomething;
        }
예제 #14
0
        private bool AddUnknownVanillaMusicFiles(ref bool mood_entries_not_found)
        {
            bool foundsomething = false;

            mood_entries_not_found = false;

            String audioFileLocation = ReflectionHelper.GetPrivateField <String>(
                Singleton <AudioManager> .instance, "m_audioLocation");

            Debug.Log("[CSLMusic] Fetching unknown vanilla music files ...");

            //Get good music
            foreach (String file in Directory.GetFiles(audioFileLocation))
            {
                if (Path.GetExtension(file) != ".raw") //Vanilla music is always *.raw
                {
                    continue;
                }
                if (MusicFileKnown(file))
                {
                    continue;
                }

                String baseName = GetVanillaMusicBaseName(file);

                Debug.Log("[CSLMusicMod] Vanilla music base name: \"" + baseName + "\" <- " + file);

                //After Dark Music
                bool after_dark = false;
                if (baseName.StartsWith("After Dark") && baseName != "After Dark Menu")
                {
                    after_dark = true;
                    baseName   = baseName.Replace("After Dark", "Colossal Style");

                    Debug.Log("[CSLMusicMod] AfterDark override: " + baseName + " to Colossal Style#night");
                    baseName = baseName.Replace("After Dark", "Colossal Style");
                }

                // Translate names to OST original names
                switch (baseName)
                {
                case "Colossal Menu":
                    baseName = "Cities: Skylines - Main Theme";
                    break;

                case "After Dark Menu":
                    baseName = "Cities: Skylines - Main Theme (After Dark)";
                    break;

                case "Colossal Style 1":
                    baseName = "Cities: Skylines - Stern Berger";
                    break;

                case "Colossal Style 2":
                    baseName = "Cities: Skylines - Burned Bean Coffee";
                    break;

                case "Colossal Style 3":
                    baseName = "Cities: Skylines - AUKIO";
                    break;

                case "Colossal Style 4":
                    baseName = "Cities: Skylines - Itsy Bitsy Critter";
                    break;

                case "Colossal Style 5":
                    baseName = "Cities: Skylines - Dino Oil";
                    break;
                }

                MusicEntry entry = GetEntryByName(baseName);

                if (entry == null)
                {
                    if (baseName == "Cities: Skylines - Main Theme" || baseName == "Cities: Skylines - Main Theme (After Dark)")
                    {
                        entry = new MusicEntry(false, gameObject, baseName);
                    }
                    else
                    {
                        entry = new MusicEntry(true, gameObject, baseName);
                    }

                    MusicEntries.Add(entry);
                }

                //Add the vanilla music according to the vanilla annotation
                String file_noext = Path.GetFileNameWithoutExtension(file);

                if (after_dark)
                {
                    //This is afterdark music: add it as #night
                    if (file_noext.EndsWith("b"))
                    {
                        entry.AddSong(file, "bad", "night");
                    }
                    else if (file_noext.EndsWith("s"))
                    {
                        entry.AddSong(file, "sky", "night");
                    }
                    else
                    {
                        entry.AddSong(file, "night");
                    }
                }
                else
                {
                    if (file_noext.EndsWith("b"))
                    {
                        entry.AddSong(file, "bad");
                    }
                    else if (file_noext.EndsWith("s"))
                    {
                        entry.AddSong(file, "sky");
                    }
                    else
                    {
                        entry.AddSong(file, "");
                    }
                }

                foundsomething = true;
            }

            Debug.Log("... done");

            return(foundsomething);
        }