Version: 2022.3

Display

class in UnityEngine

切换到手册

描述

提供对显示器/屏幕的访问,以便进行渲染操作。

Unity supports multi-display rendering on: Desktop platforms (Windows, macOS X, and Linux) Android (OpenGL ES and Vulkan) iOS Some features in the Display class only work on some of the supported platforms. See the properties and methods for more information about platform compatibility.

使用 Display 类可在显示器本身上进行操作,使用 Camera.targetDisplay 可设置摄像机,以便分别渲染到各显示器。

另请参阅:Camera.targetDisplayCanvas.targetDisplay

using UnityEngine;

public class Example : MonoBehaviour { Camera extCam; Camera cam;

void Start() { // GUI is rendered with last camera. // As we want it to end up in the main screen, make sure main camera is the last one drawn. extCam.depth = cam.depth - 1;

cam.SetTargetBuffers(Display.main.colorBuffer, Display.main.depthBuffer); extCam.enabled = false; }

void Update() { if (Display.displays.Length > 1 && !extCam.enabled) { Display.displays[1].SetRenderingResolution(256, 256); extCam.SetTargetBuffers(Display.displays[1].colorBuffer, Display.displays[1].depthBuffer); } extCam.enabled = Display.displays.Length > 1; } }

静态变量

activeEditorGameViewTargetGet the Editors active GameView display target.
displaysThe list of connected displays.
main主显示器。

变量

active获取该显示器的状态,如果该显示器处于活动状态,返回 true,否则返回 false。
colorBuffer颜色 RenderBuffer。
depthBuffer深度 RenderBuffer。
renderingHeight该显示器正在渲染时所采用的垂直分辨率。
renderingWidthHorizontal resolution that the display is rendering at in the viewport.
requiresBlitToBackbuffer当后缓冲区需要中间纹理进行渲染时为 true。
requiresSrgbBlitToBackbuffer当对后缓冲区进行 blit 需要手动进行颜色空间转换时为 true。
systemHeight垂直原生显示分辨率。
systemWidth水平原生显示分辨率。

公共函数

ActivateActivates an external display. For example, a secondary monitor connected to the system.
SetParamsWindows platforms only. Sets rendering size and position on screen.
SetRenderingResolution设置该显示器的渲染分辨率。

静态函数

RelativeMouseAt查询相对鼠标坐标。