有什么方法可以使Unity3d成为前台?

pet*_*ept 5 c# unity-game-engine

我已使用将用户发送到浏览器Application.OpenURL。现在,我想以编程方式使团结回到前台。

没有插件,有什么办法吗?

谢谢。

Dav*_*vid 0

如果您在 Windows 中使用 Unity3D,请在调用 Application.OpenURL(...) 后尝试以下代码:

[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);

var prc = Process.GetProcessesByName("..."); //Get Unity's process, or 
var prc = Process.GetCurrentProcess();
if (prc.Length > 0) 
    SetForegroundWindow(prc[0].MainWindowHandle);
Run Code Online (Sandbox Code Playgroud)

  • 还没有运气。上面的代码始终为窗口句柄返回 0。我将其更改为 EnumWindows 并且确实获得了有效的窗口句柄。但调用 SetForegroundWIndow() 没有任何效果。我会继续挖掘。 (2认同)