IEnumerator Initialize() { var error = EVRInitError.None; // No need to initialize OpenVR until we have a valid session while (!VarjoPlugin.SessionValid) { yield return(new WaitForSeconds(1.0f)); } OpenVR.Init(ref error, EVRApplicationType.VRApplication_Background); if (error != EVRInitError.None) { if (error == EVRInitError.Init_NoServerForBackgroundApp) { Debug.LogError("Failed to initialize OpenVR. OpenVR controllers will not work. Restart Unity Editor and try again."); yield break; } else { Debug.LogWarning("Failed to initialize OpenVR. Entering into poll mode..."); do { OpenVR.Init(ref error, EVRApplicationType.VRApplication_Background); yield return(new WaitForSeconds(3.0f)); } while (error != EVRInitError.None); } } Debug.Log("Varjo_SteamVR_Manager initialized succesfully"); Varjo_SteamVR_Events.System(EVREventType.VREvent_Quit).Listen(OnQuit); #if UNITY_2017_1_OR_NEWER Application.onBeforeRender += OnBeforeRender; #else Camera.onPreCull += OnCameraPreCull; #endif // We should always use standing tracking with Varjo TrackingSpace = ETrackingUniverseOrigin.TrackingUniverseStanding; var vr = Varjo_SteamVR.instance; if (vr == null) { enabled = false; yield break; } }
void OnDisable() { StopAllCoroutines(); if (OpenVR.System == null) { return; } Varjo_SteamVR_Events.System(EVREventType.VREvent_Quit).Remove(OnQuit); #if UNITY_2017_1_OR_NEWER Application.onBeforeRender -= OnBeforeRender; #else Camera.onPreCull -= OnCameraPreCull; #endif }
void Update() { if (!VarjoPlugin.SessionValid || OpenVR.System == null) { return; } // Force controller update in case no one else called this frame to ensure prevState gets updated. Varjo_SteamVR_Controller.Update(); // Dispatch any OpenVR events. var system = OpenVR.System; if (system != null) { var vrEvent = new VREvent_t(); var size = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t)); for (int i = 0; i < 64; i++) { if (!system.PollNextEvent(ref vrEvent, size)) { break; } switch ((EVREventType)vrEvent.eventType) { case EVREventType.VREvent_ShowRenderModels: Varjo_SteamVR_Events.HideRenderModels.Send(false); break; case EVREventType.VREvent_HideRenderModels: Varjo_SteamVR_Events.HideRenderModels.Send(true); break; default: Varjo_SteamVR_Events.System((EVREventType)vrEvent.eventType).Send(vrEvent); break; } } } }
Varjo_SteamVR_ControllerManager() { inputFocusAction = Varjo_SteamVR_Events.InputFocusAction(OnInputFocus); deviceConnectedAction = Varjo_SteamVR_Events.DeviceConnectedAction(OnDeviceConnected); trackedDeviceRoleChangedAction = Varjo_SteamVR_Events.SystemAction(EVREventType.VREvent_TrackedDeviceRoleChanged, OnTrackedDeviceRoleChanged); }
Varjo_SteamVR_TrackedObject() { newPosesAction = Varjo_SteamVR_Events.NewPosesAction(OnNewPoses); }