Ejemplo n.º 1
0
    // Corourtine to handle all the steps across loading boundaries.
    private IEnumerator LoadLevel()
    {
        // Optionally rotate loading screen transform around the camera into view.
        // We assume here that the loading screen is already facing toward the origin,
        // and that the progress bar transform (if any) is a child and will follow along.
        if (loadingScreen != null && loadingScreenDistance > 0.0f)
        {
            // Wait until we have tracking.
            var hmd = SteamVR_Controller.Input((int)OpenVR.k_unTrackedDeviceIndex_Hmd);
            while (!hmd.hasTracking)
            {
                yield return(null);
            }

            var tloading = hmd.transform;
            tloading.rot  = Quaternion.Euler(0.0f, tloading.rot.eulerAngles.y, 0.0f);
            tloading.pos += tloading.rot * new Vector3(0.0f, 0.0f, loadingScreenDistance);

            var t = loadingScreenTransform != null ? loadingScreenTransform : transform;
            t.position = tloading.pos;
            t.rotation = tloading.rot;
        }

        _active = this;

        SteamVR_Events.Loading.Send(true);

        // Calculate rate for fading in loading screen and progress bar.
        if (loadingScreenFadeInTime > 0.0f)
        {
            fadeRate = 1.0f / loadingScreenFadeInTime;
        }
        else
        {
            alpha = 1.0f;
        }

        var overlay = OpenVR.Overlay;

        // Optionally create our loading screen overlay.
        if (loadingScreen != null && overlay != null)
        {
            loadingScreenOverlayHandle = GetOverlayHandle("loadingScreen", loadingScreenTransform != null ? loadingScreenTransform : transform, loadingScreenWidthInMeters);
            if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
            {
                var texture = new Texture_t();
                texture.handle      = loadingScreen.GetNativeTexturePtr();
                texture.eType       = SteamVR.instance.textureType;
                texture.eColorSpace = EColorSpace.Auto;
                overlay.SetOverlayTexture(loadingScreenOverlayHandle, ref texture);
            }
        }

        bool fadedForeground = false;

        // Fade out to compositor
        SteamVR_Events.LoadingFadeOut.Send(fadeOutTime);

        // Optionally set a skybox to use as a backdrop in the compositor.
        var compositor = OpenVR.Compositor;

        if (compositor != null)
        {
            if (front != null)
            {
                SteamVR_Skybox.SetOverride(front, back, left, right, top, bottom);

                // Explicitly fade to the compositor since loading will cause us to stop rendering.
                compositor.FadeGrid(fadeOutTime, true);
                yield return(new WaitForSeconds(fadeOutTime));
            }
            else if (backgroundColor != Color.clear)
            {
                // Otherwise, use the specified background color.
                if (showGrid)
                {
                    // Set compositor background color immediately, and start fading to it.
                    compositor.FadeToColor(0.0f, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, true);
                    compositor.FadeGrid(fadeOutTime, true);
                    yield return(new WaitForSeconds(fadeOutTime));
                }
                else
                {
                    // Fade the foreground color in (which will blend on top of the scene), and then cut to the compositor.
                    compositor.FadeToColor(fadeOutTime, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, false);
                    yield return(new WaitForSeconds(fadeOutTime + 0.1f));

                    compositor.FadeGrid(0.0f, true);
                    fadedForeground = true;
                }
            }
        }

        // Now that we're fully faded out, we can stop submitting frames to the compositor.
        SteamVR_Render.pauseRendering = true;

        // Continue waiting for the overlays to fully fade in before continuing.
        while (alpha < 1.0f)
        {
            yield return(null);
        }

        // Keep us from getting destroyed when loading the new level, otherwise this coroutine will get stopped prematurely.
        transform.parent = null;
        DontDestroyOnLoad(gameObject);

        if (!string.IsNullOrEmpty(internalProcessPath))
        {
            Debug.Log("Launching external application...");
            var applications = OpenVR.Applications;
            if (applications == null)
            {
                Debug.Log("Failed to get OpenVR.Applications interface!");
            }
            else
            {
                var workingDirectory = Directory.GetCurrentDirectory();
                var fullPath         = Path.Combine(workingDirectory, internalProcessPath);
                Debug.Log("LaunchingInternalProcess");
                Debug.Log("ExternalAppPath = " + internalProcessPath);
                Debug.Log("FullPath = " + fullPath);
                Debug.Log("ExternalAppArgs = " + internalProcessArgs);
                Debug.Log("WorkingDirectory = " + workingDirectory);
                var error = applications.LaunchInternalProcess(fullPath, internalProcessArgs, workingDirectory);
                Debug.Log("LaunchInternalProcessError: " + error);
#if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
#elif !UNITY_METRO
                System.Diagnostics.Process.GetCurrentProcess().Kill();
#endif
            }
        }
        else
        {
            var mode = loadAdditive ? UnityEngine.SceneManagement.LoadSceneMode.Additive : UnityEngine.SceneManagement.LoadSceneMode.Single;
            if (loadAsync)
            {
                Application.backgroundLoadingPriority = ThreadPriority.Low;
                async = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(levelName, mode);

                // Performing this in a while loop instead seems to help smooth things out.
                //yield return async;
                while (!async.isDone)
                {
                    yield return(null);
                }
            }
            else
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene(levelName, mode);
            }
        }

        yield return(null);

        System.GC.Collect();

        yield return(null);

        Shader.WarmupAllShaders();

        // Optionally wait a short period of time after loading everything back in, but before we start rendering again
        // in order to give everything a change to settle down to avoid any hitching at the start of the new level.
        yield return(new WaitForSeconds(postLoadSettleTime));

        SteamVR_Render.pauseRendering = false;

        // Fade out loading screen.
        if (loadingScreenFadeOutTime > 0.0f)
        {
            fadeRate = -1.0f / loadingScreenFadeOutTime;
        }
        else
        {
            alpha = 0.0f;
        }

        // Fade out to compositor
        SteamVR_Events.LoadingFadeIn.Send(fadeInTime);

        // Refresh compositor reference since loading scenes might have invalidated it.
        compositor = OpenVR.Compositor;
        if (compositor != null)
        {
            // Fade out foreground color if necessary.
            if (fadedForeground)
            {
                compositor.FadeGrid(0.0f, false);
                compositor.FadeToColor(fadeInTime, 0.0f, 0.0f, 0.0f, 0.0f, false);
                yield return(new WaitForSeconds(fadeInTime));
            }
            else
            {
                // Fade scene back in, and reset skybox once no longer visible.
                compositor.FadeGrid(fadeInTime, false);
                yield return(new WaitForSeconds(fadeInTime));

                if (front != null)
                {
                    SteamVR_Skybox.ClearOverride();
                }
            }
        }

        // Finally, stick around long enough for our overlays to fully fade out.
        while (alpha > 0.0f)
        {
            yield return(null);
        }

        if (overlay != null)
        {
            if (progressBarOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
            {
                overlay.HideOverlay(progressBarOverlayHandle);
            }
            if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
            {
                overlay.HideOverlay(loadingScreenOverlayHandle);
            }
        }

        Destroy(gameObject);

        _active = null;

        SteamVR_Events.Loading.Send(false);
    }
