Example #1
0
        /// <summary>
        ///     Adds the specified value to the volume of the specified type. Add negative value to decrease the volume.
        /// </summary>
        /// <param name="volumeType">The type of volume to add the value to (Master, Music or SFX)</param>
        /// <param name="value">The value to add to the volume</param>
        private void AddToVolume(SoundVolumeType volumeType, float value)
        {
            //Set the volume
            switch (volumeType)
            {
            case SoundVolumeType.Master:
                SoundEffect.MasterVolume = Math.Clamp(SoundEffect.MasterVolume + value, 0, 1f);
                break;

            case SoundVolumeType.Music:
                currentMusicVolume = Math.Clamp(currentMusicVolume + value, 0, 1f);
                break;

            case SoundVolumeType.Sfx:
                currentSfxVolume = Math.Clamp(currentMusicVolume + value, 0, 1f);
                break;
            }

            //Apply the volume to the currently playing sounds
            currentInGameMusicInstance.Volume = currentMusicVolume;
            foreach (SoundEffectInstance instance in sfxInstances)
            {
                instance.Volume = currentSfxVolume;
            }
        }
Example #2
0
 /// <summary> Set sound volume of specified sound type. The value is a float value between 0 (no sound) and 1 (full). So (0.5) is half the sound volume.</summary>
 public static void SetSoundVolume(SoundVolumeType type, float value)
 {
     SettingsManager.soundVolumes[(int)type] = Mathf.Clamp01(value);
     for (int i = 0; i < SettingsManager.soundVolumeUpdaters[(int)type].Count; i++)
     {
         SettingsManager.soundVolumeUpdaters[(int)type][i].UpdateVolume(SettingsManager.soundVolumes[(int)type]);
     }
 }
Example #3
0
 public static void RegisterVolumeUpdater(SoundVolumeType type, SoundVolumeUpdater target)
 {
     if (!SettingsManager.soundVolumeUpdaters[(int)type].Contains(target))
     {
         SettingsManager.soundVolumeUpdaters[(int)type].Add(target);
         target.UpdateVolume(SettingsManager.soundVolumes[(int)type]);
     }
 }
Example #4
0
        private void ToggleMuteVolume(SoundVolumeType volumeType)
        {
            //Mutes or Unmutes volume based on the previous state.

            switch (volumeType)
            {
            case SoundVolumeType.Master:
                sfxMuted = musicMuted = masterMuted = !masterMuted;
                if (!masterMuted)
                {
                    prevMasterVolume         = SoundEffect.MasterVolume;
                    SoundEffect.MasterVolume = 0;
                }
                else
                {
                    SoundEffect.MasterVolume = prevMasterVolume;
                }

                break;

            case SoundVolumeType.Music:
                musicMuted = !musicMuted;
                if (!musicMuted)
                {
                    prevSfxVolume    = currentSfxVolume;
                    currentSfxVolume = 0;
                }
                else
                {
                    currentMusicVolume = prevMusicVolume;
                }

                break;

            case SoundVolumeType.Sfx:
                sfxMuted = !sfxMuted;
                if (!sfxMuted)
                {
                    prevSfxVolume    = currentSfxVolume;
                    currentSfxVolume = 0;
                }
                else
                {
                    currentSfxVolume = prevSfxVolume;
                }

                break;
            }

            currentInGameMusicInstance.Volume = currentMusicVolume;
            foreach (SoundEffectInstance instance in sfxInstances)
            {
                instance.Volume = currentSfxVolume;
            }
        }
Example #5
0
 /// <summary> Get sound volume of specified sound type. The value is a float value between 0 (no sound) and 1 (full). So (0.5) is half the sound volume.</summary>
 public static float GetSoundVolume(SoundVolumeType type)
 {
     return(SettingsManager.soundVolumes[(int)type]);
 }
Example #6
0
 public static void RemoveVolumeUpdater(SoundVolumeType type, SoundVolumeUpdater target)
 {
     SettingsManager.soundVolumeUpdaters[(int)type].Remove(target);
 }