如何冻结屏幕? [英] How to freeze the screen?

查看:472
本文介绍了如何冻结屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Unity中,如何在一个场景中冻结屏幕,更改场景,然后在另一个场景中解冻屏幕?冻结屏幕只不过意味着冻结时不会更新.在屏幕上,我的意思仅仅是:

In Unity, how can I freeze the screen in one scene, change scene, and then unfreeze it in the other scene? With freezing the screen I simply mean that it doesn't get updated while it's frozen. With screen I simply mean this:

我尝试将Time.timeScale设置为0,但这没用.

I've tried to set Time.timeScale = 0, but that didn't work.

问题是我在场景中具有不同的屏幕方向:第一个是肖像,另一个是风景.这将导致第二个场景扭曲/破坏第一个场景中加载的加载屏幕.在第二个场景中初始化的内容需要横向显示,因此我不能仅在所有内容都初始化后更改屏幕方向.

The thing is that I have different screen orientations in the scenes: portrait in the first and landscape in the other. This causes the second scene to twist/ruin the loading screen that was loaded in the first scene. The stuff being initialized in the second scene demands landscape orientation, so I can't just change the screen orientation after everything have been initialized.

我只想在加载图像加载后冻结屏幕,然后在初始化第二个场景后将其解冻.这可能吗?

I just want to freeze the screen after the loading image has loaded and then unfreeze it after the second scene has been initialized. Is this possible?

这是我目前的代码,概括为:

This is my code at the moment, generalized:

// Script for the first scene
class firstClass(){
    IEnumerator ChangeScene(){
        // Display loading screen in portrait orientation
        loadingScreen.SetActive(true);
        // Load the second scene
        SceneManager.LoadSceneAsync("secondScene");
    }
}

// Script for the second scene
class secondClass(){
     Start(){
         Screen.orientation = ScreenOrientation.LandscapeLeft; // twists the loading screen :(
         Init(a lot of stuff) // Needs landscape orientation to be initialized properly

         // Init done, hide loading screen
         loadingScreen.SetActive(false);

     }
}

这就是我想要的工作方式:

This is how I want it to work:

class firstClass(){
    IEnumerator ChangeScene(){
        // Display loading screen in portrait orientation
        loadingScreen.SetActive(true);
        FreezeScreen();
        SceneManager.LoadSceneAsync("secondScene");
    }
}

class secondClass(){
     Start(){
         Screen.orientation = ScreenOrientation.LandscapeLeft; // doesn't affect the loading screen because the screen is frozen!
         Init(a lot of stuff);
         UnfreezeScreen();
         // Init done, hide loading screen
         loadingScreen.SetActive(false);

     }
}

这是一个例子: https://gyazo.com/864303465be750b7970636415ddf070d

推荐答案

确实,这不仅在统一性中而且在任何游戏引擎中都是预期的行为.

As truly this is expected behavior not only in unity, but in any game engine.

我为什么这么认为? 当您加载另一个场景时-旧场景必须被破坏:)因为它占用了大量资源:)

Why I think so? When you load another scene -- old scene must be destroyed :) As it's takes lot of resources :)

我认为,您需要保存有关场景中对象设置的所有信息.加载另一个场景.做你所需要的.然后切换回该场景并从设置中还原.

As I think, you need to save all info about objects settings on the scene. Load another scene. Do what do you need. And switch back to this scene and restore from settings.

或通过另一种方式提出您的问题:告知预期结果并询问如何更好地做到这一点:)

or to ask your question by another way: tell about expected result and ask how to do this better :)

这篇关于如何冻结屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