// This handles disabling VR in the event that the HMD has been disconnected bool onDeviceEvent(PlayStationVR.deviceEventType eventType, int value) { Debug.LogFormat("onDeviceEvent: {0}, {1}", eventType, value); bool handledEvent = false; switch (eventType) { case PlayStationVR.deviceEventType.deviceStopped: PlayStationVR.setOutputModeHMD(false); handledEvent = true; break; case PlayStationVR.deviceEventType.StatusChanged: // e.g. HMD unplugged VRDeviceStatus devstatus = (VRDeviceStatus)value; Debug.LogFormat("DeviceStatus: {0}", devstatus); if (devstatus != VRDeviceStatus.Ready) { HmdSetupDialog.OpenAsync(0, null); } handledEvent = true; break; case PlayStationVR.deviceEventType.MountChanged: VRHmdMountStatus status = (VRHmdMountStatus)value; Debug.LogFormat("VRHmdMountStatus: {0}", status); handledEvent = true; break; } return(handledEvent); }
public bool IsHeadTracked() { if (!mHasHmd) { return(true); } #if UNITY_PS4 && !UNITY_EDITOR int handle = PlayStationVR.GetHmdHandle(); PlayStationVRTrackingStatus status; Tracker.GetTrackedDeviceStatus(handle, out status); if (status != PlayStationVRTrackingStatus.Tracking) { return(false); } PlayStationVRTrackingQuality quality; Tracker.GetTrackedDevicePositionQuality(handle, out quality); return(quality == PlayStationVRTrackingQuality.Full); #elif VZ_GAME && !UNITY_ANDROID if (IsSteamVR) { return(!SteamVR.outOfRange); } else { return(OVRPlugin.positionTracked); } #else return(true); #endif }
/** * @brief PSVR HMDの位置 */ private void UpdateHmdPosition() { if (VRSettings.enabled) { int hmdHandle = PlayStationVR.GetHmdHandle(); Tracker.GetTrackedDevicePosition(hmdHandle, PlayStationVRSpace.Raw, out outhmdPositionRaw); Tracker.GetTrackedDevicePosition(hmdHandle, PlayStationVRSpace.Unity, out outhmdPositionUnity); Tracker.GetTrackedDeviceOrientation(hmdHandle, PlayStationVRSpace.Unity, out outhmdOrientation); } else { Camera camera = transform.GetChild(0).gameObject.GetComponent <Camera>(); outhmdOrientation = camera.transform.rotation; } }
void OnPostRender() { if (cam == null) { cam = GetComponent <Camera>(); } if (UnityEngine.VR.VRSettings.loadedDeviceName == VRDeviceNames.PlayStationVR) { if (PlayStationVRSettings.postReprojectionType == PlayStationVRPostReprojectionType.None) { // If post-reprojection isn't supported (either because it wasn't turned on, or else we're in // Deferred) then disable this script and re-parent the reticle to the main camera instead Debug.LogError("You're trying to use Post Reprojection, but it is not enabled in your PlayStationVRSettings!"); if (transform.childCount > 0) { Transform reticle = transform.GetChild(0); reticle.gameObject.layer = 0; reticle.parent = Camera.main.transform; } gameObject.SetActive(false); // busySpinner.SetActive(false); } else { if (currentEye == 0) { postReprojectionTexture = PlayStationVR.GetCurrentFramePostReprojectionEyeTexture(UnityEngine.VR.VRNode.LeftEye); } else if (currentEye == 1) { postReprojectionTexture = PlayStationVR.GetCurrentFramePostReprojectionEyeTexture(UnityEngine.VR.VRNode.RightEye); } #if UNITY_5_6_OR_NEWER Graphics.Blit(RenderTexture.active, postReprojectionTexture); #else Graphics.Blit(cam.targetTexture, postReprojectionTexture); #endif currentEye++; } } }
IEnumerator ShutdownVR() { VRSettings.LoadDeviceByName(VRDeviceNames.None); // WORKAROUND: At the moment the device is created at the end of the frame so // we need to wait a frame until the VR device is changed back to 'None', and // then reset the Main Camera's FOV and Aspect yield return(null); VRSettings.enabled = false; VRSettings.showDeviceView = false; #if UNITY_PS4 // Unregister the callbacks needed to detect resetting the HMD Utility.onSystemServiceEvent -= OnSystemServiceEvent; PlayStationVR.onDeviceEvent -= onDeviceEvent; // PlayStationVR.setOutputModeHMD(false, false); PlayStationVR.SetOutputModeHMD(false); #endif Camera.main.ResetFieldOfView(); Camera.main.ResetAspect(); GameFadeManager.Instance.ResetVRMode(); }