internal void SetAudioLevel(AudioChannelType audioChannelType, float v)
 {
     audioLevelPercentage[audioChannelType] = v;
     if (audioLevelChangedEvent != null)
     {
         audioLevelChangedEvent(audioChannelType);
     }
 }
        /// <summary>
        ///   Stops the clip being played at the specified channel, if any.
        /// </summary>
        /// <param name="channelType">Channel to stop the current audio clip of.</param>
        public void ClearAudioChannel(AudioChannelType channelType)
        {
            var audioChannel = this[channelType];
            if (audioChannel.Source == null)
            {
                Debug.LogError(string.Format("No audio source set for channel {0}.", channelType));
                return;
            }

            audioChannel.Source.FadeOut();
        }
 internal void MuteAudioLevel(AudioChannelType audioChannelType, bool muted)
 {
     if (muted)
     {
         SetAudioLevel(audioChannelType, minAudioLevel);
     }
     else
     {
         SetAudioLevel(audioChannelType, maxAudioLevel);
     }
 }
示例#4
0
    private void SendCallback(AudioChannelType type)
    {
        float value = m_CurrentVolumes[(int)type];

        foreach (var channel in m_Channels)
        {
            if (channel != null && channel.AudioType == type)
            {
                channel.SetAudioLevel(value);
            }
        }
    }
示例#5
0
	public static string GetAudioClipPath(AudioChannelType channelType, string audioName)
	{
		switch(channelType){
		case AudioChannelType.BGM:
			return "Audio/BGM/" + audioName;
		case AudioChannelType.SoundFX:
			return "Audio/Sound/" + audioName;
		default:
			Debug.LogError("例外的 ChannelType:" + channelType.ToString());
			return null;
		}
	}
示例#6
0
        /// <summary>
        ///   Stops the clip being played at the specified channel, if any.
        /// </summary>
        /// <param name="channelType">Channel to stop the current audio clip of.</param>
        public void ClearAudioChannel(AudioChannelType channelType)
        {
            var audioChannel = this[channelType];

            if (audioChannel.Source == null)
            {
                Debug.LogError(string.Format("No audio source set for channel {0}.", channelType));
                return;
            }

            audioChannel.Source.FadeOut();
        }
        // ReSharper restore FieldCanBeMadeReadOnly.Local

        #endregion

        #region Public Indexers

        /// <summary>
        ///   Gets or sets the audio channel of the specified type.
        /// </summary>
        /// <param name="channelType">Type of the audio channel.</param>
        /// <returns>Audio channel of the specified type.</returns>
        public AudioChannel this[AudioChannelType channelType]
        {
            get
            {
                var audioChannel = this.audioChannels.FirstOrDefault(channel => channel.Type == channelType);

                if (audioChannel == null)
                {
                    audioChannel = new AudioChannel { Type = channelType };
                    this.audioChannels.Add(audioChannel);
                }

                return audioChannel;
            }
        }
示例#8
0
        /// <summary>
        ///   Plays the specified clip, if it's not already playing.
        /// </summary>
        /// <param name="channelType">Channel to play the clip at.</param>
        /// <param name="clip">Music clip to play.</param>
        /// <param name="volume">Volume to play the clip at.</param>
        /// <param name="loop">Whether to loop the clip or play one-shot.</param>
        public void PlayAudioClip(AudioChannelType channelType, AudioClip clip, float volume, bool loop)
        {
            var audioChannel = this[channelType];

            if (audioChannel.Source == null)
            {
                Debug.LogError(string.Format("No audio source set for channel {0}.", channelType));
                return;
            }

            if (!audioChannel.Source.IsPlaying || audioChannel.Source.Clip != clip)
            {
                PlayAudioClip(audioChannel.Source, clip, volume, loop);
            }
        }
