Skip to content

Commit a49ace5

Browse files
committed
feat: add prefab with ui elements baked in
1 parent a817e63 commit a49ace5

File tree

5 files changed

+592
-1
lines changed

5 files changed

+592
-1
lines changed

src/Packages/Passport/Runtime/Scripts/Public/PassportManager.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public class PassportManager : MonoBehaviour
7777
public bool IsInitialized { get; private set; }
7878
public bool IsLoggedIn { get; private set; }
7979

80+
// UI Builder integration
81+
private PassportUIBuilder uiBuilder;
82+
8083
private void Awake()
8184
{
8285
// Singleton pattern
@@ -94,6 +97,9 @@ private void Awake()
9497

9598
private void Start()
9699
{
100+
// Find UI Builder if present
101+
uiBuilder = GetComponent<PassportUIBuilder>();
102+
97103
// Configure UI elements if provided
98104
ConfigureUIElements();
99105

@@ -237,6 +243,12 @@ private async UniTask LoginAsync(DirectLoginMethod? loginMethod = null)
237243

238244
// Update UI state after successful login
239245
UpdateUIState();
246+
247+
// Switch to logged-in panel if UI builder is present
248+
if (uiBuilder != null)
249+
{
250+
uiBuilder.ShowLoggedInPanel();
251+
}
240252
}
241253
else
242254
{
@@ -278,6 +290,12 @@ public async void Logout()
278290

279291
// Update UI state after logout
280292
UpdateUIState();
293+
294+
// Switch back to login panel if UI builder is present
295+
if (uiBuilder != null)
296+
{
297+
uiBuilder.ShowLoginPanel();
298+
}
281299
}
282300
catch (Exception ex)
283301
{
@@ -294,35 +312,45 @@ public async void Logout()
294312
/// </summary>
295313
private void ConfigureUIElements()
296314
{
297-
// Set up button listeners
315+
// Set up button listeners (clear existing first to prevent duplicates)
298316
if (loginButton != null)
299317
{
318+
loginButton.onClick.RemoveAllListeners();
300319
loginButton.onClick.AddListener(() => Login());
301320
loginButton.interactable = IsInitialized && !IsLoggedIn;
321+
Debug.Log("[PassportManager] Configured login button");
302322
}
303323

304324
if (googleLoginButton != null)
305325
{
326+
googleLoginButton.onClick.RemoveAllListeners();
306327
googleLoginButton.onClick.AddListener(() => Login(DirectLoginMethod.Google));
307328
googleLoginButton.interactable = IsInitialized && !IsLoggedIn;
329+
Debug.Log("[PassportManager] Configured Google login button");
308330
}
309331

310332
if (appleLoginButton != null)
311333
{
334+
appleLoginButton.onClick.RemoveAllListeners();
312335
appleLoginButton.onClick.AddListener(() => Login(DirectLoginMethod.Apple));
313336
appleLoginButton.interactable = IsInitialized && !IsLoggedIn;
337+
Debug.Log("[PassportManager] Configured Apple login button");
314338
}
315339

316340
if (facebookLoginButton != null)
317341
{
342+
facebookLoginButton.onClick.RemoveAllListeners();
318343
facebookLoginButton.onClick.AddListener(() => Login(DirectLoginMethod.Facebook));
319344
facebookLoginButton.interactable = IsInitialized && !IsLoggedIn;
345+
Debug.Log("[PassportManager] Configured Facebook login button");
320346
}
321347

322348
if (logoutButton != null)
323349
{
350+
logoutButton.onClick.RemoveAllListeners();
324351
logoutButton.onClick.AddListener(() => Logout());
325352
logoutButton.interactable = IsInitialized && IsLoggedIn;
353+
Debug.Log("[PassportManager] Configured logout button");
326354
}
327355

328356
// Update initial UI state
@@ -440,5 +468,26 @@ private void SetUserInfoText(string message)
440468
}
441469

442470
#endregion
471+
472+
#region UI Builder Integration
473+
474+
/// <summary>
475+
/// Set UI references from the UI Builder (used internally)
476+
/// </summary>
477+
public void SetUIReferences(Button login, Button google, Button apple, Button facebook, Button logout, Text status, Text userInfo)
478+
{
479+
loginButton = login;
480+
googleLoginButton = google;
481+
appleLoginButton = apple;
482+
facebookLoginButton = facebook;
483+
logoutButton = logout;
484+
statusText = status;
485+
userInfoText = userInfo;
486+
487+
// Re-configure UI elements with new references
488+
ConfigureUIElements();
489+
}
490+
491+
#endregion
443492
}
444493
}

0 commit comments

Comments
 (0)