Ejemplo n.º 2
0
 // Token: 0x06000DF2 RID: 3570 RVA: 0x00058CA0 File Offset: 0x00056EA0
 private void OnEnable()
 {
     SteamVR_Skybox.SetOverride(this.front, this.back, this.left, this.right, this.top, this.bottom);
 }
Ejemplo n.º 3
0
    // Token: 0x06005F2C RID: 24364 RVA: 0x00215578 File Offset: 0x00213978
    private IEnumerator LoadLevel()
    {
        if (this.loadingScreen != null && this.loadingScreenDistance > 0f)
        {
            SteamVR_Controller.Device hmd = SteamVR_Controller.Input(0);
            while (!hmd.hasTracking)
            {
                yield return(null);
            }
            SteamVR_Utils.RigidTransform tloading = hmd.transform;
            tloading.rot  = Quaternion.Euler(0f, tloading.rot.eulerAngles.y, 0f);
            tloading.pos += tloading.rot * new Vector3(0f, 0f, this.loadingScreenDistance);
            Transform t = (!(this.loadingScreenTransform != null)) ? base.transform : this.loadingScreenTransform;
            t.position = tloading.pos;
            t.rotation = tloading.rot;
        }
        SteamVR_LoadLevel._active = this;
        SteamVR_Events.Loading.Send(true);
        if (this.loadingScreenFadeInTime > 0f)
        {
            this.fadeRate = 1f / this.loadingScreenFadeInTime;
        }
        else
        {
            this.alpha = 1f;
        }
        CVROverlay overlay = OpenVR.Overlay;

        if (this.loadingScreen != null && overlay != null)
        {
            this.loadingScreenOverlayHandle = this.GetOverlayHandle("loadingScreen", (!(this.loadingScreenTransform != null)) ? base.transform : this.loadingScreenTransform, this.loadingScreenWidthInMeters);
            if (this.loadingScreenOverlayHandle != 0UL)
            {
                Texture_t texture_t = default(Texture_t);
                texture_t.handle      = this.loadingScreen.GetNativeTexturePtr();
                texture_t.eType       = SteamVR.instance.textureType;
                texture_t.eColorSpace = EColorSpace.Auto;
                overlay.SetOverlayTexture(this.loadingScreenOverlayHandle, ref texture_t);
            }
        }
        bool fadedForeground = false;

        SteamVR_Events.LoadingFadeOut.Send(this.fadeOutTime);
        CVRCompositor compositor = OpenVR.Compositor;

        if (compositor != null)
        {
            if (this.front != null)
            {
                SteamVR_Skybox.SetOverride(this.front, this.back, this.left, this.right, this.top, this.bottom);
                compositor.FadeGrid(this.fadeOutTime, true);
                yield return(new WaitForSeconds(this.fadeOutTime));
            }
            else if (this.backgroundColor != Color.clear)
            {
                if (this.showGrid)
                {
                    compositor.FadeToColor(0f, this.backgroundColor.r, this.backgroundColor.g, this.backgroundColor.b, this.backgroundColor.a, true);
                    compositor.FadeGrid(this.fadeOutTime, true);
                    yield return(new WaitForSeconds(this.fadeOutTime));
                }
                else
                {
                    compositor.FadeToColor(this.fadeOutTime, this.backgroundColor.r, this.backgroundColor.g, this.backgroundColor.b, this.backgroundColor.a, false);
                    yield return(new WaitForSeconds(this.fadeOutTime + 0.1f));

                    compositor.FadeGrid(0f, true);
                    fadedForeground = true;
                }
            }
        }
        SteamVR_Render.pauseRendering = true;
        while (this.alpha < 1f)
        {
            yield return(null);
        }
        base.transform.parent = null;
        UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
        if (!string.IsNullOrEmpty(this.internalProcessPath))
        {
            UnityEngine.Debug.Log("Launching external application...");
            CVRApplications applications = OpenVR.Applications;
            if (applications == null)
            {
                UnityEngine.Debug.Log("Failed to get OpenVR.Applications interface!");
            }
            else
            {
                string currentDirectory = Directory.GetCurrentDirectory();
                string text             = Path.Combine(currentDirectory, this.internalProcessPath);
                UnityEngine.Debug.Log("LaunchingInternalProcess");
                UnityEngine.Debug.Log("ExternalAppPath = " + this.internalProcessPath);
                UnityEngine.Debug.Log("FullPath = " + text);
                UnityEngine.Debug.Log("ExternalAppArgs = " + this.internalProcessArgs);
                UnityEngine.Debug.Log("WorkingDirectory = " + currentDirectory);
                EVRApplicationError evrapplicationError = applications.LaunchInternalProcess(text, this.internalProcessArgs, currentDirectory);
                UnityEngine.Debug.Log("LaunchInternalProcessError: " + evrapplicationError);
                Process.GetCurrentProcess().Kill();
            }
        }
        else
        {
            LoadSceneMode mode = (!this.loadAdditive) ? LoadSceneMode.Single : LoadSceneMode.Additive;
            if (this.loadAsync)
            {
                Application.backgroundLoadingPriority = ThreadPriority.Low;
                this.async = SceneManager.LoadSceneAsync(this.levelName, mode);
                while (!this.async.isDone)
                {
                    yield return(null);
                }
            }
            else
            {
                SceneManager.LoadScene(this.levelName, mode);
            }
        }
        yield return(null);

        GC.Collect();
        yield return(null);

        Shader.WarmupAllShaders();
        yield return(new WaitForSeconds(this.postLoadSettleTime));

        SteamVR_Render.pauseRendering = false;
        if (this.loadingScreenFadeOutTime > 0f)
        {
            this.fadeRate = -1f / this.loadingScreenFadeOutTime;
        }
        else
        {
            this.alpha = 0f;
        }
        SteamVR_Events.LoadingFadeIn.Send(this.fadeInTime);
        if (compositor != null)
        {
            if (fadedForeground)
            {
                compositor.FadeGrid(0f, false);
                compositor.FadeToColor(this.fadeInTime, 0f, 0f, 0f, 0f, false);
                yield return(new WaitForSeconds(this.fadeInTime));
            }
            else
            {
                compositor.FadeGrid(this.fadeInTime, false);
                yield return(new WaitForSeconds(this.fadeInTime));

                if (this.front != null)
                {
                    SteamVR_Skybox.ClearOverride();
                }
            }
        }
        while (this.alpha > 0f)
        {
            yield return(null);
        }
        if (overlay != null)
        {
            if (this.progressBarOverlayHandle != 0UL)
            {
                overlay.HideOverlay(this.progressBarOverlayHandle);
            }
            if (this.loadingScreenOverlayHandle != 0UL)
            {
                overlay.HideOverlay(this.loadingScreenOverlayHandle);
            }
        }
        UnityEngine.Object.Destroy(base.gameObject);
        SteamVR_LoadLevel._active = null;
        SteamVR_Events.Loading.Send(false);
        yield break;
    }
