Skip to content

Commit 8c13d0f

Browse files
committed
refactor: decouple UI components from core SDK
- Move PassportManager.cs and PassportUIBuilder.cs to Samples folder - Remove Unity.Modules.UI and Unity.TextMeshPro dependencies from core SDK - Create separate assembly definition for samples with UI dependencies - Core SDK is now UI-agnostic while preserving drag-and-drop prefab experience - Developers can use provided UI samples or build their own UI
1 parent 5e5b616 commit 8c13d0f

File tree

7 files changed

+192
-27
lines changed

7 files changed

+192
-27
lines changed

src/Packages/Passport/Runtime/Scripts/Public/Immutable.Passport.Runtime.asmdef

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
"Unity.Modules.UnityWebRequest",
1212
"Unity.Modules.AndroidJNI",
1313
"Unity.Modules.JSONSerialize",
14-
"Unity.Modules.Core",
15-
"Unity.Modules.UI",
16-
"Unity.TextMeshPro"
14+
"Unity.Modules.Core"
1715
],
1816
"includePlatforms": [
1917
"Android",

src/Packages/Passport/Runtime/Scripts/Public/PassportUIBuilder.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "Immutable.Passport.Samples",
3+
"rootNamespace": "Immutable.Passport",
4+
"references": [
5+
"Immutable.Passport.Runtime.Public",
6+
"Immutable.Passport.Runtime.Private",
7+
"Immutable.Passport.Core.Logging",
8+
"Immutable.Browser.Core",
9+
"UniTask",
10+
"Unity.Modules.UI",
11+
"Unity.TextMeshPro"
12+
],
13+
"includePlatforms": [
14+
"Android",
15+
"Editor",
16+
"iOS",
17+
"macOSStandalone",
18+
"WebGL",
19+
"WindowsStandalone64"
20+
],
21+
"excludePlatforms": [],
22+
"allowUnsafeCode": false,
23+
"overrideReferences": false,
24+
"precompiledReferences": [],
25+
"autoReferenced": false,
26+
"defineConstraints": [],
27+
"versionDefines": [],
28+
"noEngineReferences": false
29+
}

src/Packages/Passport/Samples~/PassportManagerPrefab/PassportManagerComplete.prefab

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ GameObject:
1010
m_Component:
1111
- component: {fileID: 2471608869895950181}
1212
- component: {fileID: 2471608869895950182}
13-
- component: {fileID: 2471608869895950183}
13+
- component: {fileID: 8072342326407231330}
1414
m_Layer: 0
1515
m_Name: PassportManagerComplete
1616
m_TagString: Untagged
@@ -52,6 +52,7 @@ MonoBehaviour:
5252
autoInitialize: 1
5353
autoLogin: 0
5454
directLoginMethod: 0
55+
defaultMarketingConsent: 1
5556
logLevel: 3
5657
redactTokensInLogs: 1
5758
loginButton: {fileID: 0}
@@ -81,7 +82,7 @@ MonoBehaviour:
8182
OnLogoutFailed:
8283
m_PersistentCalls:
8384
m_Calls: []
84-
--- !u!114 &2471608869895950183
85+
--- !u!114 &8072342326407231330
8586
MonoBehaviour:
8687
m_ObjectHideFlags: 0
8788
m_CorrespondingSourceObject: {fileID: 0}
@@ -90,14 +91,15 @@ MonoBehaviour:
9091
m_GameObject: {fileID: 2471608869895950180}
9192
m_Enabled: 1
9293
m_EditorHideFlags: 0
93-
m_Script: {fileID: 11500000, guid: abcdef1234567890abcdef1234567890, type: 3}
94+
m_Script: {fileID: 11500000, guid: ef72a80840b41d54aa0117a1694f72b6, type: 3}
9495
m_Name:
9596
m_EditorClassIdentifier:
96-
passportManager: {fileID: 2471608869895950182}
97+
passportManager: {fileID: 0}
9798
canvasOrder: 100
9899
panelSize: {x: 300, y: 400}
99100
buttonSize: {x: 280, y: 45}
100101
elementSpacing: 10
102+
forceCursorAlwaysAvailable: 1
101103
uiCanvas: {fileID: 0}
102104
loginPanel: {fileID: 0}
103105
loggedInPanel: {fileID: 0}

src/Packages/Passport/Runtime/Scripts/Public/PassportUIBuilder.cs renamed to src/Packages/Passport/Samples~/PassportManagerPrefab/PassportUIBuilder.cs

Lines changed: 156 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using UnityEngine.UI;
33
using UnityEngine.EventSystems;
44
using TMPro;
5+
using Immutable.Passport.Model;
56

67
namespace Immutable.Passport
78
{
@@ -346,20 +347,166 @@ private void WireUpPassportManager()
346347
if (passportManager == null) return;
347348

348349
// Set UI references using the public method
349-
passportManager.SetUIReferences(
350-
loginButton,
351-
googleLoginButton,
352-
appleLoginButton,
353-
facebookLoginButton,
354-
logoutButton,
355-
statusText,
356-
userInfoText
357-
);
350+
// Wire up generated UI elements to PassportManager directly
351+
ConfigureUIButtons();
358352

359353
Debug.Log("[PassportUIBuilder] UI wired to PassportManager successfully!");
360354
Debug.Log($"[PassportUIBuilder] Button click listeners: Google={googleLoginButton.onClick.GetPersistentEventCount()}");
361355
}
362356

