RegisterLayoutChangedCallback(Action<DisplayLayoutChangedEventArgs>)
Registers a callback that Unity invokes when the display layout changes, for example when a display is connected or disconnected.
Read time 1 minuteLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
public static void RegisterLayoutChangedCallback(Action<DisplayLayoutChangedEventArgs> callback)
Parameters
The callback to invoke when the display layout changes. If is null, Unity throws an .
callbackArgumentNullExceptionRemarks
Unity invokes the callback on the main thread at most once per frame, even if several displays change in the same frame. The callback does not report which display changed; call DisplayInfo.GetLayout from the callback to read the new layout. Discard any DisplayInfo values you stored before the callback, because the operating system can renumber displays when one is disconnected. This method is supported only in Linux, Embedded Linux and QNX players. In the Editor and on other platforms it throws a . The changes a platform reports depend on the operating system. Linux and Embedded Linux report connected, disconnected, orientation, and mode changes. QNX reports connected and disconnected displays. On QNX, the last connected display stays in the layout that DisplayInfo.GetLayout returns until another display connects.
NotSupportedExceptionExamples
using System.Collections.Generic;using UnityEngine;public class DisplayLayoutWatcher : MonoBehaviour{ private List<DisplayInfo> displays = new List<DisplayInfo>(); void OnEnable() { DisplayInfo.RegisterLayoutChangedCallback(OnDisplayLayoutChanged); } void OnDisable() { DisplayInfo.UnregisterLayoutChangedCallback(OnDisplayLayoutChanged); } void OnDisplayLayoutChanged(DisplayLayoutChangedEventArgs args) { DisplayInfo.GetLayout(displays); Debug.Log("Display layout changed. Display count: " + displays.Count); }}