2016-08-05 108 views
-1

在Unity中,如何凍結一個場景中的屏幕,更改場景,然後在其他場景中解凍它?通過凍結屏幕,我只是表示它在凍結時不會更新。屏幕我只是這個意思:https://i.gyazo.com/10f8673d28da776c064fbb0e716866ad.jpg如何凍結屏幕?

我試過設置Time.timeScale = 0,但沒有奏效。

事情是我在場景中有不同的屏幕方向:第一個是肖像,第二個是風景。這會導致第二個場景扭曲/毀壞第一個場景中加載的加載屏幕。在第二個場景中初始化的東西需要橫向定位,所以我不能在所有東西都初始化後改變屏幕方向。

我只想在加載圖像加載後凍結屏幕,然後在第二個場景初始化後解凍屏幕。這可能嗎?

這是我的代碼的那一刻,廣義:

// 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); 

    } 
} 

這是我想要的工作:

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

+0

你是什麼意思凍結?你的意思是讓方向保持不變而不改變? – Programmer

+0

是的,確切地說。即使改變屏幕方向,我也希望屏幕上顯示的內容保持不變。 – Johan

+0

「凍結」屏幕的含義完全不清楚。你將不得不刪除這個詞。可能是你想***禁用旋轉***或許在你的加載過程中,只有***啓用旋轉***以後? – Fattie

回答

0
void freezeOrientation(bool freezeOrnt = true) 
{ 
    Screen.autorotateToLandscapeLeft = freezeOrnt; 
    Screen.autorotateToLandscapeRight = freezeOrnt; 
    Screen.autorotateToPortrait = freezeOrnt; 
    Screen.autorotateToPortraitUpsideDown = freezeOrnt; 
} 

凍結方向

freezeOrientation(true); 

取消凍結取向

freezeOrientation(false); 
+0

謝謝,但沒有,它沒有工作。我認爲我的問題現在更加明確,請檢查我的編輯 – Johan

+0

**「我認爲我的問題現在更加明確**」我不這麼認爲。我改變了標題是有道理的,然後你把它改回了一些毫無意義的東西。你在問題中的更新代碼看起來不像我答案中的代碼。在更新代碼以反映我的答案之前,我無法確定你做錯了什麼。我所有的代碼正在做的是禁用旋轉是所有的方向。 – Programmer

0

使用在需要的方向修改場景下面你Start()Awake()活動對象上線。選擇與您的預期方向有關的任何行

void Awake() 
{ 
Screen.orientation = ScreenOrientation.LandscapeLeft; 
//OR 
Screen.orientation = ScreenOrientation.Portrait; 
} 

由於這些是邏輯方向,所以觸摸座標也隨當前方向改變。

您需要修改第二類啓動,以便在初始化和禁用加載場景後進行橫向調整。

class secondClass(){ 
void Start() 
{ 
     Init(a lot of stuff); 

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

     Screen.orientation = ScreenOrientation.LandscapeLeft; 
} 
} 
0

誠然,這是預期的行爲,不僅在統一,而且在任何遊戲引擎。

爲什麼我這麼認爲? 當你加載另一個場景 - 舊場景必須被破壞:)因爲它需要很多資源:)

因爲我認爲,你需要保存關於對象設置的所有信息在場景中。加載另一個場景。做你需要的東西。然後切換回此場景並從設置中恢復。

或者通過另一種方式來問你的問題:告訴預期的結果,並詢問如何做到這一點更好:)