LoginSignup
5
4

More than 5 years have passed since last update.

Landscapeのみのautorotationにしようとしたらportrait設定が活きてしまう問題対応

Posted at

横画面固定だが、ホームボタンが右でも左でも大丈夫なようにしようとしたとき、ビルドスクリプト側でこんな風に書いてました。

BatchBuild.cs
PlayerSettings.defaultInterfaceOrientation = UIOrientation.AutoRotation;
PlayerSettings.allowedAutorotateToPortrait        = false;
PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;
PlayerSettings.allowedAutorotateToLandscapeRight  = true;
PlayerSettings.allowedAutorotateToLandscapeLeft   = true;

しかし何故か!縦画面ローテートが活きてしまう。何でだろう…と思ってたら実行時のメッセージにこんな表示が。

all orientations are disabled for auto-rotation. Enabling Portrait
UnityEditor.PlayerSettings:set_allowedAutorotateToPortrait(Boolean)
BatchBuild:AndroidBuild(Boolean) (at Assets/Editor/BatchBuild.cs:90)
BatchBuild:AndroidDevelopmentBuild() (at Assets/Editor/BatchBuild.cs:38)

90行目というのがちょうどPlayerSettings.allowedAutorotateToPortrait=falseを設定しようとしているところで、うーんつまり「オートローテーションで全方向disableになってるから、portraitをenableにするね!」ということか?

じゃあfalseのところをコメントアウトしたらいいのかな?と思いましたが、これも失敗。

結論としてこれでいけました。

BatchBuild.cs
PlayerSettings.defaultInterfaceOrientation = UIOrientation.AutoRotation;
PlayerSettings.allowedAutorotateToLandscapeRight  = true;
PlayerSettings.allowedAutorotateToLandscapeLeft   = true;
PlayerSettings.allowedAutorotateToPortrait        = false;
PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;

…うーん、何だか腑に落ちない…

5
4
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
5
4