357+
/// <summary>
358+
/// Configure UI button listeners to call PassportManager methods
359+
/// </summary>
360+
private void ConfigureUIButtons()
361+
{
362+
if (passportManager == null) return;
363+
364+
// Clear existing listeners to prevent duplicates
365+
if (loginButton != null)
366+
{
367+
loginButton.onClick.RemoveAllListeners();
368+
loginButton.onClick.AddListener(() => passportManager.Login());
369+
Debug.Log("[PassportUIBuilder] Configured login button");
370+
}
371+
372+
if (googleLoginButton != null)
373+
{
374+
googleLoginButton.onClick.RemoveAllListeners();
375+
googleLoginButton.onClick.AddListener(() => passportManager.Login(new DirectLoginOptions(DirectLoginMethod.Google)));
376+
Debug.Log("[PassportUIBuilder] Configured Google login button");
377+
}
378+
379+
if (appleLoginButton != null)
380+
{
381+
appleLoginButton.onClick.RemoveAllListeners();
382+
appleLoginButton.onClick.AddListener(() => passportManager.Login(new DirectLoginOptions(DirectLoginMethod.Apple)));
383+
Debug.Log("[PassportUIBuilder] Configured Apple login button");
384+
}
385+
386+
if (facebookLoginButton != null)
387+
{
388+
facebookLoginButton.onClick.RemoveAllListeners();
389+
facebookLoginButton.onClick.AddListener(() => passportManager.Login(new DirectLoginOptions(DirectLoginMethod.Facebook)));
390+
Debug.Log("[PassportUIBuilder] Configured Facebook login button");
391+
}
392+
393+
if (logoutButton != null)
394+
{
395+
logoutButton.onClick.RemoveAllListeners();
396+
logoutButton.onClick.AddListener(() => passportManager.Logout());
397+
Debug.Log("[PassportUIBuilder] Configured logout button");
398+
}
399+
400+
// Subscribe to PassportManager events for UI state management
401+
if (passportManager.OnPassportInitialized != null)
402+
passportManager.OnPassportInitialized.AddListener(UpdateUIState);
403+
if (passportManager.OnLoginSucceeded != null)
404+
passportManager.OnLoginSucceeded.AddListener(OnLoginSuccess);
405+
if (passportManager.OnLogoutSucceeded != null)
406+
passportManager.OnLogoutSucceeded.AddListener(OnLogoutSuccess);
407+
408+
// Initial UI state update
409+
UpdateUIState();
410+
}
411+
412+
/// <summary>
413+
/// Handle successful login
414+
/// </summary>
415+
private void OnLoginSuccess()
416+
{
417+
ShowLoggedInPanel();
418+
UpdateUIState();
419+
}
420+
421+
/// <summary>
422+
/// Handle successful logout
423+
/// </summary>
424+
private void OnLogoutSuccess()
425+
{
426+
ShowLoginPanel();
427+
UpdateUIState();
428+
}
429+
430+
/// <summary>
431+
/// Update UI state based on PassportManager status
432+
/// </summary>
433+
private void UpdateUIState()
434+
{
435+
if (passportManager == null) return;
436+
437+
bool isInitialized = passportManager.IsInitialized;
438+
bool isLoggedIn = passportManager.IsLoggedIn;
439+
440+
// Update button states
441+
if (loginButton != null)
442+
loginButton.interactable = isInitialized && !isLoggedIn;
443+
if (googleLoginButton != null)
444+
googleLoginButton.interactable = isInitialized && !isLoggedIn;
445+
if (appleLoginButton != null)
446+
appleLoginButton.interactable = isInitialized && !isLoggedIn;
447+
if (facebookLoginButton != null)
448+
facebookLoginButton.interactable = isInitialized && !isLoggedIn;
449+
if (logoutButton != null)
450+
logoutButton.interactable = isInitialized && isLoggedIn;
451+
452+
// Update status text
453+
string statusMessage;
454+
Color statusColor;
455+
456+
if (!isInitialized)
457+
{
458+
statusMessage = "Initializing Passport...";
459+
statusColor = Color.yellow;
460+
}
461+
else if (isLoggedIn)
462+
{
463+
statusMessage = "✅ Logged In Successfully";
464+
statusColor = Color.green;
465+
}
466+
else
467+
{
468+
statusMessage = "Ready to login";
469+
statusColor = Color.white;
470+
}
471+
472+
if (statusText != null)
473+
{
474+
statusText.text = statusMessage;
475+
statusText.color = statusColor;
476+
}
477+
478+
// Update user info
479+
if (isLoggedIn)
480+
{
481+
UpdateUserInfoDisplay();
482+
}
483+
else if (userInfoText != null)
484+
{
485+
userInfoText.text = "";
486+
}
487+
}
488+
489+
/// <summary>
490+
/// Update user info display with token preview
491+
/// </summary>
492+
private async void UpdateUserInfoDisplay()
493+
{
494+
if (userInfoText != null && passportManager != null && passportManager.PassportInstance != null)
495+
{
496+
try
497+
{
498+
string accessToken = await passportManager.PassportInstance.GetAccessToken();
499+
string tokenPreview = accessToken.Length > 20 ? accessToken.Substring(0, 20) + "..." : accessToken;
500+
userInfoText.text = $"Token: {tokenPreview}";
501+
}
502+
catch (System.Exception ex)
503+
{
504+
userInfoText.text = $"Error: {ex.Message}";
505+
Debug.LogWarning($"[PassportUIBuilder] Failed to load user info: {ex.Message}");
506+
}
507+
}
508+
}
509+
363510
/// <summary>
364511
/// Show the login panel and hide the logged-in panel
365512
/// </summary>

0 commit comments

Comments
 (0)