- Home /
Is there any way to show/hide the game window on demand?
Short story:
I'm making a game with a level editor, the game itself is made in Unity, the Editor is made in WPF.
When the Editor is opened, the game establishes a TCP connection with the editor, and displays a blank scene with some GUIText with information about the connection.
I would like to hide the game window entirely, when the editor is in use, but i need to keep the game running in background so when people click "Test Level" in the editor, the level is started inmediatly, without having to wait the game to initialize and stuff.
Is there any way to hide and show the Game Window on demand?
Could you have two cameras - one displaying Game Window and one displaying the other thing, both with full viewport rects, and enable/disable pause/unpause as needed?
The thing is... the editor has nothing to do with Unity, is a Standalone app...
You can probably force a $$anonymous$$imize of the Game Window via script but it sounds like you need to know how to do that from WPF code, not Unity. See this thread for some info on Unity code
http://answers.unity3d.com/questions/27490/$$anonymous$$imizing-and-maximizing-by-script.html
Answer by OliverJackman · Sep 26, 2019 at 11:53 PM
Sure !
using System;
using UnityEngine;
using System.Runtime.InteropServices;
public class HideUnityWindow : MonoBehaviour
{
[DllImport("user32.dll")]
private static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;
void Start()
{
var hwnd = GetActiveWindow();
ShowWindow(hwnd, SW_HIDE);
}
}
Would you be willing to explain the code a little bit? Or change the variable names to be a little more informative? I don't quite understand what I am seeing here.
Thank you
Is there a way to show the window after u hide it? @OliverJackman I tried the SW_RESTORE and the other SW Stuff, nothing worked D: