[Unity] 橫向播放影片,播完轉回直向。ScreenOrientation Bug?
Autorotation Bug
大部分的 App 通常並不會同時支援橫向與直向的功能
然而透過播放影片時,又希望使用者能夠看到全螢幕的畫面
最完美的解法當然是在播放影片時
可以讓使用者自己旋轉螢幕
然後播放完畢再轉回原本 App 的直向或橫向
可惜 Unity 中的 Runtime Autorotation 似乎有 Bug
並無法透過程式順利動態調整:
// Not working code Screen.autorotateToLandscapeLeft = true; Screen.autorotateToLandscapeRight = true; Screen.autorotateToPortrait = true; Screen.autorotateToPortraitUpsideDown = true; Screen.orientation = ScreenOrientation.AutoRotation;
PlayFullScreen Movie by Coroutine
退而求其次,我們可以做到的是指定轉向的功能
只是一旦設定過 Screen Orientation 之後
裝置就沒有自動轉向的功能了
即使是只有上下或只有左右的旋轉都會失效
當你下播放影片的指令時 Handheld.PlayFullScreenMovie
Unity 會根據你原本設定的 orientation 去做播放
因此如果在 PlayFullScreenMovie 之前去調整 Screen Orientation 是沒有用的
他一樣會轉回來
所以得要利用 Coroutine,讓程序卡在 screen.orientation 處
這樣就可以順利進行旋轉了
// Play video from persistent path private IEnumerator PlayVideo( string path ) { #if UNITY_IOS path = "file://" + path; #endif Handheld.PlayFullScreenMovie( path ); yield return Screen.orientation = ScreenOrientation.LandscapeLeft; Screen.orientation = ScreenOrientation.Portrait; }
歡迎您留言與分享!(Welcome for comments or sharing!)
- [Unity] WWW v.s HttpWebRequest & HttpWebResponse
- [Unity] PlayFullScreenMovie from PersistentDataPath (iOS + Android)