示例#9
0
        /// <summary>
        ///   Fades to the specified intro clip, if it's not already playing,
        ///   playing it one time, and loops the passed loop after.
        /// </summary>
        /// <param name="channelType">Channel to play the clip at.</param>
        /// <param name="introClip">Clip to play once.</param>
        /// <param name="loopClip">Clip to loop after.</param>
        /// <param name="volume">Volume to play the clip at.</param>
        /// <seealso cref="FadingAudioSource.Fade(UnityEngine.AudioClip,float,bool)" />
        public void PlayAudioClipWithIntroAndLoop(
            AudioChannelType channelType, AudioClip introClip, AudioClip loopClip, float volume)
        {
            var audioChannel = this[channelType];

            if (audioChannel.Source == null)
            {
                Debug.LogError(string.Format("No audio source set for channel {0}.", channelType));
                return;
            }

            if (!audioChannel.Source.IsPlaying || audioChannel.Source.Clip != introClip)
            {
                PlayAudioIntroAndLoopClip(audioChannel.Source, introClip, loopClip, volume);
            }
        }
示例#10
0
        // ReSharper restore FieldCanBeMadeReadOnly.Local

        #endregion

        #region Public Indexers

        /// <summary>
        ///   Gets or sets the audio channel of the specified type.
        /// </summary>
        /// <param name="channelType">Type of the audio channel.</param>
        /// <returns>Audio channel of the specified type.</returns>
        public AudioChannel this[AudioChannelType channelType]
        {
            get
            {
                var audioChannel = this.audioChannels.FirstOrDefault(channel => channel.Type == channelType);

                if (audioChannel == null)
                {
                    audioChannel = new AudioChannel {
                        Type = channelType
                    };
                    this.audioChannels.Add(audioChannel);
                }

                return(audioChannel);
            }
        }
示例#11
0
        //设置音量
        public void SetChannelVolume(uint eChannelType, float in_value)
        {
            if (in_value < 0)
            {
                in_value = 0;
            }
            if (in_value > 1.0f)
            {
                in_value = 1.0f;
            }
            AudioChannel kAudioChannel = GetChannelByType(eChannelType);

            if (kAudioChannel != null)
            {
                kAudioChannel.SetVolume(in_value);
            }
            //记录
            AudioChannelType tt = (AudioChannelType)eChannelType;

            if (tt == AudioChannelType.ACT_BGM)
            {
                m_fCurBGMVolume  = in_value;
                m_fLastBGMVolume = in_value;
                PlayerPrefs.SetFloat(System.Enum.GetName(typeof(AudioService.AudioChannelType), AudioService.AudioChannelType.ACT_BGM), m_fCurBGMVolume);
            }
            else if (tt == AudioChannelType.ACT_EF)
            {
                m_fCurEFVolume  = in_value;
                m_fLastEFVolume = in_value;
                PlayerPrefs.SetFloat(System.Enum.GetName(typeof(AudioService.AudioChannelType), AudioService.AudioChannelType.ACT_EF), m_fCurEFVolume);
            }
            else if (tt == AudioChannelType.ACT_UI)
            {
                m_fCurUIVolume  = in_value;
                m_fLastUIVolume = in_value;
                PlayerPrefs.SetFloat(System.Enum.GetName(typeof(AudioService.AudioChannelType), AudioService.AudioChannelType.ACT_UI), m_fCurUIVolume);
            }
            else if (tt == AudioChannelType.ACT_VOICE)
            {
                m_fCurVoiceVolume  = in_value;
                m_fLastVoiceVolume = in_value;
                PlayerPrefs.SetFloat(System.Enum.GetName(typeof(AudioService.AudioChannelType), AudioService.AudioChannelType.ACT_VOICE), m_fCurVoiceVolume);
            }
        }
示例#12
0
        //获取通道
        private AudioChannel GetChannelByType(uint eChannelType)
        {
            AudioChannelType tt = (AudioChannelType)eChannelType;

            switch (tt)
            {
            case AudioChannelType.ACT_BGM:
                return(m_kChannel_BGM);

            case AudioChannelType.ACT_UI:
                return(m_kChannel_UI);

            case AudioChannelType.ACT_VOICE:
                return(m_kChannel_VOICE);

            case AudioChannelType.ACT_EF:
                return(m_kChannel_EF);

            default:
                return(null);
            }
        }
示例#13
0
        //获取对应通道音量
        public float GetVolumeByChannel(uint eChannelType)
        {
            AudioChannelType tt = (AudioChannelType)eChannelType;

            switch (tt)
            {
            case AudioChannelType.ACT_BGM:
                return(m_fCurBGMVolume);

            case AudioChannelType.ACT_UI:
                return(m_fCurUIVolume);

            case AudioChannelType.ACT_VOICE:
                return(m_fCurVoiceVolume);

            case AudioChannelType.ACT_EF:
                return(m_fCurEFVolume);

            default:
                return(m_fCurUIVolume);
            }
        }
