Ejemplo n.º 1
0
        /// <summary>
        /// 获取指定声音组
        /// </summary>
        /// <param name="soundGroupName">声音组名称</param>
        /// <returns>要获取的声音组</returns>
        public SoundGroup GetSoundGroup(string soundGroupName)
        {
            if (string.IsNullOrEmpty(soundGroupName))
            {
                Debug.LogError("要获取的声音组名称为空");
                return(null);
            }

            SoundGroup soundGroup = null;

            if (m_SoundGroups.TryGetValue(soundGroupName, out soundGroup))
            {
                return(soundGroup);
            }

            return(null);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public SoundAgent(SoundGroup soundGroup, SoundHelperBase soundHelper, SoundAgentHelperBase soundAgentHelper)
        {
            if (soundGroup == null)
            {
                Debug.LogError("用来构造声音代理对象的声音组为空");
            }

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

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

            m_SoundGroup  = soundGroup;
            m_SoundHelper = soundHelper;
            Helper        = soundAgentHelper;
            Helper.resetSoundAgentEventHandler += OnResetSoundAgent;
            SerialId = 0;
            Reset();
        }