diff --git a/Assets/Cryville/Common/Unity/UrlOpener.cs b/Assets/Cryville/Common/Unity/UrlOpener.cs index 09a0c1c..f8bcdf1 100644 --- a/Assets/Cryville/Common/Unity/UrlOpener.cs +++ b/Assets/Cryville/Common/Unity/UrlOpener.cs @@ -1,8 +1,22 @@ +using System; +using System.Runtime.InteropServices; + namespace Cryville.Common.Unity { public static class UrlOpener { public static void Open(string url) { #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN - System.Diagnostics.Process.Start(url); + url += "\0"; + unsafe { + fixed (char* lpFile = url) { + var info = new SHELLEXECUTEINFOW { + cbSize = (uint)sizeof(SHELLEXECUTEINFOW), + fMask = 0x0540, + lpFile = lpFile, + nShow = 1, + }; + ShellExecuteExW(ref info); + } + } #elif UNITY_ANDROID using (var clazz = new UnityEngine.AndroidJavaClass("world.cryville.common.unity.UrlOpener")) { clazz.CallStatic("open", url); @@ -22,5 +36,27 @@ namespace Cryville.Common.Unity { #error Unknown platform. #endif } + +#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN + [DllImport("shell32.dll")] + static extern void ShellExecuteExW(ref SHELLEXECUTEINFOW pExecInfo); + unsafe struct SHELLEXECUTEINFOW { + public uint cbSize; + public uint fMask; + public IntPtr hwnd; + public char* lpVerb; + public char* lpFile; + public char* lpParameters; + public char* lpDirectory; + public int nShow; + public IntPtr hInstApp; + public IntPtr lpIDList; + public IntPtr lpClass; + public IntPtr hkeyClass; + public uint dwHotKey; + public IntPtr hIconMonitor; + public IntPtr hProcess; + } +#endif } }