SteamVR_Ears.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using UnityEngine;
  3. using Valve.VR;
  4. [RequireComponent(typeof(AudioListener))]
  5. public class SteamVR_Ears : MonoBehaviour
  6. {
  7. private void OnNewPosesApplied(params object[] args)
  8. {
  9. Transform origin = this.vrcam.origin;
  10. Quaternion lhs = (!(origin != null)) ? Quaternion.identity : origin.rotation;
  11. base.transform.rotation = lhs * this.offset;
  12. }
  13. private void OnEnable()
  14. {
  15. this.usingSpeakers = false;
  16. CVRSettings settings = OpenVR.Settings;
  17. if (settings != null)
  18. {
  19. EVRSettingsError evrsettingsError = EVRSettingsError.None;
  20. if (settings.GetBool("steamvr", "usingSpeakers", false, ref evrsettingsError))
  21. {
  22. this.usingSpeakers = true;
  23. float @float = settings.GetFloat("steamvr", "speakersForwardYawOffsetDegrees", 0f, ref evrsettingsError);
  24. this.offset = Quaternion.Euler(0f, @float, 0f);
  25. }
  26. }
  27. if (this.usingSpeakers)
  28. {
  29. SteamVR_Utils.Event.Listen("new_poses_applied", new SteamVR_Utils.Event.Handler(this.OnNewPosesApplied));
  30. }
  31. }
  32. private void OnDisable()
  33. {
  34. if (this.usingSpeakers)
  35. {
  36. SteamVR_Utils.Event.Remove("new_poses_applied", new SteamVR_Utils.Event.Handler(this.OnNewPosesApplied));
  37. }
  38. }
  39. public SteamVR_Camera vrcam;
  40. private bool usingSpeakers;
  41. private Quaternion offset;
  42. }