PXR_Audio_Spatializer_AmbisonicSource.cs 874 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright © 2015-2021 Pico Technology Co., Ltd. All Rights Reserved.
  2. using UnityEngine;
  3. [RequireComponent(typeof(AudioSource))]
  4. public class PXR_Audio_Spatializer_AmbisonicSource : MonoBehaviour
  5. {
  6. private AudioSource nativeSource;
  7. private float playheadPosition = 0.0f;
  8. private bool wasPlaying = false;
  9. /// <summary>
  10. /// Resume audio playing status.
  11. /// </summary>
  12. public void Resume()
  13. {
  14. if (nativeSource)
  15. {
  16. nativeSource.time = playheadPosition;
  17. if (wasPlaying)
  18. {
  19. nativeSource.Play();
  20. }
  21. }
  22. }
  23. void Awake()
  24. {
  25. nativeSource = GetComponent<AudioSource>();
  26. }
  27. void Update()
  28. {
  29. if (nativeSource.isPlaying)
  30. playheadPosition = nativeSource.time;
  31. wasPlaying = nativeSource.isPlaying;
  32. }
  33. }
粤ICP备19079148号