Esempio n. 1
0
        public void LoadAudioSet(AudioSet audioSet)
        {
            print($"Attempting to load AudioSet:{audioSet}");

            foreach (KeyValuePair <string, AudioClip> bgm in audioSet.BgmMap)
            {
                int hash = Animator.StringToHash(bgm.Key);

                if (bgmMap.ContainsKey(hash))
                {
                    throw new Exception($"The BGM key {bgm.Key} of audio set {audioSet.AudioSetName} is already loaded");
                }

                bgmMap.Add(hash, bgm.Value);
            }

            foreach (KeyValuePair <string, AudioClip> sfx in audioSet.SfxMap)
            {
                int hash = Animator.StringToHash(sfx.Key);

                if (sfxMap.ContainsKey(hash))
                {
                    throw new Exception($"The SFX key {sfx.Key} of audio set {audioSet.AudioSetName} is already loaded");
                }

                sfxMap.Add(hash, sfx.Value);
            }

            loadedAudioSets.Add(Animator.StringToHash(audioSet.AudioSetName), audioSet);

            print($"Successfully loaded AudioSet:{audioSet}");
        }
Esempio n. 2
0
        public void UnloadAudioSet(string audioSetName)
        {
            print($"Attempting to unload AudioSet:{audioSetName}");

            int hash = Animator.StringToHash(audioSetName);

            if (!loadedAudioSets.ContainsKey(hash))
            {
                throw new Exception($"Can't unload audio set with name {audioSetName}, it doesn't exist");
            }

            AudioSet audioSetToRemove = loadedAudioSets[hash];

            foreach (KeyValuePair <string, AudioClip> keyValuePair in audioSetToRemove.BgmMap)
            {
                bgmMap.Remove(Animator.StringToHash(keyValuePair.Key));
            }

            foreach (KeyValuePair <string, AudioClip> keyValuePair in audioSetToRemove.SfxMap)
            {
                sfxMap.Remove(Animator.StringToHash(keyValuePair.Key));
            }

            loadedAudioSets.Remove(hash);

            print($"Successfully unloaded AudioSet: {audioSetName}");
        }