13
13
using Immutable . Passport . Core ;
14
14
using Cysharp . Threading . Tasks ;
15
15
using UnityEngine ;
16
+ #if UNITY_EDITOR
17
+ using UnityEditor ;
18
+ #endif
16
19
17
20
namespace Immutable . Passport
18
21
{
@@ -52,6 +55,10 @@ private Passport()
52
55
OnDeepLinkActivated ( Application . absoluteURL ) ;
53
56
}
54
57
#endif
58
+
59
+ #if UNITY_EDITOR
60
+ EditorApplication . playModeStateChanged += OnPlayModeStateChanged ;
61
+ #endif
55
62
}
56
63
57
64
/// <summary>
@@ -65,18 +72,13 @@ private Passport()
65
72
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout duration in milliseconds to wait for the default Windows browser engine to start.</param>
66
73
/// <param name="webBrowserClient">(Windows only) Custom Windows browser to use instead of the default browser in the SDK.</param>
67
74
public static UniTask < Passport > Init (
68
- #if UNITY_STANDALONE_WIN || ( UNITY_ANDROID && UNITY_EDITOR_WIN ) || ( UNITY_IPHONE && UNITY_EDITOR_WIN )
69
- string clientId ,
70
- string environment ,
71
- string redirectUri = null ,
72
- string logoutRedirectUri = null ,
73
- int engineStartupTimeoutMs = 30000 ,
74
- IWindowsWebBrowserClient windowsWebBrowserClient = null
75
- #else
76
75
string clientId ,
77
76
string environment ,
78
77
string redirectUri = null ,
79
78
string logoutRedirectUri = null
79
+ #if UNITY_STANDALONE_WIN || ( UNITY_ANDROID && UNITY_EDITOR_WIN ) || ( UNITY_IPHONE && UNITY_EDITOR_WIN )
80
+ , int engineStartupTimeoutMs = 30000 ,
81
+ IWindowsWebBrowserClient windowsWebBrowserClient = null
80
82
#endif
81
83
)
82
84
{
@@ -178,19 +180,6 @@ private async UniTask Initialise(
178
180
}
179
181
}
180
182
181
-
182
- #if UNITY_STANDALONE_WIN || ( UNITY_ANDROID && UNITY_EDITOR_WIN ) || ( UNITY_IPHONE && UNITY_EDITOR_WIN )
183
- /// <summary>
184
- /// Handles clean-up when the application quits.
185
- /// </summary>
186
- private void OnQuit ( )
187
- {
188
- Debug . Log ( $ "{ TAG } Quitting the Player") ;
189
- webBrowserClient . Dispose ( ) ;
190
- Instance = null ;
191
- }
192
- #endif
193
-
194
183
/// <summary>
195
184
/// Sets the timeout time for waiting for each call to respond (in milliseconds).
196
185
/// This only applies to functions that use the browser communications manager.
@@ -502,5 +491,70 @@ private void OnPassportAuthEvent(PassportAuthEvent authEvent)
502
491
OnAuthEvent . Invoke ( authEvent ) ;
503
492
}
504
493
}
494
+
495
+ /// <summary>
496
+ /// Handles clean-up when the application quits
497
+ /// </summary>
498
+ private void OnQuit ( )
499
+ {
500
+ Debug . Log ( $ "{ TAG } Quitting the Player") ;
501
+
502
+ #if UNITY_EDITOR
503
+ EditorApplication . playModeStateChanged -= OnPlayModeStateChanged ;
504
+ #endif
505
+
506
+ DisposeAll ( ) ;
507
+ }
508
+
509
+ #if UNITY_EDITOR
510
+ /// <summary>
511
+ /// Handles play mode state changes in the editor
512
+ /// </summary>
513
+ /// <param name="state">The current play mode state</param>
514
+ private void OnPlayModeStateChanged ( PlayModeStateChange state )
515
+ {
516
+ // Dispose of all resources when exiting play mode
517
+ if ( state == PlayModeStateChange . ExitingPlayMode )
518
+ {
519
+ DisposeAll ( ) ;
520
+ }
521
+ }
522
+ #endif
523
+
524
+ /// <summary>
525
+ /// Disposes of all resources and unsubscribes from events
526
+ /// </summary>
527
+ private void DisposeAll ( )
528
+ {
529
+ // Dispose of the web browser client for Windows only
530
+ #if UNITY_STANDALONE_WIN || ( UNITY_ANDROID && UNITY_EDITOR_WIN ) || ( UNITY_IPHONE && UNITY_EDITOR_WIN )
531
+ if ( webBrowserClient != null )
532
+ {
533
+ webBrowserClient . Dispose ( ) ;
534
+ webBrowserClient = null ;
535
+ }
536
+ #endif
537
+
538
+ // Unsubscribe from Passport authentication events
539
+ // and dispose of the Passport implementation
540
+ if ( passportImpl != null )
541
+ {
542
+ passportImpl . OnAuthEvent -= OnPassportAuthEvent ;
543
+ passportImpl = null ;
544
+ }
545
+
546
+ // Unsubscribe from application quitting event
547
+ Application . quitting -= OnQuit ;
548
+
549
+ #if UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
550
+ // Unsubscribe from deep link activation events on iOS and macOS
551
+ Application . deepLinkActivated -= OnDeepLinkActivated ;
552
+ #endif
553
+
554
+ // Reset static fields
555
+ Instance = null ;
556
+ deeplink = null ;
557
+ readySignalReceived = false ;
558
+ }
505
559
}
506
560
}
0 commit comments