Ejemplo n.º 1
0
    void InitOVROverlay()
    {
        if (!OVRManager.isHmdPresent)
        {
            enabled = false;
            return;
        }

        constructedOverlayXRDevice = OVRManager.XRDevice.Unknown;
        if (OVRManager.loadedXRDevice == OVRManager.XRDevice.OpenVR)
        {
            OVR.OpenVR.CVROverlay overlay = OVR.OpenVR.OpenVR.Overlay;
            if (overlay != null)
            {
                OVR.OpenVR.EVROverlayError error = overlay.CreateOverlay(OpenVROverlayKey + transform.name, gameObject.name, ref OpenVROverlayHandle);
                if (error != OVR.OpenVR.EVROverlayError.None)
                {
                    enabled = false;
                    return;
                }
            }
            else
            {
                enabled = false;
                return;
            }
        }

        constructedOverlayXRDevice = OVRManager.loadedXRDevice;
        xrDeviceConstructed        = true;
    }
Ejemplo n.º 2
0
    void OnDisable()
    {
        if ((gameObject.hideFlags & HideFlags.DontSaveInBuild) != 0)
        {
            return;
        }

        if (OVRManager.loadedXRDevice != constructedOverlayXRDevice)
        {
            return;
        }

        if (OVRManager.loadedXRDevice == OVRManager.XRDevice.Oculus)
        {
            DestroyLayerTextures();
            DestroyLayer();
        }
        else if (OVRManager.loadedXRDevice == OVRManager.XRDevice.OpenVR)
        {
            if (OpenVROverlayHandle != OVR.OpenVR.OpenVR.k_ulOverlayHandleInvalid)
            {
                OVR.OpenVR.CVROverlay overlay = OVR.OpenVR.OpenVR.Overlay;
                if (overlay != null)
                {
                    overlay.DestroyOverlay(OpenVROverlayHandle);
                }
                OpenVROverlayHandle = OVR.OpenVR.OpenVR.k_ulOverlayHandleInvalid;
            }
        }
        constructedOverlayXRDevice = OVRManager.XRDevice.Unknown;
    }
Ejemplo n.º 3
0
    void OpenVROverlayUpdate(Vector3 scale, OVRPose pose)
    {
        OVR.OpenVR.CVROverlay overlayRef = OVR.OpenVR.OpenVR.Overlay;
        if (overlayRef == null)
        {
            return;
        }

        Texture overlayTex = textures[0];

        if (overlayTex != null)
        {
            OVR.OpenVR.EVROverlayError error = overlayRef.ShowOverlay(OpenVROverlayHandle);
            if (error == OVR.OpenVR.EVROverlayError.InvalidHandle || error == OVR.OpenVR.EVROverlayError.UnknownOverlay)
            {
                if (overlayRef.FindOverlay(OpenVROverlayKey + transform.name, ref OpenVROverlayHandle) != OVR.OpenVR.EVROverlayError.None)
                {
                    return;
                }
            }

            OVR.OpenVR.Texture_t tex = new OVR.OpenVR.Texture_t();
            tex.handle      = overlayTex.GetNativeTexturePtr();
            tex.eType       = SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL") ? OVR.OpenVR.ETextureType.OpenGL : OVR.OpenVR.ETextureType.DirectX;
            tex.eColorSpace = OVR.OpenVR.EColorSpace.Auto;
            overlayRef.SetOverlayTexture(OpenVROverlayHandle, ref tex);

            OVR.OpenVR.VRTextureBounds_t textureBounds = new OVR.OpenVR.VRTextureBounds_t();
            textureBounds.uMin = (0 + OpenVRUVOffsetAndScale.x) * OpenVRUVOffsetAndScale.z;
            textureBounds.vMin = (1 + OpenVRUVOffsetAndScale.y) * OpenVRUVOffsetAndScale.w;
            textureBounds.uMax = (1 + OpenVRUVOffsetAndScale.x) * OpenVRUVOffsetAndScale.z;
            textureBounds.vMax = (0 + OpenVRUVOffsetAndScale.y) * OpenVRUVOffsetAndScale.w;

            overlayRef.SetOverlayTextureBounds(OpenVROverlayHandle, ref textureBounds);

            OVR.OpenVR.HmdVector2_t vecMouseScale = new OVR.OpenVR.HmdVector2_t();
            vecMouseScale.v0 = OpenVRMouseScale.x;
            vecMouseScale.v1 = OpenVRMouseScale.y;
            overlayRef.SetOverlayMouseScale(OpenVROverlayHandle, ref vecMouseScale);

            overlayRef.SetOverlayWidthInMeters(OpenVROverlayHandle, scale.x);

            Matrix4x4 mat44 = Matrix4x4.TRS(pose.position, pose.orientation, Vector3.one);

            OVR.OpenVR.HmdMatrix34_t pose34 = mat44.ConvertToHMDMatrix34();

            overlayRef.SetOverlayTransformAbsolute(OpenVROverlayHandle, OVR.OpenVR.ETrackingUniverseOrigin.TrackingUniverseStanding, ref pose34);
        }
    }
Ejemplo n.º 4
0
    void OnDisable()
    {
        #if UNITY_EDITOR
        if (previewObject != null)
        {
            previewObject.SetActive(false);
        }
        #endif

        if ((gameObject.hideFlags & HideFlags.DontSaveInBuild) != 0)
        {
            return;
        }

        if (!OVRManager.OVRManagerinitialized)
        {
            return;
        }

        if (OVRManager.loadedXRDevice != constructedOverlayXRDevice)
        {
            return;
        }

        if (OVRManager.loadedXRDevice == OVRManager.XRDevice.Oculus)
        {
            DestroyLayerTextures();
            DestroyLayer();
        }
        else if (OVRManager.loadedXRDevice == OVRManager.XRDevice.OpenVR)
        {
            if (OpenVROverlayHandle != OVR.OpenVR.OpenVR.k_ulOverlayHandleInvalid)
            {
                OVR.OpenVR.CVROverlay overlay = OVR.OpenVR.OpenVR.Overlay;
                if (overlay != null)
                {
                    overlay.DestroyOverlay(OpenVROverlayHandle);
                }
                OpenVROverlayHandle = OVR.OpenVR.OpenVR.k_ulOverlayHandleInvalid;
            }
        }
        constructedOverlayXRDevice = OVRManager.XRDevice.Unknown;
        xrDeviceConstructed        = false;
    }