Beispiel #1
0
    public SoundManager()
    {
        Instance = this;
        goHelper = new GameObject();
        goHelper.AddComponent <SoundManagerHelper>();

        if (!dicSoundGroups.ContainsKey(MUSIC_GROUP_KEY))
        {
            SoundGroup musicGroup = new SoundGroup(MUSIC_GROUP_KEY, audioMixer == null ? null : audioMixer.FindMatchingGroups("BGM")[0]);
            dicSoundGroups[MUSIC_GROUP_KEY] = musicGroup;
            musicGroup.Volume = MusicVolume;
            musicGroup.Mute   = MusicMute;
            musicGroup.AddSoundAgentHelper(goHelper.transform);
        }
        if (!dicSoundGroups.ContainsKey(SOUND_GROUP_KEY))
        {
            SoundGroup soundGroup = new SoundGroup(SOUND_GROUP_KEY, audioMixer == null ? null : audioMixer.FindMatchingGroups("Sound")[0]);
            dicSoundGroups[SOUND_GROUP_KEY] = soundGroup;
            soundGroup.AddSoundAgentHelper(goHelper.transform);
            soundGroup.AddSoundAgentHelper(goHelper.transform);
            soundGroup.AddSoundAgentHelper(goHelper.transform);
        }
        if (!dicSoundGroups.ContainsKey(VOICE_GROUP_KEY))
        {
            SoundGroup voiceGroup = new SoundGroup(VOICE_GROUP_KEY, audioMixer == null ? null : audioMixer.FindMatchingGroups("Voice")[0]);
            dicSoundGroups[VOICE_GROUP_KEY] = voiceGroup;
            voiceGroup.AddSoundAgentHelper(goHelper.transform);
        }
        Messenger.AddListener <int>(MessageId.SOUND_STOPED, OnSoundStoped);
    }
        /// <summary>
        /// 增加声音代理辅助器。
        /// </summary>
        /// <param name="soundGroupName">声音组名称。</param>
        /// <param name="soundAgentHelper">要增加的声音代理辅助器。</param>
        public void AddSoundAgentHelper(string soundGroupName, ISoundAgentHelper soundAgentHelper)
        {
            if (m_SoundHelper == null)
            {
                throw new GameFrameworkException("You must set sound helper first.");
            }

            SoundGroup soundGroup = (SoundGroup)GetSoundGroup(soundGroupName);

            if (soundGroup == null)
            {
                throw new GameFrameworkException(Utility.Text.Format("Sound group '{0}' is not exist.", soundGroupName));
            }

            soundGroup.AddSoundAgentHelper(m_SoundHelper, soundAgentHelper);
        }