AudioKitSettings.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using UnityEngine;
  2. namespace QFramework
  3. {
  4. /// <summary>
  5. /// 专门用来为音频做设置
  6. /// </summary>
  7. public class AudioKitSettings
  8. {
  9. // 用来存储的Key
  10. const string KEY_AUDIO_MANAGER_SOUND_ON = "KEY_AUDIO_MANAGER_SOUND_ON";
  11. const string KEY_AUDIO_MANAGER_MUSIC_ON = "KEY_AUDIO_MANAGER_MUSIC_ON";
  12. const string KEY_AUDIO_MANAGER_VOICE_ON = "KEY_AUDIO_MANAGER_VOICE_ON";
  13. const string KEY_AUDIO_MANAGER_VOICE_VOLUME = "KEY_AUDIO_MANAGER_VOICE_VOLUME";
  14. const string KEY_AUDIO_MANAGER_SOUND_VOLUME = "KEY_AUDIO_MANAGER_SOUND_VOLUME";
  15. const string KEY_AUDIO_MANAGER_MUSIC_VOLUME = "KEY_AUDIO_MANAGER_MUSIC_VOLUME";
  16. public AudioKitSettings()
  17. {
  18. IsSoundOn = new PlayerPrefsBooleanProperty(KEY_AUDIO_MANAGER_SOUND_ON, true);
  19. IsMusicOn = new PlayerPrefsBooleanProperty(KEY_AUDIO_MANAGER_MUSIC_ON, true);
  20. IsVoiceOn = new PlayerPrefsBooleanProperty(KEY_AUDIO_MANAGER_VOICE_ON, true);
  21. IsOn = new CustomProperty<bool>(
  22. () => IsSoundOn.Value && IsMusicOn.Value && IsVoiceOn.Value,
  23. isOn =>
  24. {
  25. Debug.Log(isOn);
  26. IsSoundOn.Value = isOn;
  27. IsMusicOn.Value = isOn;
  28. IsVoiceOn.Value = isOn;
  29. }
  30. );
  31. SoundVolume = new PlayerPrefsFloatProperty(KEY_AUDIO_MANAGER_SOUND_VOLUME, 1.0f);
  32. MusicVolume = new PlayerPrefsFloatProperty(KEY_AUDIO_MANAGER_VOICE_VOLUME, 1.0f);
  33. VoiceVolume = new PlayerPrefsFloatProperty(KEY_AUDIO_MANAGER_MUSIC_VOLUME, 1.0f);
  34. }
  35. public PlayerPrefsBooleanProperty IsSoundOn { get; private set; }
  36. public PlayerPrefsBooleanProperty IsMusicOn { get; private set; }
  37. public PlayerPrefsBooleanProperty IsVoiceOn { get; private set; }
  38. public PlayerPrefsFloatProperty SoundVolume { get; private set; }
  39. public PlayerPrefsFloatProperty MusicVolume { get; private set; }
  40. public PlayerPrefsFloatProperty VoiceVolume { get; private set; }
  41. public CustomProperty<bool> IsOn { get; private set; }
  42. }
  43. }