Skip to content

Commit 871a5b3

Browse files
authored
Merge pull request #170 from immutable/feat/android-ios-editor
[DX-2665] feat: ability to target android/ios and run the sdk in the unity mac editor
2 parents b76cda2 + 6f8bca2 commit 871a5b3

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

sample/Assets/Scripts/AuthenticatedScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public async void GetAddress()
180180
public async void Logout()
181181
{
182182
ShowOutput("Logging out...");
183-
#if UNITY_ANDROID || UNITY_IPHONE || (UNITY_STANDALONE_OSX && !UNITY_EDITOR_OSX)
183+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
184184
await passport.LogoutPKCE();
185185
#else
186186
await passport.Logout();

sample/Assets/Scripts/UnauthenticatedScript.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ async void Start()
3434
string redirectUri = null;
3535
string logoutRedirectUri = null;
3636

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

82-
// macOS editor (play scene) does not support deeplinking
83-
#if UNITY_ANDROID || UNITY_IPHONE || (UNITY_STANDALONE_OSX && !UNITY_EDITOR_OSX)
81+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
8482
await passport.LoginPKCE();
8583
#else
8684
await passport.Login();
@@ -109,9 +107,7 @@ public async void Login()
109107

110108
Debug.Log(error);
111109
ShowOutput(error);
112-
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX
113110
LoginButton.gameObject.SetActive(true);
114-
#endif
115111
}
116112
}
117113

@@ -149,8 +145,7 @@ public async void Connect()
149145
ShowOutput("Called Connect()...");
150146
ConnectButton.gameObject.SetActive(false);
151147

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

180175
Debug.Log(error);
181176
ShowOutput(error);
182-
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX
183177
ConnectButton.gameObject.SetActive(true);
184-
#endif
185178
}
186179
}
187180

