Skip to content

Commit 3d7e9ae

Browse files
committed
feat: support vuplex
1 parent d394f38 commit 3d7e9ae

File tree

6 files changed

+82
-6
lines changed

6 files changed

+82
-6
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,8 @@ sample/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json
9797
sample/AltTester.log
9898

9999
# Crashes
100-
sample/mono_crash*
100+
sample/mono_crash*
101+
102+
# Vuplex
103+
src/Packages/Passport/Runtime/ThirdParty/Vuplex/Vuplex
104+
src/Packages/Passport/Runtime/ThirdParty/Vuplex/Vuplex.meta

src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public static class Constants
66
public const string SCHEME_FILE = "file:///";
77
public const string PASSPORT_DATA_DIRECTORY_NAME = "/ImmutableSDK/Runtime/Passport";
88
public const string PASSPORT_HTML_FILE_NAME = "/index.html";
9+
public const string PASSPORT_PACKAGE_RESOURCES_DIRECTORY = "Packages/com.immutable.passport/Runtime/Resources";
910
#pragma warning restore IDE0051
1011
}
1112
}

src/Packages/Passport/Runtime/ThirdParty/UnityWebBrowser/Runtime/Core/WebBrowserClient.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public class WebBrowserClient : IWebBrowserClient, IDisposable
6565

6666
private const string ENGINE_APP_NAME = "UnityWebBrowser.Engine.Cef";
6767
public static string ENGINE_FILE_LOCATION = "Packages/com.immutable.passport/Runtime/ThirdParty/UnityWebBrowser.Engine.Cef.Win-x64/Engine/";
68-
private const string PASSPORT_PACKAGE_RESOURCES_DIRECTORY = "Packages/com.immutable.passport/Runtime/Resources";
6968
private const string INITIAL_URL = "https://www.immutable.com/";
7069

7170
/// <summary>
@@ -319,11 +318,9 @@ public async UniTask Init(int engineStartupTimeout = 30000)
319318
//Initial URL
320319
string filePath = "";
321320
#if UNITY_EDITOR
322-
filePath = Constants.SCHEME_FILE + Path.GetFullPath($"{PASSPORT_PACKAGE_RESOURCES_DIRECTORY}{Constants.PASSPORT_HTML_FILE_NAME}");
323-
#else
324-
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
321+
filePath = Constants.SCHEME_FILE + Path.GetFullPath($"{Constants.PASSPORT_PACKAGE_RESOURCES_DIRECTORY}{Constants.PASSPORT_HTML_FILE_NAME}");
322+
#elif UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
325323
filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
326-
#endif
327324
#endif
328325
initialUrl = filePath;
329326
argsBuilder.AppendArgument("initial-url", initialUrl, true);

src/Packages/Passport/Runtime/ThirdParty/Vuplex.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
2+
3+
using UnityEngine;
4+
using Cysharp.Threading.Tasks;
5+
using Immutable.Browser.Core;
6+
using Vuplex.WebView;
7+
8+
namespace Immutable.Browser.Vuplex
9+
{
10+
public class VuplexWebView : IWebBrowserClient
11+
{
12+
public event OnUnityPostMessageDelegate OnAuthPostMessage;
13+
public event OnUnityPostMessageErrorDelegate OnPostMessageError;
14+
public event OnUnityPostMessageDelegate OnUnityPostMessage;
15+
16+
private IWebView webView;
17+
18+
public VuplexWebView()
19+
{
20+
webView = Web.CreateWebView();
21+
}
22+
23+
public async UniTask Init()
24+
{
25+
await webView.Init(600, 300);
26+
27+
// Get game bridge file path
28+
string filePath = "";
29+
#if UNITY_EDITOR
30+
filePath = Constants.SCHEME_FILE + Path.GetFullPath($"{Constants.PASSPORT_PACKAGE_RESOURCES_DIRECTORY}{Constants.PASSPORT_HTML_FILE_NAME}");
31+
#elif UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
32+
filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
33+
#endif
34+
// Load game bridge file
35+
webView.LoadUrl(filePath);
36+
37+
// Listen to messages from game bridge
38+
webView.MessageEmitted += (sender, eventArgs) => {
39+
OnUnityPostMessage?.Invoke(eventArgs.Value);
40+
};
41+
}
42+
43+
public void ExecuteJs(string js)
44+
{
45+
await webView.ExecuteJavaScript(js);
46+
}
47+
48+
public void LaunchAuthURL(string url, string? redirectUri)
49+
{
50+
Application.OpenURL(url);
51+
}
52+
}
53+
}
54+
55+
#endif

src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)