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 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); } #else #error Unknown platform. #endif } public static void OpenThreaded(string url) { #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN Open(url); #elif UNITY_ANDROID UnityEngine.AndroidJNI.AttachCurrentThread(); Open(url); UnityEngine.AndroidJNI.DetachCurrentThread(); #else #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 } }