文档

Unity Engine

Unity Engine

currentSwapChainPreTransform

The rotation that Unity applies during rendering to match the native orientation of the device's display panel.
阅读时间2 分钟最后更新于 16 小时前

Definition

  • Type: Property
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public static SwapchainPreTransform currentSwapChainPreTransform { get; }

Remarks

When pre-rotation is active, Unity renders each frame to the backbuffer already rotated to the native orientation of the display panel, so the operating system doesn't need to rotate the image again before it displays it. Use this property to find out which rotation Unity applies in the current frame. For more information, refer to Framebuffer orientation.
This value isn't a screen orientation or a device orientation. It describes the rotation of the app's window relative to the native orientation of the display panel, which differs between devices:
To find out whether the app is in portrait or landscape, use Screen.orientation. To read the physical orientation of the device, use Input.deviceOrientation.
The value is SwapchainPreTransform.Identity in the following cases, because Unity doesn't apply pre-rotation:
  • The platform or graphics API doesn't support pre-rotation. Only Android with the Vulkan graphics API supports pre-rotation.
  • Apply display rotation during rendering is disabled in the Android Player settings. To check this setting from an Editor script, use PlayerSettings.vulkanEnablePreTransform.
  • The app has no visible window, for example when it's in the background.
  • The app runs in the Unity Editor, including the Device Simulator.
Unity applies pre-rotation only when it renders to the backbuffer, not when it renders to a RenderTexture. When Unity renders to the backbuffer, the shader constant
UNITY_DISPLAY_ORIENTATION_PRETRANSFORM
has the matching value.
Unity updates this value when it recreates the swapchain after the display rotates. During a rotation, this value can briefly differ from Screen.orientation.
Additional Resources: SwapchainPreTransform.