123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using UnityEngine;
- using Valve.VR;
- [RequireComponent(typeof(AudioListener))]
- public class SteamVR_Ears : MonoBehaviour
- {
- private void OnNewPosesApplied(params object[] args)
- {
- Transform origin = this.vrcam.origin;
- Quaternion lhs = (!(origin != null)) ? Quaternion.identity : origin.rotation;
- base.transform.rotation = lhs * this.offset;
- }
- private void OnEnable()
- {
- this.usingSpeakers = false;
- CVRSettings settings = OpenVR.Settings;
- if (settings != null)
- {
- EVRSettingsError evrsettingsError = EVRSettingsError.None;
- if (settings.GetBool("steamvr", "usingSpeakers", false, ref evrsettingsError))
- {
- this.usingSpeakers = true;
- float @float = settings.GetFloat("steamvr", "speakersForwardYawOffsetDegrees", 0f, ref evrsettingsError);
- this.offset = Quaternion.Euler(0f, @float, 0f);
- }
- }
- if (this.usingSpeakers)
- {
- SteamVR_Utils.Event.Listen("new_poses_applied", new SteamVR_Utils.Event.Handler(this.OnNewPosesApplied));
- }
- }
- private void OnDisable()
- {
- if (this.usingSpeakers)
- {
- SteamVR_Utils.Event.Remove("new_poses_applied", new SteamVR_Utils.Event.Handler(this.OnNewPosesApplied));
- }
- }
- public SteamVR_Camera vrcam;
- private bool usingSpeakers;
- private Quaternion offset;
- }
|