示例#14
0
 /// <summary>
 ///   Plays the specified clip, if it's not already playing.
 /// </summary>
 /// <param name="channelType">Channel to play the clip at.</param>
 /// <param name="clip">Music clip to play.</param>
 public void PlayAudioClip(AudioChannelType channelType, AudioClip clip)
 {
     this.PlayAudioClip(channelType, clip, DefaultVolume);
 }
        /// <summary>
        ///   Fades to the specified intro clip, if it's not already playing,
        ///   playing it one time, and loops the passed loop after.
        /// </summary>
        /// <param name="channelType">Channel to play the clip at.</param>
        /// <param name="introClip">Clip to play once.</param>
        /// <param name="loopClip">Clip to loop after.</param>
        /// <param name="volume">Volume to play the clip at.</param>
        /// <seealso cref="FadingAudioSource.Fade(UnityEngine.AudioClip,float,bool)" />
        public void PlayAudioClipWithIntroAndLoop(
            AudioChannelType channelType, AudioClip introClip, AudioClip loopClip, float volume)
        {
            var audioChannel = this[channelType];
            if (audioChannel.Source == null)
            {
                Debug.LogError(string.Format("No audio source set for channel {0}.", channelType));
                return;
            }

            if (!audioChannel.Source.IsPlaying || audioChannel.Source.Clip != introClip)
            {
                PlayAudioIntroAndLoopClip(audioChannel.Source, introClip, loopClip, volume);
            }
        }
        /// <summary>
        ///   Fades to the specified clip, if it's not already playing.
        /// </summary>
        /// <param name="channelType">Channel to play the clip at.</param>
        /// <param name="clip">Music clip to play.</param>
        /// <param name="volume">Volume to play the clip at.</param>
        /// <param name="loop">Whether to loop the clip or play one-shot.</param>
        /// <param name="fadeSpeed">Speed to fade in or out with, in volume/second.</param>
        /// <seealso cref="FadingAudioSource.Fade(UnityEngine.AudioClip,float,bool)" />
        public void PlayAudioClip(
            AudioChannelType channelType, AudioClip clip, float volume, bool loop, float fadeSpeed)
        {
            var audioChannel = this[channelType];
            if (audioChannel.Source == null)
            {
                Debug.LogError(string.Format("No audio source set for channel {0}.", channelType));
                return;
            }

            if (!audioChannel.Source.IsPlaying || audioChannel.Source.Clip != clip)
            {
                audioChannel.Source.Fade(clip, volume, loop, fadeSpeed);
            }
        }
 /// <summary>
 ///   Plays the specified clip, if it's not already playing.
 /// </summary>
 /// <param name="channelType">Channel to play the clip at.</param>
 /// <param name="clip">Music clip to play.</param>
 public void PlayAudioClip(AudioChannelType channelType, AudioClip clip)
 {
     this.PlayAudioClip(channelType, clip, DefaultVolume);
 }
 /// <summary>
 ///   Plays the specified clip, if it's not already playing.
 /// </summary>
 /// <param name="channelType">Channel to play the clip at.</param>
 /// <param name="clip">Music clip to play.</param>
 /// <param name="volume">Volume to play the clip at.</param>
 public void PlayAudioClip(AudioChannelType channelType, AudioClip clip, float volume)
 {
     this.PlayAudioClip(channelType, clip, volume, true);
 }
 public float GetAudioVolume(AudioChannelType audioChannelType)
 {
     return(audioLevelPercentage[audioChannelType]);
 }
示例#20
0
 /// <summary>
 ///   Plays the specified clip, if it's not already playing.
 /// </summary>
 /// <param name="channelType">Channel to play the clip at.</param>
 /// <param name="clip">Music clip to play.</param>
 /// <param name="volume">Volume to play the clip at.</param>
 public void PlayAudioClip(AudioChannelType channelType, AudioClip clip, float volume)
 {
     this.PlayAudioClip(channelType, clip, volume, true);
 }