「Unity/端末の向き」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→端末の向き) |
(→向き確認) |
||
| (同じ利用者による、間の13版が非表示) | |||
| 行1: | 行1: | ||
==端末の向き== | ==端末の向き== | ||
| − | File/ | + | File/BuildSettingsからPlayerSettingsボタンを押し |
| + | "Resolution and Presentation"のorientationを変更する | ||
*portrait:縦 | *portrait:縦 | ||
*landscape:横 | *landscape:横 | ||
| + | |||
| + | 縦だけにすると、androidにおいて、インストール端末から、テレビやウェアラブル(時計)が除外される。 | ||
| + | |||
| + | ↓縦のみにした時の設定ファイル変更 | ||
| + | ProjectSettings/ProjectSettings.asset | ||
| + | allowedAutorotateToPortrait: 1 | ||
| + | - allowedAutorotateToPortraitUpsideDown: 1 | ||
| + | - allowedAutorotateToLandscapeRight: 1 | ||
| + | - allowedAutorotateToLandscapeLeft: 1 | ||
| + | + allowedAutorotateToPortraitUpsideDown: 0 | ||
| + | + allowedAutorotateToLandscapeRight: 0 | ||
| + | + allowedAutorotateToLandscapeLeft: 0 | ||
| + | |||
| + | csで書くならこう? | ||
| + | <pre> | ||
| + | using UnityEditor; | ||
| + | PlayerSettings.allowedAutorotateToLandscapeRight = false; | ||
| + | PlayerSettings.allowedAutorotateToLandscapeLeft = false; | ||
| + | PlayerSettings.allowedAutorotateToPortrait = true; | ||
| + | PlayerSettings.allowedAutorotateToPortraitUpsideDown = false; | ||
| + | </pre> | ||
| + | |||
| + | https://qiita.com/takeswim/items/dff6a6be5afa258ac474 | ||
| + | |||
| + | ==固定からautoローテーションできるように== | ||
| + | |||
| + | <pre> | ||
| + | Screen.autorotateToPortrait = true; | ||
| + | Screen.autorotateToLandscapeRight = false; | ||
| + | Screen.autorotateToLandscapeLeft = true; | ||
| + | Screen.autorotateToPortraitUpsideDown = false; | ||
| + | </pre> | ||
| + | |||
| + | 以下だと"CS0103: The name 'PlayerSettings' does not exist in the current context"なエラーが出るので注意 | ||
| + | <pre> | ||
| + | PlayerSettings.defaultInterfaceOrientation = UIOrientation.AutoRotation; | ||
| + | PlayerSettings.allowedAutorotateToLandscapeRight = false; | ||
| + | PlayerSettings.allowedAutorotateToLandscapeLeft = true; | ||
| + | PlayerSettings.allowedAutorotateToPortrait = true; | ||
| + | PlayerSettings.allowedAutorotateToPortraitUpsideDown = false; | ||
| + | </pre> | ||
| + | |||
| + | ==端末向き== | ||
| + | <pre> | ||
| + | Screen.orientation; // 現在の向き | ||
| + | ScreenOrientation.LandscapeLeft; // 横左 | ||
| + | ScreenOrientation.LandscapeRight; // 横右 | ||
| + | ScreenOrientation.Portrait; // 縦 | ||
| + | </pre> | ||
| + | |||
| + | ==端末の向き許可設定== | ||
| + | falseにすると禁止となる | ||
| + | <pre> | ||
| + | // 縦 | ||
| + | Screen.autorotateToPortrait = true; | ||
| + | // 左 | ||
| + | Screen.autorotateToLandscapeLeft = true; | ||
| + | // 右 | ||
| + | Screen.autorotateToLandscapeRight = true; | ||
| + | // 上下反転 | ||
| + | Screen.autorotateToPortraitUpsideDown = true; | ||
| + | </pre> | ||
| + | https://qiita.com/satotin/items/2009788da11805a4a9cf | ||
| + | |||
| + | ==向き確認== | ||
| + | <pre> | ||
| + | void Update() | ||
| + | { | ||
| + | Debug.Log("Input.deviceOrientation=" + Input.deviceOrientation); // Portrait // 縦の場合 | ||
| + | } | ||
| + | </pre> | ||
2023年8月21日 (月) 18:06時点における最新版
端末の向き
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
向き確認
void Update()
{
Debug.Log("Input.deviceOrientation=" + Input.deviceOrientation); // Portrait // 縦の場合
}
