0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Unity】java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation

Posted at

問題自体は、以下の記事で紹介されてるものと同じです。

java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation

この記事では解決策の1つを紹介します。

解決策

1.PlayerSettings>Resolution Scalingで、OrientationAllowed Orientations for AutoRotationの設定を以下のようにする。
image.png

2.[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]を使い、Sceneが読み込まれる前に画面を縦に固定させます。

以下のScriptをプロジェクトに追加するだけで済みます。

RotationController.cs
using UnityEngine;

public static class RotationController
{
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    public static void Initialize()
    {
        // 縦画面に固定する場合の設定です
        Screen.autorotateToPortrait = true; // 縦
        Screen.autorotateToLandscapeLeft = false; // 左
        Screen.autorotateToLandscapeRight = false; // 右
        Screen.autorotateToPortraitUpsideDown = false; // 上下逆        
        Screen.orientation = ScreenOrientation.Portrait;
    }
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]については、参考資料も紹介しておきます。
http://tsubakit1.hateblo.jp/entry/2016/07/29/073000

デバイスを横にしたまま起動すると、起動直後はUnityのロゴが横になって表示され、起動直後も一瞬横画面で表示されるかもしれませんが、その後すぐに縦画面に固定されプレイ体験としてはほぼほぼ問題ないものになります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?