@@ -901,35 +901,74 @@ public static bool AutomaticResolutionEnabled {
901
901
/// Initializes the <see cref="GooglePlayServices.PlayServicesResolver"/> class.
902
902
/// </summary>
903
903
static PlayServicesResolver ( ) {
904
- // Create the resolver.
905
- if ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . Android ) {
906
- gradleResolver = new GradleResolver ( ) ;
907
- // Monitor Android dependency XML files to perform auto-resolution.
908
- AddAutoResolutionFilePatterns ( xmlDependencies . fileRegularExpressions ) ;
904
+ // Cache the flag to prevent string comparison in every frame during
905
+ // PollOnUpdateUntilComplete()
906
+ bool isExecuteMethodEnabled = ExecutionEnvironment . ExecuteMethodEnabled ;
907
+
908
+ // Delay initialization until the build target is iOS and the editor is not in play
909
+ // mode.
910
+ RunOnMainThread . PollOnUpdateUntilComplete ( ( ) => {
911
+ if ( EditorUserBuildSettings . activeBuildTarget != BuildTarget . Android ||
912
+ EditorApplication . isPlayingOrWillChangePlaymode ) {
913
+ // If Unity is launched with -executeMethod, in some Unity versions, editor
914
+ // update will never be called. As a result, PollOnUpdateUntilComplete() will
915
+ // attempt to call this poll function repeating on current thread until it
916
+ // returns true. Therefore, return true immediately and stop the polling in
917
+ // executeMethod mode.
918
+ return isExecuteMethodEnabled ;
919
+ }
920
+ Initialize ( ) ;
921
+ return true ;
922
+ } ) ;
923
+
924
+ }
909
925
910
- svcSupport = PlayServicesSupport . CreateInstance (
911
- "PlayServicesResolver" ,
912
- AndroidSdkRoot ,
913
- "ProjectSettings" ,
914
- logMessageWithLevel : LogDelegate ) ;
926
+ /// <summary>
927
+ /// Whether Android Resolver have been initialized.
928
+ /// </summary>
929
+ private static bool isInitialized = false ;
930
+
931
+ /// <summary>
932
+ /// Initialize the module. This should be called on the main thread only if
933
+ /// current active build target is Android and not in play mode.
934
+ /// </summary>
935
+ private static void Initialize ( ) {
936
+ if ( isInitialized ) return ;
937
+
938
+ if ( EditorUserBuildSettings . activeBuildTarget != BuildTarget . Android ) {
939
+ throw new Exception ( "PlayServiceResolver.Initialize() is called when active " +
940
+ "build target is not Android. This should never happen. If it does, " +
941
+ "please report to the developer." ) ;
915
942
}
943
+
944
+ // Create the resolver.
945
+ gradleResolver = new GradleResolver ( ) ;
946
+ // Monitor Android dependency XML files to perform auto-resolution.
947
+ AddAutoResolutionFilePatterns ( xmlDependencies . fileRegularExpressions ) ;
948
+
949
+ svcSupport = PlayServicesSupport . CreateInstance (
950
+ "PlayServicesResolver" ,
951
+ AndroidSdkRoot ,
952
+ "ProjectSettings" ,
953
+ logMessageWithLevel : LogDelegate ) ;
954
+
916
955
RunOnMainThread . OnUpdate -= PollBundleId ;
917
956
RunOnMainThread . OnUpdate += PollBundleId ;
918
957
919
958
// Initialize settings and resolve if required.
920
959
OnSettingsChanged ( ) ;
921
960
922
961
// Setup events for auto resolution.
923
- if ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . Android ) {
924
- BundleIdChanged += ResolveOnBundleIdChanged ;
925
- AndroidBuildSystemChanged += ResolveOnBuildSystemChanged ;
926
- AndroidAbisChanged += ResolveOnAndroidAbisChanged ;
927
- AndroidSdkRootChanged += ResolveOnAndroidSdkRootChange ;
928
- Reresolve ( ) ;
962
+ BundleIdChanged += ResolveOnBundleIdChanged ;
963
+ AndroidBuildSystemChanged += ResolveOnBuildSystemChanged ;
964
+ AndroidAbisChanged += ResolveOnAndroidAbisChanged ;
965
+ AndroidSdkRootChanged += ResolveOnAndroidSdkRootChange ;
966
+ Reresolve ( ) ;
929
967
930
- if ( SettingsDialogObj . EnableAutoResolution ) LinkAutoResolution ( ) ;
931
- }
968
+ if ( SettingsDialogObj . EnableAutoResolution ) LinkAutoResolution ( ) ;
932
969
970
+ isInitialized = true ;
971
+ Log ( "Android Resolver Initialized" , level : LogLevel . Verbose ) ;
933
972
}
934
973
935
974
// Unregister events to monitor build system changes for the Android Resolver and other
0 commit comments