Created
July 21, 2020 08:45
-
-
Save tarukosu/fb25791968ddd9c0164332655c2e3db3 to your computer and use it in GitHub Desktop.
Launch browser from HoloLens Unity app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
#if WINDOWS_UWP | |
using System; | |
using Windows.System; | |
#endif | |
public static class BrowserLauncher | |
{ | |
public static void Launch(string url, bool useHoloBrowser = false) | |
{ | |
#if WINDOWS_UWP | |
UnityEngine.WSA.Application.InvokeOnUIThread(async () => | |
{ | |
try | |
{ | |
var uri = new Uri(url); | |
if (useHoloBrowser) | |
{ | |
var holoBrowserUri = new Uri($"holo-browser:{url}"); | |
var option = new LauncherOptions() | |
{ | |
FallbackUri = uri | |
}; | |
await Launcher.LaunchUriAsync(holoBrowserUri, option); | |
} | |
else | |
{ | |
await Launcher.LaunchUriAsync(uri); | |
} | |
} | |
catch (Exception e) | |
{ | |
Debug.LogWarning(e); | |
} | |
}, false); | |
#else | |
Application.OpenURL(url); | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment