Skip to content

Commit

Permalink
feat: ability to target android/ios and run the sdk in the unity mac …
Browse files Browse the repository at this point in the history
…editor
  • Loading branch information
nattb8 committed Feb 14, 2024
1 parent b76cda2 commit 6f8bca2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion sample/Assets/Scripts/AuthenticatedScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public async void GetAddress()
public async void Logout()
{
ShowOutput("Logging out...");
#if UNITY_ANDROID || UNITY_IPHONE || (UNITY_STANDALONE_OSX && !UNITY_EDITOR_OSX)
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
await passport.LogoutPKCE();
#else
await passport.Logout();
Expand Down
13 changes: 3 additions & 10 deletions sample/Assets/Scripts/UnauthenticatedScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ async void Start()
string redirectUri = null;
string logoutRedirectUri = null;

// macOS editor (play scene) does not support deeplinking
#if UNITY_ANDROID || UNITY_IPHONE || (UNITY_STANDALONE_OSX && !UNITY_EDITOR_OSX)
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
redirectUri = "imxsample://callback";
logoutRedirectUri = "imxsample://callback/logout";
#endif
Expand Down Expand Up @@ -79,8 +78,7 @@ public async void Login()
ShowOutput("Called Login()...");
LoginButton.gameObject.SetActive(false);

// macOS editor (play scene) does not support deeplinking
#if UNITY_ANDROID || UNITY_IPHONE || (UNITY_STANDALONE_OSX && !UNITY_EDITOR_OSX)
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
await passport.LoginPKCE();
#else
await passport.Login();
Expand Down Expand Up @@ -109,9 +107,7 @@ public async void Login()

Debug.Log(error);
ShowOutput(error);
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX
LoginButton.gameObject.SetActive(true);
#endif
}
}

Expand Down Expand Up @@ -149,8 +145,7 @@ public async void Connect()
ShowOutput("Called Connect()...");
ConnectButton.gameObject.SetActive(false);

// macOS editor (play scene) does not support deeplinking
#if UNITY_ANDROID || UNITY_IPHONE || (UNITY_STANDALONE_OSX && !UNITY_EDITOR_OSX)
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
await passport.ConnectImxPKCE();
#else
await passport.ConnectImx();
Expand Down Expand Up @@ -179,9 +174,7 @@ public async void Connect()

