我已使用 Application.OpenURL
将我的用户发送到浏览器。现在我想以编程方式将统一带回前台。
有没有不用插件的方法呢?
谢谢。
最佳答案
在将用户送走之前使用 GetActiveWindow
获取窗口的句柄,然后使用该句柄使用 SetForegroundWindow
。在使用 SetForegroundWindow
之前,您可以 try simulating an Alt keypress调出要遵守的菜单certain limitations SetForegroundWindow
:
private IntPtr unityWindow;
[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
const int ALT = 0xA4;
const int EXTENDEDKEY = 0x1;
const int KEYUP = 0x2;
private void SendUser()
{
unityWindow = GetActiveWindow();
Application.OpenURL("http://example.com");
StartCoroutine(RefocusWindow(30f));
}
private IEnumerator RefocusWindow(float waitSeconds) {
// wait for new window to appear
yield return new WaitWhile(() => unityWindow == GetActiveWindow());
yield return new WaitForSeconds(waitSeconds);
// Simulate alt press
keybd_event((byte)ALT, 0x45, EXTENDEDKEY | 0, 0);
// Simulate alt release
keybd_event((byte)ALT, 0x45, EXTENDEDKEY | KEYUP, 0);
SetForegroundWindow(unityWindow);
}
关于c# - 有什么方法可以将 Unity3d 带到前台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29092145/