Exemple #1
0
        private IEnumerator RenderLoop()
        {
            while (Application.isPlaying)
            {
                yield return(this.waitForEndOfFrame);

                if (!SteamVR_Render.pauseRendering)
                {
                    CVRCompositor compositor = OpenVR.Compositor;
                    if (compositor != null)
                    {
                        if (!compositor.CanRenderScene() || cameras.Length < 1)
                        {
                            continue;
                        }
                        compositor.SetTrackingSpace(SteamVR.settings.trackingSpace);
                        SteamVR_Utils.QueueEventOnRenderThread(201510020);
                        SteamVR.Unity.EventWriteString("[UnityMain] GetNativeTexturePtr - Begin");
                        SteamVR_Camera.GetSceneTexture(this.cameras[0].GetComponent <Camera>()).GetNativeTexturePtr();
                        SteamVR.Unity.EventWriteString("[UnityMain] GetNativeTexturePtr - End");
                        compositor.GetLastPoses(this.poses, this.gamePoses);
                        SteamVR_Events.NewPoses.Send(this.poses);
                        SteamVR_Events.NewPosesApplied.Send();
                    }
                    SteamVR_Overlay instance = SteamVR_Overlay.instance;
                    if (instance != null)
                    {
                        instance.UpdateOverlay();
                    }
                    if (this.CheckExternalCamera())
                    {
                        this.RenderExternalCamera();
                    }
                    SteamVR instance2 = SteamVR.instance;
                    this.RenderEye(instance2, EVREye.Eye_Left);
                    this.RenderEye(instance2, EVREye.Eye_Right);
                    foreach (SteamVR_Camera steamVR_Camera in this.cameras)
                    {
                        steamVR_Camera.transform.localPosition = Vector3.zero;
                        steamVR_Camera.transform.localRotation = Quaternion.identity;
                    }
                    if (this.cameraMask != null)
                    {
                        this.cameraMask.Clear();
                    }
                }
            }
            yield break;
        }
        public void HideMenu()
        {
            RestoreCursorState();

            if (overlayCam != null)
            {
                overlayCam.enabled = true;
            }

            if (overlay != null)
            {
                overlay.uvOffset = uvOffset;
                overlay.distance = distance;
                overlay          = null;
            }
        }
        public void ShowMenu()
        {
            var overlay = SteamVR_Overlay.instance;

            if (overlay == null)
            {
                return;
            }

            var texture = overlay.texture as RenderTexture;

            if (texture == null)
            {
                Debug.LogError("Menu requires overlay texture to be a render texture.");
                return;
            }

            SaveCursorState();

            Cursor.visible   = true;
            Cursor.lockState = CursorLockMode.None;

            this.overlay = overlay;
            uvOffset     = overlay.uvOffset;
            distance     = overlay.distance;

            // If an existing camera is rendering into the overlay texture, we need
            // to temporarily disable it to keep it from clearing the texture on us.
            var cameras = Object.FindObjectsOfType(typeof(Camera)) as Camera[];

            foreach (var cam in cameras)
            {
                if (cam.enabled && cam.targetTexture == texture)
                {
                    overlayCam         = cam;
                    overlayCam.enabled = false;
                    break;
                }
            }

            var tracker = SteamVR_Render.Top();

            if (tracker != null)
            {
                scale = tracker.origin.localScale.x;
            }
        }