Hi,
I make two Unity applications who called each others, let’s name them “app A” and “app B”.
I coded a script using C# library, as seen as this page. It will switch between apps when clicking on an object.
Here is the code :
public class launchExternalApp : MonoBehaviour {
/*
* C# imports from user32.dll
*/
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hwnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SetActiveWindow(IntPtr hwnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, uint flag);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr FindWindow(string className, string windowTitle);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
/**/
private enum ShowWindowEnum
{
Hide = 0,
ShowNormal = 1, ShowMinimized = 2, ShowMaximized = 3,
Maximize = 3, ShowNormalNoActivate = 4, Show = 5,
Minimize = 6, ShowMinNoActivate = 7, ShowNoActivate = 8,
Restore = 9, ShowDefault = 10, ForceMinimized = 11
};
public string windowName = "app_A";
public string processPathExe ="D:/Unity/Utils/Build/app_a/app_A.exe";
void OnMouseUpAsButton()
{
IntPtr wdwIntPtr = (IntPtr) (-1) ;
wdwIntPtr = FindWindow(null, windowName);
if (wdwIntPtr == (IntPtr)0)
{
Process.Start(processPathExe);
}
else
{
ShowWindow(wdwIntPtr, (uint)ShowWindowEnum.Show); // Make the window visible if it was hidden
ShowWindow(wdwIntPtr, (uint)ShowWindowEnum.Restore); // Next, restore it if it was minimized
SetForegroundWindow(wdwIntPtr); // Finally, activate the window
}
}
}
This script works differently according to application window state :
- If both applications are windowed, this works fine.
- if one application is windowed and the other one is fullscreen, it works fine.
- if both are in fullscreen, clicking on the object will flash the other app, then back to my desktop.
There’s a conflict bewteen two fullscreen applications, how can i manage that ?
Thanks,