SwapchainPreTransform
The rotations that Unity can apply during rendering to match the native orientation of the device's display panel.
読み終わるまでの所要時間 2 分最終更新 4時間前
Definition
- Type: Enum
- Namespace: UnityEngine.Rendering
- Assembly: UnityEngine.CoreModule
public enum SwapchainPreTransform
Remarks
On devices that support pre-rotation, Unity can render each frame to the backbuffer already rotated to the native orientation of the display panel. This saves the operating system from rotating the image again before it displays it. Use Screen.currentSwapChainPreTransform to find out which rotation Unity applies in the current frame. For more information, refer to Framebuffer orientation.
Each value is relative to the native orientation of the display panel, not to portrait or landscape. For example, a landscape app reports a 90-degree or 270-degree rotation on most phones, but no rotation on most tablets. Don't use these values to detect the screen orientation. Use Screen.orientation instead.
Each value matches a Vulkan surface transform (). Vulkan defines these rotations as clockwise rotations of the image content.
VkSurfaceTransformFlagBitsKHRA 90-degree or 270-degree rotation swaps the width and height of the native backbuffer relative to Screen.width and Screen.height. Unity adjusts the C# API, viewports, and scissor rectangles for you. You only need to handle the rotation yourself if you write directly to the backbuffer, for example from a native rendering plug-in, or in shaders that don't use Unity's projection matrix.
Additional Resources: Screen.currentSwapChainPreTransform, SystemInfo.supportsSwapChainPreTransform, QualitySettings.disableSwapChainPreTransform.
Examples
// Attach this script to a GameObject in a scene.// This example logs the pre-rotation that Unity applies whenever it changes, for example when the user rotates the device.using UnityEngine;using UnityEngine.Rendering;public class PreTransformLogger : MonoBehaviour{ SwapchainPreTransform m_LastPreTransform; void Start() { if (!SystemInfo.supportsSwapChainPreTransform) Debug.Log("This device doesn't support pre-rotation, so the pre-transform is always SwapchainPreTransform.Identity."); m_LastPreTransform = Screen.currentSwapChainPreTransform; Debug.Log("Initial pre-transform: " + m_LastPreTransform); } void Update() { SwapchainPreTransform preTransform = Screen.currentSwapChainPreTransform; if (preTransform == m_LastPreTransform) return; m_LastPreTransform = preTransform; // A 90-degree or 270-degree rotation swaps the width and height of the native backbuffer. bool swapsWidthAndHeight = preTransform == SwapchainPreTransform.Rotate90 || preTransform == SwapchainPreTransform.Rotate270; Debug.Log("Pre-transform changed to " + preTransform + ". Native backbuffer width and height swapped: " + swapsWidthAndHeight); }}
Fields
Value | Description |
|---|---|
| Identity | No rotation. The rendered image already matches the native orientation of the display panel. |
| Rotate180 | Unity rotates rendering by 180 degrees to match the native orientation of the display panel. |
| Rotate270 | Unity rotates rendering by 270 degrees clockwise to match the native orientation of the display panel. |
| Rotate90 | Unity rotates rendering by 90 degrees clockwise to match the native orientation of the display panel. |