-
Notifications
You must be signed in to change notification settings - Fork 14
/
Display.cs
51 lines (48 loc) · 1.22 KB
/
Display.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
public class Display : MonoBehaviour
{
async Task MoveWindowTask (int index) // Minimum Unity Version required: 2021.2
{
List<DisplayInfo> displayLayout = new List<DisplayInfo>();
Screen.GetDisplayLayout(displayLayout);
if (index < displayLayout.Count)
{
DisplayInfo display = displayLayout[index];
Vector2Int position = new Vector2Int(0, 0);
if (Screen.fullScreenMode != FullScreenMode.Windowed)
{
position.x += display.width / 2;
position.y += display.height / 2;
}
AsyncOperation asyncOperation = Screen.MoveMainWindowTo(display, position);
while (asyncOperation.progress < 1f)
{
await Task.Yield();
}
}
else
{
await Task.CompletedTask;
}
}
async void MoveWindowAsync (int index)
{
await MoveWindowTask (index);
}
void Update()
{
for (KeyCode keyCode = KeyCode.Keypad0; keyCode <= KeyCode.Keypad9; keyCode++)
{
if (Input.GetKeyDown(keyCode))
{
string key = keyCode.ToString();
int index = System.Convert.ToInt32(key[key.Length-1].ToString());
MoveWindowAsync(index);
break;
}
}
}
}