Ejemplo n.º 4
0
    // Corourtine to handle all the steps across loading boundaries.
    IEnumerator LoadLevel()
    {
        var vr = SteamVR.instance;

        // Optionally rotate loading screen transform around the camera into view.
        // We assume here that the loading screen is already facing toward the origin,
        // and that the progress bar transform (if any) is a child and will follow along.
        if (loadingScreen != null && loadingScreenDistance > 0.0f)
        {
            // Wait until we have tracking.
            var hmd = SteamVR_Controller.Input((int)OpenVR.k_unTrackedDeviceIndex_Hmd);
            while (!hmd.hasTracking)
            {
                yield return(null);
            }

            var tloading = hmd.transform;
            tloading.rot  = Quaternion.Euler(0.0f, tloading.rot.eulerAngles.y, 0.0f);
            tloading.pos += tloading.rot * new Vector3(0.0f, 0.0f, loadingScreenDistance);

            var t = loadingScreenTransform != null ? loadingScreenTransform : transform;
            t.position = tloading.pos;
            t.rotation = tloading.rot;
        }

        _active = this;

        SteamVR_Utils.Event.Send("loading", true);

        // Calculate rate for fading in loading screen and progress bar.
        if (loadingScreenFadeInTime > 0.0f)
        {
            fadeRate = 1.0f / loadingScreenFadeInTime;
        }
        else
        {
            alpha = 1.0f;
        }

        // Optionally create our loading screen overlay.
        if (loadingScreen != null)
        {
            loadingScreenOverlayHandle = GetOverlayHandle("loadingScreen", loadingScreenTransform != null ? loadingScreenTransform : transform, loadingScreenWidthInMeters);
            if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
            {
                vr.overlay.SetHighQualityOverlay(loadingScreenOverlayHandle);
                vr.overlay.SetOverlayFlag(loadingScreenOverlayHandle, VROverlayFlags.Curved, false);
                vr.overlay.SetOverlayFlag(loadingScreenOverlayHandle, VROverlayFlags.RGSS4X, true);

                var texture = new Texture_t();
                texture.handle      = loadingScreen.GetNativeTexturePtr();
                texture.eType       = vr.graphicsAPI;
                texture.eColorSpace = EColorSpace.Auto;
                vr.overlay.SetOverlayTexture(loadingScreenOverlayHandle, ref texture);
            }
        }

        bool fadedForeground = false;

        // Optionally set a skybox to use as a backdrop in the compositor.
        if (front != null)
        {
            SteamVR_Skybox.SetOverride(front, back, left, right, top, bottom);

            // Explicitly fade to the compositor since loading will cause us to stop rendering.
            vr.compositor.FadeGrid(fadeOutTime, true);
            yield return(new WaitForSeconds(fadeOutTime));
        }
        else if (backgroundColor != Color.clear)
        {
            // Otherwise, use the specified background color.
            if (showGrid)
            {
                // Set compositor background color immediately, and start fading to it.
                vr.compositor.FadeToColor(0.0f, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, true);
                vr.compositor.FadeGrid(fadeOutTime, true);
                yield return(new WaitForSeconds(fadeOutTime));
            }
            else
            {
                // Fade the foreground color in (which will blend on top of the scene), and then cut to the compositor.
                vr.compositor.FadeToColor(fadeOutTime, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, false);
                yield return(new WaitForSeconds(fadeOutTime + 0.1f));

                vr.compositor.FadeGrid(0.0f, true);
                fadedForeground = true;
            }
        }

        // Now that we're fully faded out, we can stop submitting frames to the compositor.
        SteamVR_Render.pauseRendering = true;

        // Continue waiting for the overlays to fully fade in before continuing.
        while (alpha < 1.0f)
        {
            yield return(null);
        }

        // Keep us from getting destroyed when loading the new level, otherwise this coroutine will get stopped prematurely.
        transform.parent = null;
        DontDestroyOnLoad(gameObject);

        // Loading asynchronously so we can update the progress bar above.
        async = loadAdditive ? Application.LoadLevelAdditiveAsync(levelName) : Application.LoadLevelAsync(levelName);
        yield return(async);

        System.GC.Collect();

        // Optionally wait a short period of time after loading everything back in, but before we start rendering again
        // in order to give everything a change to settle down to avoid any hitching at the start of the new level.
        yield return(new WaitForSeconds(postLoadSettleTime));

        SteamVR_Render.pauseRendering = false;

        // Fade out loading screen.
        if (loadingScreenFadeOutTime > 0.0f)
        {
            fadeRate = -1.0f / loadingScreenFadeOutTime;
        }
        else
        {
            alpha = 0.0f;
        }

        // Fade out foreground color if necessary.
        if (fadedForeground)
        {
            vr.compositor.FadeGrid(0.0f, false);
            vr.compositor.FadeToColor(fadeInTime, 0.0f, 0.0f, 0.0f, 0.0f, false);
            yield return(new WaitForSeconds(fadeInTime));
        }
        else
        {
            // Fade scene back in, and reset skybox once no longer visible.
            vr.compositor.FadeGrid(fadeInTime, false);
            yield return(new WaitForSeconds(fadeInTime));

            if (front != null)
            {
                SteamVR_Skybox.ClearOverride();
            }
        }

        // Finally, stick around long enough for our overlays to fully fade out.
        while (alpha > 0.0f)
        {
            yield return(null);
        }

        Destroy(gameObject);

        _active = null;

        SteamVR_Utils.Event.Send("loading", false);
    }