From 3d7e9ae66c470c584f7757141e5ac331b99194d8 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Mon, 29 Jul 2024 14:39:38 +1200 Subject: [PATCH 1/7] feat: support vuplex --- .gitignore | 6 +- .../ImmutableBrowserCore/Constants.cs | 1 + .../Runtime/Core/WebBrowserClient.cs | 7 +-- .../Passport/Runtime/ThirdParty/Vuplex.meta | 8 +++ .../ThirdParty/Vuplex/VuplexWebView.cs | 55 +++++++++++++++++++ .../ThirdParty/Vuplex/VuplexWebView.cs.meta | 11 ++++ 6 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 src/Packages/Passport/Runtime/ThirdParty/Vuplex.meta create mode 100644 src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs create mode 100644 src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs.meta diff --git a/.gitignore b/.gitignore index 94a1dd85..bc5b1510 100644 --- a/.gitignore +++ b/.gitignore @@ -97,4 +97,8 @@ sample/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json sample/AltTester.log # Crashes -sample/mono_crash* \ No newline at end of file +sample/mono_crash* + +# Vuplex +src/Packages/Passport/Runtime/ThirdParty/Vuplex/Vuplex +src/Packages/Passport/Runtime/ThirdParty/Vuplex/Vuplex.meta \ No newline at end of file diff --git a/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/Constants.cs b/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/Constants.cs index e2a20e24..9bc6ab1a 100644 --- a/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/Constants.cs +++ b/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/Constants.cs @@ -6,6 +6,7 @@ public static class Constants public const string SCHEME_FILE = "file:///"; public const string PASSPORT_DATA_DIRECTORY_NAME = "/ImmutableSDK/Runtime/Passport"; public const string PASSPORT_HTML_FILE_NAME = "/index.html"; + public const string PASSPORT_PACKAGE_RESOURCES_DIRECTORY = "Packages/com.immutable.passport/Runtime/Resources"; #pragma warning restore IDE0051 } } \ No newline at end of file diff --git a/src/Packages/Passport/Runtime/ThirdParty/UnityWebBrowser/Runtime/Core/WebBrowserClient.cs b/src/Packages/Passport/Runtime/ThirdParty/UnityWebBrowser/Runtime/Core/WebBrowserClient.cs index 8a03f078..8d27d713 100644 --- a/src/Packages/Passport/Runtime/ThirdParty/UnityWebBrowser/Runtime/Core/WebBrowserClient.cs +++ b/src/Packages/Passport/Runtime/ThirdParty/UnityWebBrowser/Runtime/Core/WebBrowserClient.cs @@ -65,7 +65,6 @@ public class WebBrowserClient : IWebBrowserClient, IDisposable private const string ENGINE_APP_NAME = "UnityWebBrowser.Engine.Cef"; public static string ENGINE_FILE_LOCATION = "Packages/com.immutable.passport/Runtime/ThirdParty/UnityWebBrowser.Engine.Cef.Win-x64/Engine/"; - private const string PASSPORT_PACKAGE_RESOURCES_DIRECTORY = "Packages/com.immutable.passport/Runtime/Resources"; private const string INITIAL_URL = "https://www.immutable.com/"; /// @@ -319,11 +318,9 @@ public async UniTask Init(int engineStartupTimeout = 30000) //Initial URL string filePath = ""; #if UNITY_EDITOR - filePath = Constants.SCHEME_FILE + Path.GetFullPath($"{PASSPORT_PACKAGE_RESOURCES_DIRECTORY}{Constants.PASSPORT_HTML_FILE_NAME}"); -#else -#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN) + filePath = Constants.SCHEME_FILE + Path.GetFullPath($"{Constants.PASSPORT_PACKAGE_RESOURCES_DIRECTORY}{Constants.PASSPORT_HTML_FILE_NAME}"); +#elif UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN) filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME; -#endif #endif initialUrl = filePath; argsBuilder.AppendArgument("initial-url", initialUrl, true); diff --git a/src/Packages/Passport/Runtime/ThirdParty/Vuplex.meta b/src/Packages/Passport/Runtime/ThirdParty/Vuplex.meta new file mode 100644 index 00000000..44ffebab --- /dev/null +++ b/src/Packages/Passport/Runtime/ThirdParty/Vuplex.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ef595a71880834a50a4aea19f85c4139 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs b/src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs new file mode 100644 index 00000000..05c59b17 --- /dev/null +++ b/src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs @@ -0,0 +1,55 @@ +#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN) + +using UnityEngine; +using Cysharp.Threading.Tasks; +using Immutable.Browser.Core; +using Vuplex.WebView; + +namespace Immutable.Browser.Vuplex +{ + public class VuplexWebView : IWebBrowserClient + { + public event OnUnityPostMessageDelegate OnAuthPostMessage; + public event OnUnityPostMessageErrorDelegate OnPostMessageError; + public event OnUnityPostMessageDelegate OnUnityPostMessage; + + private IWebView webView; + + public VuplexWebView() + { + webView = Web.CreateWebView(); + } + + public async UniTask Init() + { + await webView.Init(600, 300); + + // Get game bridge file path + string filePath = ""; +#if UNITY_EDITOR + filePath = Constants.SCHEME_FILE + Path.GetFullPath($"{Constants.PASSPORT_PACKAGE_RESOURCES_DIRECTORY}{Constants.PASSPORT_HTML_FILE_NAME}"); +#elif UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN) + filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME; +#endif + // Load game bridge file + webView.LoadUrl(filePath); + + // Listen to messages from game bridge + webView.MessageEmitted += (sender, eventArgs) => { + OnUnityPostMessage?.Invoke(eventArgs.Value); + }; + } + + public void ExecuteJs(string js) + { + await webView.ExecuteJavaScript(js); + } + + public void LaunchAuthURL(string url, string? redirectUri) + { + Application.OpenURL(url); + } + } +} + +#endif \ No newline at end of file diff --git a/src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs.meta b/src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs.meta new file mode 100644 index 00000000..1eb1db2e --- /dev/null +++ b/src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: da6f82a50caeb4bb2aee23a92d46cd7c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 2f1647f5a245f3909d4c037bdf73718d00b0521e Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Tue, 30 Jul 2024 17:20:40 +1200 Subject: [PATCH 2/7] feat: windows webview --- .gitignore | 3 +- .../Assets/Scripts/SelectAuthMethodScript.cs | 1 + sample/ProjectSettings/ProjectSettings.asset | 9 +- .../Passport/Runtime/Resources/index.html | 38 ++++---- .../Core/BrowserCommunicationsManager.cs | 4 + .../Runtime/Scripts/Private/PassportImpl.cs | 3 + .../Runtime/Scripts/Public/Passport.cs | 92 ++++++++++++++----- .../Gree/Assets/Plugins/GreeBrowserClient.cs | 6 +- .../ImmutableBrowserCore/IWebBrowserClient.cs | 13 ++- .../Immutable.Browser.Core.asmdef | 4 +- .../WindowsWebBrowserClient.cs | 39 ++++++++ .../WindowsWebBrowserClient.cs.meta} | 2 +- .../Runtime/Core/WebBrowserClient.cs | 2 - .../Passport/Runtime/ThirdParty/Vuplex.meta | 8 -- .../ThirdParty/Vuplex/VuplexWebView.cs | 55 ----------- .../Core/BrowserCommunicationsManagerTests.cs | 4 + 16 files changed, 166 insertions(+), 117 deletions(-) create mode 100644 src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/WindowsWebBrowserClient.cs rename src/Packages/Passport/Runtime/ThirdParty/{Vuplex/VuplexWebView.cs.meta => ImmutableBrowserCore/WindowsWebBrowserClient.cs.meta} (83%) delete mode 100644 src/Packages/Passport/Runtime/ThirdParty/Vuplex.meta delete mode 100644 src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs diff --git a/.gitignore b/.gitignore index bc5b1510..62c972de 100644 --- a/.gitignore +++ b/.gitignore @@ -100,5 +100,4 @@ sample/AltTester.log sample/mono_crash* # Vuplex -src/Packages/Passport/Runtime/ThirdParty/Vuplex/Vuplex -src/Packages/Passport/Runtime/ThirdParty/Vuplex/Vuplex.meta \ No newline at end of file +sample/Assets/Vuplex* \ No newline at end of file diff --git a/sample/Assets/Scripts/SelectAuthMethodScript.cs b/sample/Assets/Scripts/SelectAuthMethodScript.cs index 3e0bb829..1d0c13d7 100644 --- a/sample/Assets/Scripts/SelectAuthMethodScript.cs +++ b/sample/Assets/Scripts/SelectAuthMethodScript.cs @@ -79,6 +79,7 @@ private async void InitialisePassport(string redirectUri = null, string logoutRe } catch (Exception ex) { + Debug.Log(ex); ShowOutput($"Initialise Passport error: {ex.Message}"); } } diff --git a/sample/ProjectSettings/ProjectSettings.asset b/sample/ProjectSettings/ProjectSettings.asset index a11f3171..92da38a3 100644 --- a/sample/ProjectSettings/ProjectSettings.asset +++ b/sample/ProjectSettings/ProjectSettings.asset @@ -499,6 +499,9 @@ PlayerSettings: - m_BuildTarget: iOSSupport m_APIs: 10000000 m_Automatic: 1 + - m_BuildTarget: WindowsStandaloneSupport + m_APIs: 02000000 + m_Automatic: 1 m_BuildTargetVRSettings: [] m_DefaultShaderChunkSizeInMB: 16 m_DefaultShaderChunkCount: 0 @@ -766,14 +769,14 @@ PlayerSettings: webGLDecompressionFallback: 0 webGLPowerPreference: 2 scriptingDefineSymbols: - Standalone: + Standalone: VUPLEX_STANDALONE additionalCompilerArguments: Standalone: - -nullable+ platformArchitecture: {} scriptingBackend: Android: 1 - Standalone: 1 + Standalone: 0 il2cppCompilerConfiguration: {} managedStrippingLevel: EmbeddedLinux: 1 @@ -794,7 +797,7 @@ PlayerSettings: allowUnsafeCode: 0 useDeterministicCompilation: 1 enableRoslynAnalyzers: 1 - selectedPlatform: 2 + selectedPlatform: 0 additionalIl2CppArgs: scriptingRuntimeVersion: 1 gcIncremental: 1 diff --git a/src/Packages/Passport/Runtime/Resources/index.html b/src/Packages/Passport/Runtime/Resources/index.html index 4c990e28..a6a8a371 100644 --- a/src/Packages/Passport/Runtime/Resources/index.html +++ b/src/Packages/Passport/Runtime/Resources/index.html @@ -1,4 +1,4 @@ -GameSDK Bridge