Exemple #1
0
        public SoundGroup(string name, SoundGroupHelperBase soundGroupHelper)
        {
            if (string.IsNullOrEmpty(name))
            {
                Debug.LogError("用来构造声音组对象的名称为空");
            }

            if (soundGroupHelper == null)
            {
                Debug.LogError("用来构造声音组对象的声音组辅助器为空");
            }

            Name          = name;
            Helper        = soundGroupHelper;
            m_SoundAgents = new List <SoundAgent>();
        }
Exemple #2
0
        /// <summary>
        /// 增加声音代理辅助器
        /// </summary>
        /// <param name="soundGroupName">声音组名称</param>
        /// <param name="soundGroupHelper">声音组辅助器</param>
        /// <param name="index">声音代理辅助器索引</param>
        /// <returns>是否增加声音代理辅助器成功</returns>
        private bool AddSoundAgentHelper(string soundGroupName, SoundGroupHelperBase soundGroupHelper, int index)
        {
            if (m_SoundHelper == null)
            {
                Debug.LogError("添加声音代理辅助器时声音辅助器为空");
                return(false);
            }

            //获取声音组
            SoundGroup soundGroup = GetSoundGroup(soundGroupName);

            if (soundGroup == null)
            {
                Debug.LogError("添加声音代理辅助器时声音组为空");
                return(false);
            }

            //创建声音代理辅助器
            SoundAgentHelperBase soundAgentHelper = new GameObject().AddComponent <DefaultSoundAgentHelper>();

            soundAgentHelper.name = string.Format("Sound Agent Helper - {0} - {1}", soundGroupName, index.ToString());
            soundAgentHelper.transform.SetParent(soundGroupHelper.transform);

            //设置声音代理辅助器的混音组
            if (m_AudioMixer != null)
            {
                AudioMixerGroup[] audioMixerGroups = m_AudioMixer.FindMatchingGroups(string.Format("Master/{0}/{1}", soundGroupName, index.ToString()));
                if (audioMixerGroups.Length > 0)
                {
                    soundAgentHelper.AudioMixerGroup = audioMixerGroups[0];
                }
                else
                {
                    soundAgentHelper.AudioMixerGroup = soundGroupHelper.AudioMixerGroup;
                }
            }

            //为声音组添加声音代理辅助器
            soundGroup.AddSoundAgentHelper(m_SoundHelper, soundAgentHelper);
            return(true);
        }