使用多显示功能可以同时在最多八台不同的监视器上显示应用程序的最多八个不同摄像机视图。此功能可用于 PC 游戏、街机游戏机或公共显示装置等设施。
Unity 在以下平台上支持多显示功能:
Unity 的默认显示模式仅为一台监视器。在运行应用程序时,需要使用 Display.Activate()
显式激活其他显示。激活的显示不能停用。
激活额外显示的最佳时间是在应用程序创建新场景时。一个好方法是将脚本组件附加到默认摄像机。确保仅在启动过程中调用一次 Display.Activate()
。一般情况下,创建一个小的初始场景来测试脚本可能会很有帮助。
using UnityEngine;
using System.Collections;
public class ActivateAllDisplays : MonoBehaviour
{
void Start ()
{
Debug.Log ("displays connected: " + Display.displays.Length);
// Display.displays[0] 是主要的默认显示,并始终为 ON,因此从索引 1 开始。
// 检查是否有其他可用的显示,并激活每个显示。
for (int i = 1; i < Display.displays.Length; i++)
{
Display.displays[i].Activate();
}
}
void Update()
{
}
}
要预览不同的摄像机视图,请按照以下步骤操作:
确保当前处于 Game 视图中。
从左上角的 Display 菜单中,选择要预览的 Display 选项。
Unity 支持以下 UnityEngine.Display API 方法:
方法 | 描述 |
---|---|
public void Activate() |
根据当前监视器的宽度和高度激活具体显示。必须在启动新场景时进行一次此调用。可从新场景中的__摄像机__或虚拟__游戏对象__附加的用户脚本进行此调用。 |
public void Activate(int width, int height, int refreshRate) |
仅限 Windows。激活自定义宽度和高度的特定显示。在 Linux 和 macOS X 上,辅助显示上始终使用当前显示分辨率(如果可用)。 |
默认情况下,用户的计算机会根据其 x、y 虚拟桌面对其监视器的相对位置进行排序。要覆盖此设置以便应用程序显示时不进行任何排序,请从命令行启动应用程序并使用 -multidisplay
命令行标志。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.