c# - 有什么方法可以将 Unity3d 带到前台?

标签 c# unity3d

我已使用 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/

相关文章:

unity3d - 捷运 | HoloLens - 获取对象内网格的所有三角形

c# - 编辑网页值并通过单击按钮提交?

c# - 需要结合 WHERE、AND、OR 的 SQL 帮助

c# - 使用 Unity IoC 时如何实现 Ninject .InSingletonScope()

c# - 如何检测 UI 和 GameObjects 上的点击/触摸事件

c# - 统一: Instantiating prefab with animator

java - 如何在原生 android 中嵌入多个统一模块?

c# - .NET/WPF 中的通用 JSON 解析器?

c# - 自定义集合无法实现 IEnumerable<T>

c# - 将局部比例设置为实例化的游戏对象时,它会丢失 Material