Esempio n. 1
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)
        {
            SoundAgentHelperBase soundAgentHelper = Utility.Helper.CreateHelper(m_SoundAgentHelperTypeName, m_CustomSoundAgentHelper, index);

            if (soundAgentHelper == null)
            {
                Log.Error("Can not create sound agent helper.");
                return(false);
            }

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

            transform.SetParent(soundGroupHelper.transform);
            transform.localScale = Vector3.one;

            if (m_AudioMixer != null)
            {
                AudioMixerGroup[] audioMixerGroups = m_AudioMixer.FindMatchingGroups(string.Format("Master/{0}/{1}", soundGroupName, index.ToString()));
                if (audioMixerGroups.Length > 0)
                {
                    soundAgentHelper.SetAudioMixerGroup(audioMixerGroups[0]);
                }
                else
                {
                    soundAgentHelper.SetAudioMixerGroup(soundGroupHelper.AudioMixerGroup);
                }
            }

            m_SoundManager.AddSoundAgentHelper(soundGroupName, soundAgentHelper);

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// 增加声音组。
        /// </summary>
        /// <param name="soundGroupName">声音组名称。</param>
        /// <param name="soundGroupAvoidBeingReplacedBySamePriority">声音组中的声音是否避免被同优先级声音替换。</param>
        /// <param name="soundGroupMute">声音组是否静音。</param>
        /// <param name="soundGroupVolume">声音组音量。</param>
        /// <param name="soundAgentHelperCount">声音代理辅助器数量。</param>
        /// <returns>是否增加声音组成功。</returns>
        public bool AddSoundGroup(string soundGroupName, bool soundGroupAvoidBeingReplacedBySamePriority, bool soundGroupMute, float soundGroupVolume, int soundAgentHelperCount)
        {
            if (m_SoundManager.HasSoundGroup(soundGroupName))
            {
                return(false);
            }

            SoundGroupHelperBase helper = null;

            if (m_SoundGroupHelperTemplate != null)
            {
                helper = Instantiate(m_SoundGroupHelperTemplate);
            }
            else
            {
                helper = (new GameObject()).AddComponent <DefaultSoundGroupHelper>();
            }

            helper.name = string.Format("Sound Group - {0}", soundGroupName);
            Transform transform = helper.transform;

            transform.SetParent(m_InstanceRoot);
            transform.localScale = Vector3.one;

            if (!m_SoundManager.AddSoundGroup(soundGroupName, soundGroupAvoidBeingReplacedBySamePriority, soundGroupMute, soundGroupVolume, helper))
            {
                return(false);
            }

            for (int i = 0; i < soundAgentHelperCount; i++)
            {
                SoundAgentHelperBase agentHelper = null;
                if (m_SoundAgentHelperTemplate != null)
                {
                    agentHelper = Instantiate(m_SoundAgentHelperTemplate);
                }
                else
                {
                    agentHelper = (new GameObject()).AddComponent <DefaultSoundAgentHelper>();
                }

                agentHelper.name = string.Format("Sound Agent Helper - {0} - {1}", soundGroupName, i.ToString());
                Transform agentTransform = agentHelper.transform;
                agentTransform.SetParent(transform);
                agentTransform.localScale = Vector3.one;
                m_SoundManager.AddSoundAgentHelper(soundGroupName, agentHelper);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// 增加声音组。
        /// </summary>
        /// <param name="soundGroupName">声音组名称。</param>
        /// <param name="soundGroupAvoidBeingReplacedBySamePriority">声音组中的声音是否避免被同优先级声音替换。</param>
        /// <param name="soundGroupMute">声音组是否静音。</param>
        /// <param name="soundGroupVolume">声音组音量。</param>
        /// <param name="soundAgentHelperCount">声音代理辅助器数量。</param>
        /// <returns>是否增加声音组成功。</returns>
        public bool AddSoundGroup(string soundGroupName, bool soundGroupAvoidBeingReplacedBySamePriority, bool soundGroupMute, float soundGroupVolume, int soundAgentHelperCount)
        {
            if (m_SoundManager.HasSoundGroup(soundGroupName))
            {
                return(false);
            }

            SoundGroupHelperBase soundGroupHelper = Utility.Helper.CreateHelper(m_SoundGroupHelperTypeName, m_CustomSoundGroupHelper, SoundGroupCount);

            if (soundGroupHelper == null)
            {
                Log.Error("Can not create sound group helper.");
                return(false);
            }

            soundGroupHelper.name = string.Format("Sound Group - {0}", soundGroupName);
            Transform transform = soundGroupHelper.transform;

            transform.SetParent(m_InstanceRoot);
            transform.localScale = Vector3.one;

            if (m_AudioMixer != null)
            {
                AudioMixerGroup[] audioMixerGroups = m_AudioMixer.FindMatchingGroups(string.Format("Master/{0}", soundGroupName));
                if (audioMixerGroups.Length > 0)
                {
                    soundGroupHelper.SetAudioMixerGroup(audioMixerGroups[0]);
                }
                else
                {
                    soundGroupHelper.SetAudioMixerGroup(m_AudioMixer.FindMatchingGroups("Master")[0]);
                }
            }

            if (!m_SoundManager.AddSoundGroup(soundGroupName, soundGroupAvoidBeingReplacedBySamePriority, soundGroupMute, soundGroupVolume, soundGroupHelper))
            {
                return(false);
            }

            for (int i = 0; i < soundAgentHelperCount; i++)
            {
                if (!AddSoundAgentHelper(soundGroupName, soundGroupHelper, i))
                {
                    return(false);
                }
            }

            return(true);
        }