Debug.Log(error);
ShowOutput(error);
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX
ConnectButton.gameObject.SetActive(true);
#endif
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private async UniTask LaunchAuthUrl()
if (response != null && response.success == true && response.result != null)
{
string url = response.result.Replace(" ", "+");
#if UNITY_ANDROID
#if UNITY_ANDROID && !UNITY_EDITOR
loginPKCEUrl = url;
SendAuthEvent(pkceLoginOnly ? PassportAuthEvent.LoginPKCELaunchingCustomTabs : PassportAuthEvent.ConnectImxPKCELaunchingCustomTabs);
LaunchAndroidUrl(url);
Expand Down Expand Up @@ -583,7 +583,7 @@ private async void LaunchLogoutPKCEUrl()
{
string logoutUrl = await GetLogoutUrl();

#if UNITY_ANDROID
#if UNITY_ANDROID && !UNITY_EDITOR
LaunchAndroidUrl(logoutUrl);
#else
communicationsManager.LaunchAuthURL(logoutUrl, logoutRedirectUri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class GreeBrowserClient : IWebBrowserClient

public GreeBrowserClient()
{
#if (UNITY_ANDROID && UNITY_EDITOR_OSX) || (UNITY_IPHONE && UNITY_EDITOR_OSX)
Debug.LogWarning("Native Android and iOS WebViews cannot run in the Editor, so the macOS WebView is currently used to save your development time." +
" Testing your game on an actual device or emulator is recommended to ensure proper functionality.");
#endif
webViewObject = new WebViewObject();
webViewObject.Init(
cb: InvokeOnUnityPostMessage,
Expand All @@ -25,7 +29,7 @@ public GreeBrowserClient()
auth: InvokeOnAuthPostMessage,
log: InvokeOnLogMessage
);
#if UNITY_ANDROID
#if UNITY_ANDROID && !UNITY_EDITOR
string filePath = Constants.SCHEME_FILE + ANDROID_DATA_DIRECTORY + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
#elif UNITY_EDITOR_OSX
string filePath = Constants.SCHEME_FILE + Path.GetFullPath(MAC_EDITOR_RESOURCES_DIRECTORY) + Constants.PASSPORT_HTML_FILE_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class WebViewObject
ErrorCallback onHttpError;
Callback onAuth;
Callback onLog;
#if UNITY_ANDROID
#if UNITY_ANDROID && !UNITY_EDITOR
class AndroidCallback : AndroidJavaProxy
{
private Action<string> callback;
Expand All @@ -94,7 +94,7 @@ public void call(String message) {
IntPtr webView;
#endif

#if UNITY_IPHONE
#if UNITY_IPHONE && !UNITY_EDITOR
[DllImport("__Internal")]
private static extern IntPtr _CWebViewPlugin_Init(string ua);
[DllImport("__Internal")]
Expand All @@ -113,7 +113,7 @@ private static extern void _CWebViewPlugin_EvaluateJS(
private static extern void _CWebViewPlugin_ClearCache(IntPtr instance, bool includeDiskFiles);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_ClearStorage(IntPtr instance);
#elif UNITY_STANDALONE_OSX
#elif UNITY_STANDALONE_OSX || (UNITY_ANDROID && UNITY_EDITOR_OSX) || (UNITY_IPHONE && UNITY_EDITOR_OSX)
[DllImport("WebView")]
private static extern IntPtr _CWebViewPlugin_Init(string ua);
[DllImport("WebView")]
Expand Down Expand Up @@ -228,7 +228,7 @@ public void Init(
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX
//TODO: UNSUPPORTED
Debug.LogError("Webview is not supported on this platform.");
#elif UNITY_IPHONE || UNITY_STANDALONE_OSX
#elif UNITY_IPHONE || UNITY_STANDALONE_OSX || (UNITY_ANDROID && UNITY_EDITOR_OSX)
webView = _CWebViewPlugin_Init(ua);
Singleton.Instance.onJS = ((message) => CallFromJS(message));
Singleton.Instance.onError = ((id, message) => CallOnError(id, message));
Expand Down Expand Up @@ -257,7 +257,7 @@ public void LoadURL(string url)
Application.ExternalCall("unityWebView.loadURL", url);
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX
//TODO: UNSUPPORTED
#elif UNITY_STANDALONE_OSX || UNITY_IPHONE
#elif UNITY_STANDALONE_OSX || UNITY_IPHONE || (UNITY_ANDROID && UNITY_EDITOR_OSX)
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_LoadURL(webView, url);
Expand All @@ -278,7 +278,7 @@ public void EvaluateJS(string js)
Application.ExternalCall("unityWebView.evaluateJS", js);
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX
//TODO: UNSUPPORTED
#elif UNITY_STANDALONE_OSX || UNITY_IPHONE
#elif UNITY_STANDALONE_OSX || UNITY_IPHONE || (UNITY_ANDROID && UNITY_EDITOR_OSX)
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_EvaluateJS(webView, js);
Expand All @@ -291,7 +291,7 @@ public void EvaluateJS(string js)

public void LaunchAuthURL(string url, string redirectUri)
{
#if UNITY_STANDALONE_OSX
#if UNITY_STANDALONE_OSX || (UNITY_ANDROID && UNITY_EDITOR_OSX) || (UNITY_IPHONE && UNITY_EDITOR_OSX)
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_LaunchAuthURL(webView, url, redirectUri != null ? redirectUri : "");
Expand Down Expand Up @@ -332,7 +332,7 @@ public void CallFromJS(string message)
{
if (onJS != null)
{
#if !UNITY_ANDROID
#if !(UNITY_ANDROID && !UNITY_EDITOR)
#if UNITY_2018_4_OR_NEWER
message = UnityWebRequest.UnEscapeURL(message.Replace("+", "%2B"));
#else // UNITY_2018_4_OR_NEWER
Expand Down

0 comments on commit 6f8bca2

Please sign in to comment.