facebook twitter hatena line email

Unity/端末の向き

提供: 初心者エンジニアの簡易メモ
2019年9月25日 (水) 00:20時点におけるAdmin (トーク | 投稿記録)による版 (固定からautoローテーションできるように)

移動: 案内検索

端末の向き

File/BuildSettingsからPlayerSettingsボタンを押し "Resolution and Presentation"のorientationを変更する

  • portrait:縦
  • landscape:横

縦だけにすると、androidにおいて、インストール端末から、テレビやウェアラブル(時計)が除外される。

↓縦のみにした時の設定ファイル変更 ProjectSettings/ProjectSettings.asset

  allowedAutorotateToPortrait: 1
-  allowedAutorotateToPortraitUpsideDown: 1
-  allowedAutorotateToLandscapeRight: 1
-  allowedAutorotateToLandscapeLeft: 1
+  allowedAutorotateToPortraitUpsideDown: 0
+  allowedAutorotateToLandscapeRight: 0
+  allowedAutorotateToLandscapeLeft: 0

csで書くならこう?

using UnityEditor;
PlayerSettings.allowedAutorotateToLandscapeRight  = false;
PlayerSettings.allowedAutorotateToLandscapeLeft   = false;
PlayerSettings.allowedAutorotateToPortrait        = true;
PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;

https://qiita.com/takeswim/items/dff6a6be5afa258ac474

固定からautoローテーションできるように

Screen.autorotateToPortrait = true;
Screen.autorotateToLandscapeRight = false;
Screen.autorotateToLandscapeLeft = true;
Screen.autorotateToPortraitUpsideDown = false;

以下だと"CS0103: The name 'PlayerSettings' does not exist in the current context"なエラーが出るので注意

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

端末向き

Screen.orientation; // 現在の向き
ScreenOrientation.LandscapeLeft; // 横左
ScreenOrientation.LandscapeRight; // 横右
ScreenOrientation.Portrait; // 縦

端末の向き許可設定

falseにすると禁止となる

// 縦
Screen.autorotateToPortrait = true;
// 左
Screen.autorotateToLandscapeLeft = true;
// 右
Screen.autorotateToLandscapeRight = true;
// 上下反転
Screen.autorotateToPortraitUpsideDown = true;

https://qiita.com/satotin/items/2009788da11805a4a9cf