SoundManager.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using UnityEngine;
  2. using FairyGUI;
  3. using GFGGame.Launcher;
  4. namespace GFGGame
  5. {
  6. public class SoundManager : SingletonMonoBase<SoundManager>
  7. {
  8. private AudioSource _player;
  9. private bool _isOn = true;
  10. public bool isOn
  11. {
  12. get
  13. {
  14. return _isOn;
  15. }
  16. set
  17. {
  18. if(_isOn != value)
  19. {
  20. _isOn = value;
  21. if(_isOn)
  22. {
  23. GRoot.inst.soundVolume = 1;
  24. }
  25. else
  26. {
  27. GRoot.inst.soundVolume = 0;
  28. Stop();
  29. }
  30. LocalCache.SetBool(LauncherConfig.SOUND_KEY, _isOn);
  31. }
  32. }
  33. }
  34. private void Awake()
  35. {
  36. _player = this.gameObject.AddComponent<AudioSource>();
  37. }
  38. private void Start()
  39. {
  40. }
  41. private void Update()
  42. {
  43. }
  44. public void PlayOneShot(string Path)
  45. {
  46. if(_isOn)
  47. {
  48. AudioClip clip = GFGAsset.Load<AudioClip>(Path);
  49. _player.clip = clip;
  50. _player.PlayOneShot(clip);
  51. }
  52. }
  53. public void PlayClipAtPoint(string path, Vector3 position)
  54. {
  55. if (_isOn)
  56. {
  57. AudioClip clip = GFGAsset.Load<AudioClip>(path);
  58. AudioSource.PlayClipAtPoint(clip, position);
  59. }
  60. }
  61. public void Stop()
  62. {
  63. _player.Stop();
  64. }
  65. }
  66. }