如何设置始终在前台的三个显示监视器的Unity应用程序?

时间:2018-08-11 13:34:25

标签: unity3d foreground setforegroundwindow

我用3个显示监视器构建一个统一的应用程序。 这是开始功能:

 void Start () {

    for (int i=0; i<Display.displays.Length; i++)
    {
        Display.displays[i].Activate(1024, 768, 60);
    }
}

但是,如果我使用函数“ Display.displays [i] .Activate()”,则无法始终在前台设置统一应用程序。 我将以下脚本添加到我的统一应用程序中,但是它不起作用。

 using UnityEngine;
 using System;
 using System.Collections;
 using System.Runtime.InteropServices;

 public class ForeGrounder : MonoBehaviour {

 private const uint LOCK = 1;
 private const uint UNLOCK = 2;

 private IntPtr window;

 void Start() {
     LockSetForegroundWindow(LOCK);
     window = GetActiveWindow();
     StartCoroutine(Checker());
 }

 IEnumerator Checker() {
     while (true) {

         yield return new WaitForSeconds(1);
         IntPtr newWindow = GetActiveWindow();

         if (window != newWindow) {
             Debug.Log("Set to foreground");
             SwitchToThisWindow(window, true);
         }
     }
 }

 [DllImport("user32.dll")]
 static extern IntPtr GetActiveWindow();
 [DllImport("user32.dll")]
 static extern bool LockSetForegroundWindow(uint uLockCode);
 [DllImport("user32.dll")]
 static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
 }

我该如何解决这个问题?

0 个答案:

没有答案