src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ private async UniTask LaunchAuthUrl()
370370
if (response != null && response.success == true && response.result != null)
371371
{
372372
string url = response.result.Replace(" ", "+");
373-
#if UNITY_ANDROID
373+
#if UNITY_ANDROID && !UNITY_EDITOR
374374
loginPKCEUrl = url;
375375
SendAuthEvent(pkceLoginOnly ? PassportAuthEvent.LoginPKCELaunchingCustomTabs : PassportAuthEvent.ConnectImxPKCELaunchingCustomTabs);
376376
LaunchAndroidUrl(url);
@@ -583,7 +583,7 @@ private async void LaunchLogoutPKCEUrl()
583583
{
584584
string logoutUrl = await GetLogoutUrl();
585585

586-
#if UNITY_ANDROID
586+
#if UNITY_ANDROID && !UNITY_EDITOR
587587
LaunchAndroidUrl(logoutUrl);
588588
#else
589589
communicationsManager.LaunchAuthURL(logoutUrl, logoutRedirectUri);

src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/GreeBrowserClient.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public class GreeBrowserClient : IWebBrowserClient
1717

1818
public GreeBrowserClient()
1919
{
20+
#if (UNITY_ANDROID && UNITY_EDITOR_OSX) || (UNITY_IPHONE && UNITY_EDITOR_OSX)
21+
Debug.LogWarning("Native Android and iOS WebViews cannot run in the Editor, so the macOS WebView is currently used to save your development time." +
22+
" Testing your game on an actual device or emulator is recommended to ensure proper functionality.");
23+
#endif
2024
webViewObject = new WebViewObject();
2125
webViewObject.Init(
2226
cb: InvokeOnUnityPostMessage,
@@ -25,7 +29,7 @@ public GreeBrowserClient()
2529
auth: InvokeOnAuthPostMessage,
2630
log: InvokeOnLogMessage
2731
);
28-
#if UNITY_ANDROID
32+
#if UNITY_ANDROID && !UNITY_EDITOR
2933
string filePath = Constants.SCHEME_FILE + ANDROID_DATA_DIRECTORY + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
3034
#elif UNITY_EDITOR_OSX
3135
string filePath = Constants.SCHEME_FILE + Path.GetFullPath(MAC_EDITOR_RESOURCES_DIRECTORY) + Constants.PASSPORT_HTML_FILE_NAME;

src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebViewObject.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class WebViewObject
7474
ErrorCallback onHttpError;
7575
Callback onAuth;
7676
Callback onLog;
77-
#if UNITY_ANDROID
77+
#if UNITY_ANDROID && !UNITY_EDITOR
7878
class AndroidCallback : AndroidJavaProxy
7979
{
8080
private Action<string> callback;
@@ -94,7 +94,7 @@ public void call(String message) {
9494
IntPtr webView;
9595
#endif
9696

97-
#if UNITY_IPHONE
97+
#if UNITY_IPHONE && !UNITY_EDITOR
9898
[DllImport("__Internal")]
9999
private static extern IntPtr _CWebViewPlugin_Init(string ua);
100100
[DllImport("__Internal")]
@@ -113,7 +113,7 @@ private static extern void _CWebViewPlugin_EvaluateJS(
113113
private static extern void _CWebViewPlugin_ClearCache(IntPtr instance, bool includeDiskFiles);
114114
[DllImport("__Internal")]
115115
private static extern void _CWebViewPlugin_ClearStorage(IntPtr instance);
116-
#elif UNITY_STANDALONE_OSX
116+
#elif UNITY_STANDALONE_OSX || (UNITY_ANDROID && UNITY_EDITOR_OSX) || (UNITY_IPHONE && UNITY_EDITOR_OSX)
117117
[DllImport("WebView")]
118118
private static extern IntPtr _CWebViewPlugin_Init(string ua);
119119
[DllImport("WebView")]
@@ -228,7 +228,7 @@ public void Init(
228228
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX
229229
//TODO: UNSUPPORTED
230230
Debug.LogError("Webview is not supported on this platform.");
231-
#elif UNITY_IPHONE || UNITY_STANDALONE_OSX
231+
#elif UNITY_IPHONE || UNITY_STANDALONE_OSX || (UNITY_ANDROID && UNITY_EDITOR_OSX)
232232
webView = _CWebViewPlugin_Init(ua);
233233
Singleton.Instance.onJS = ((message) => CallFromJS(message));
234234
Singleton.Instance.onError = ((id, message) => CallOnError(id, message));
@@ -257,7 +257,7 @@ public void LoadURL(string url)
257257
Application.ExternalCall("unityWebView.loadURL", url);
258258
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX
259259
//TODO: UNSUPPORTED
260-
#elif UNITY_STANDALONE_OSX || UNITY_IPHONE
260+
#elif UNITY_STANDALONE_OSX || UNITY_IPHONE || (UNITY_ANDROID && UNITY_EDITOR_OSX)
261261
if (webView == IntPtr.Zero)
262262
return;
263263
_CWebViewPlugin_LoadURL(webView, url);
@@ -278,7 +278,7 @@ public void EvaluateJS(string js)
278278
Application.ExternalCall("unityWebView.evaluateJS", js);
279279
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX
280280
//TODO: UNSUPPORTED
281-
#elif UNITY_STANDALONE_OSX || UNITY_IPHONE
281+
#elif UNITY_STANDALONE_OSX || UNITY_IPHONE || (UNITY_ANDROID && UNITY_EDITOR_OSX)
282282
if (webView == IntPtr.Zero)
283283
return;
284284
_CWebViewPlugin_EvaluateJS(webView, js);
@@ -291,7 +291,7 @@ public void EvaluateJS(string js)
291291

292292
public void LaunchAuthURL(string url, string redirectUri)
293293
{
294-
#if UNITY_STANDALONE_OSX
294+
#if UNITY_STANDALONE_OSX || (UNITY_ANDROID && UNITY_EDITOR_OSX) || (UNITY_IPHONE && UNITY_EDITOR_OSX)
295295
if (webView == IntPtr.Zero)
296296
return;
297297
_CWebViewPlugin_LaunchAuthURL(webView, url, redirectUri != null ? redirectUri : "");
@@ -332,7 +332,7 @@ public void CallFromJS(string message)
332332
{
333333
if (onJS != null)
334334
{
335-
#if !UNITY_ANDROID
335+
#if !(UNITY_ANDROID && !UNITY_EDITOR)
336336
#if UNITY_2018_4_OR_NEWER
337337
message = UnityWebRequest.UnEscapeURL(message.Replace("+", "%2B"));
338338
#else // UNITY_2018_4_OR_NEWER

0 commit comments

Comments
 (0)