如何防止第 8 面墙 XR 在 Unity 中更改我的默认方向?



每次我构建时,它都会变回 Portrait。 我找不到在哪里禁用此自动更改。 可以做到吗?

进入玩家设置,将方向设置为自动旋转以外的任何内容,它不会更改。

您还可以以编程方式更改方向。 只需确保在加载AR场景之前将其设置回固定方向即可。 例如,如果您希望在非AR场景中启用自动旋转,则可以设置屏幕方向=屏幕方向自动旋转,然后在加载AR场景之前,只需将其设置回纵向或横向即可。

如果你想变得花哨,你也可以在用户按下用于启动AR场景的任何按钮时自动检测设备的方向,方法是首先检查Input.deviceOrientation,然后将Screen.orientation设置为该方向。

下面是一个示例 - Run(( 函数启动您的场景(首先检查设备方向并据此设置屏幕方向后(:

void Run(String scene) {
// Lock orientation to current device orientation prior to loading AR scene 
switch (Input.deviceOrientation) {
case DeviceOrientation.Portrait:
Screen.orientation = ScreenOrientation.Portrait;
break;
case DeviceOrientation.PortraitUpsideDown:
Screen.orientation = ScreenOrientation.PortraitUpsideDown;
break;;
case DeviceOrientation.LandscapeLeft:
Screen.orientation = ScreenOrientation.LandscapeLeft;
break;;
case DeviceOrientation.LandscapeRight:
Screen.orientation = ScreenOrientation.LandscapeRight;
break;;
default:
// if Unknown, just set to Portrait
Screen.orientation = ScreenOrientation.Portrait;
break;
}
SceneManager.LoadScene(scene);
}

最新更新