@@ -651,54 +651,90 @@ private static Assembly ResolveUnityEditoriOSXcodeExtension(
651
651
static IOSResolver ( ) {
652
652
// Load log preferences.
653
653
VerboseLoggingEnabled = VerboseLoggingEnabled ;
654
+
654
655
// NOTE: We can't reference the UnityEditor.iOS.Xcode module in this
655
656
// method as the Mono runtime in Unity 4 and below requires all
656
657
// dependencies of a method are loaded before the method is executed
657
658
// so we install the DLL loader first then try using the Xcode module.
658
659
RemapXcodeExtension ( ) ;
660
+
661
+ // Cache the flag to prevent string comparison in every frame during
662
+ // PollOnUpdateUntilComplete()
663
+ bool isExecuteMethodEnabled = ExecutionEnvironment . ExecuteMethodEnabled ;
664
+
665
+ // Delay initialization until the build target is iOS and the editor is not in play mode.
666
+ RunOnMainThread . PollOnUpdateUntilComplete ( ( ) => {
667
+ if ( EditorUserBuildSettings . activeBuildTarget != BuildTarget . iOS ||
668
+ EditorApplication . isPlayingOrWillChangePlaymode ) {
669
+ // If Unity is launched with -executeMethod, in some Unity versions, editor
670
+ // update will never be called. As a result, PollOnUpdateUntilComplete() will
671
+ // attempt to call this poll function repeating on current thread until it returns
672
+ // true. Therefore, return true immediately and stop the polling in executeMethod
673
+ // mode.
674
+ return isExecuteMethodEnabled ;
675
+ }
676
+ Initialize ( ) ;
677
+ return true ;
678
+ } ) ;
679
+ }
680
+
681
+ /// <summary>
682
+ /// Whether iOSResolver have been initialized.
683
+ /// </summary>
684
+ private static bool isInitialized = false ;
685
+
686
+ /// <summary>
687
+ /// Initialize the module. This should be called on the main thread only if
688
+ /// current active build target is iOS and not in play mode.
689
+ /// </summary>
690
+ private static void Initialize ( ) {
691
+ if ( isInitialized ) return ;
692
+
693
+ if ( EditorUserBuildSettings . activeBuildTarget != BuildTarget . iOS ) {
694
+ throw new Exception ( "IOSResolver.Initialize() is called when active build target " +
695
+ "is not iOS. This should never happen. If it does, please report to the " +
696
+ "developer." ) ;
697
+ }
698
+
659
699
// NOTE: It's not possible to catch exceptions a missing reference
660
700
// to the UnityEditor.iOS.Xcode assembly in this method as the runtime
661
701
// will attempt to load the assembly before the method is executed so
662
702
// we handle exceptions here.
663
703
try {
664
704
InitializeTargetName ( ) ;
665
705
} catch ( Exception exception ) {
666
- if ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . iOS ) {
667
- Log ( "Failed: " + exception . ToString ( ) , level : LogLevel . Error ) ;
668
- if ( exception is FileNotFoundException ||
669
- exception is TypeInitializationException ||
670
- exception is TargetInvocationException ) {
671
- // It's likely we failed to load the iOS Xcode extension.
672
- Debug . LogWarning (
673
- "Failed to load the " +
674
- "UnityEditor.iOS.Extensions.Xcode dll. " +
675
- "Is iOS support installed?" ) ;
676
- } else {
677
- throw exception ;
678
- }
706
+ Log ( "Failed: " + exception . ToString ( ) , level : LogLevel . Error ) ;
707
+ if ( exception is FileNotFoundException ||
708
+ exception is TypeInitializationException ||
709
+ exception is TargetInvocationException ) {
710
+ // It's likely we failed to load the iOS Xcode extension.
711
+ Debug . LogWarning (
712
+ "Failed to load the " +
713
+ "UnityEditor.iOS.Extensions.Xcode dll. " +
714
+ "Is iOS support installed?" ) ;
715
+ } else {
716
+ throw exception ;
679
717
}
680
718
}
681
719
682
720
// If Cocoapod tool auto-installation is enabled try installing on the first update of
683
721
// the editor when the editor environment has been initialized.
684
- if ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . iOS &&
685
- AutoPodToolInstallInEditorEnabled && CocoapodsIntegrationEnabled &&
722
+ if ( AutoPodToolInstallInEditorEnabled && CocoapodsIntegrationEnabled &&
686
723
! ExecutionEnvironment . InBatchMode ) {
687
- RunOnMainThread . Run ( ( ) => { AutoInstallCocoapods ( ) ; } , runNow : false ) ;
724
+ AutoInstallCocoapods ( ) ;
688
725
}
689
726
// Install / remove target SDK property poller.
690
727
SetEnablePollTargetSdk ( PodfileGenerationEnabled ) ;
691
728
// Load XML dependencies on the next editor update.
692
729
if ( PodfileGenerationEnabled ) {
693
- RunOnMainThread . Run ( RefreshXmlDependencies , runNow : false ) ;
730
+ RefreshXmlDependencies ( ) ;
694
731
}
695
732
696
733
// Prompt the user to use workspaces if they aren't at least using project level
697
734
// integration.
698
- if ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . iOS &&
699
- ( CocoapodsIntegrationMethod ) settings . GetInt ( PREFERENCE_COCOAPODS_INTEGRATION_METHOD ,
735
+ if ( ( CocoapodsIntegrationMethod ) settings . GetInt ( PREFERENCE_COCOAPODS_INTEGRATION_METHOD ,
700
736
CocoapodsIntegrationUpgradeDefault ) == CocoapodsIntegrationMethod . None &&
701
- ! ExecutionEnvironment . InBatchMode && ! UpgradeToWorkspaceWarningDisabled ) {
737
+ ! ExecutionEnvironment . InBatchMode && ! UpgradeToWorkspaceWarningDisabled ) {
702
738
703
739
DialogWindow . Display (
704
740
"Warning: CocoaPods integration is disabled!" ,
@@ -721,6 +757,9 @@ exception is TypeInitializationException ||
721
757
}
722
758
} ) ;
723
759
}
760
+ isInitialized = true ;
761
+
762
+ Log ( "IOSResolver Initialized" , verbose : true ) ;
724
763
}
725
764
726
765
/// <summary>
0 commit comments