22
22
using System . Collections . Generic ;
23
23
using System . IO ;
24
24
using System . Reflection ;
25
- using UnityEditor . iOS . Xcode ;
26
25
using UnityEditor ;
27
26
using UnityEditor . Callbacks ;
28
27
using UnityEngine ;
@@ -186,27 +185,27 @@ public static SortedDictionary<int, List<string>>
186
185
private static string IOS_PLAYBACK_ENGINES_PATH =
187
186
Path . Combine ( "PlaybackEngines" , "iOSSupport" ) ;
188
187
189
- // Search for a directory up to a maximum search depth stopping the
190
- // depth first search each time the specified directory is found.
191
- private static List < string > FindDirectory (
192
- string searchPath , string directoryToFind , int maxDepth ,
188
+ // Search for a file up to a maximum search depth stopping the
189
+ // depth first search each time the specified file is found.
190
+ private static List < string > FindFile (
191
+ string searchPath , string fileToFind , int maxDepth ,
193
192
int currentDepth = 0 ) {
194
- if ( Path . GetFileName ( searchPath ) == directoryToFind ) {
193
+ if ( Path . GetFileName ( searchPath ) == fileToFind ) {
195
194
return new List < string > { searchPath } ;
196
195
} else if ( maxDepth == currentDepth ) {
197
196
return new List < string > ( ) ;
198
197
}
199
- var foundDirs = new List < string > ( ) ;
200
- foreach ( var dir in Directory . GetDirectories ( searchPath ) ) {
201
- if ( Path . GetFileName ( dir ) == directoryToFind ) {
202
- foundDirs . Add ( dir ) ;
203
- } else {
204
- foundDirs . AddRange ( FindDirectory (
205
- dir , directoryToFind , maxDepth ,
206
- currentDepth : currentDepth + 1 ) ) ;
198
+ var foundFiles = new List < string > ( ) ;
199
+ foreach ( var file in Directory . GetFiles ( searchPath ) ) {
200
+ if ( Path . GetFileName ( file ) == fileToFind ) {
201
+ foundFiles . Add ( file ) ;
207
202
}
208
203
}
209
- return foundDirs ;
204
+ foreach ( var dir in Directory . GetDirectories ( searchPath ) ) {
205
+ foundFiles . AddRange ( FindFile ( dir , fileToFind , maxDepth ,
206
+ currentDepth : currentDepth + 1 ) ) ;
207
+ }
208
+ return foundFiles ;
210
209
}
211
210
212
211
// Try to load the Xcode editor extension.
@@ -218,47 +217,55 @@ private static Assembly ResolveUnityEditoriOSXcodeExtension(
218
217
// Unity.iOS.Extensions.Xcode. Catch this and redirect the load to
219
218
// the UnityEditor.iOS.Extensions.Xcode.
220
219
string assemblyName = ( new AssemblyName ( args . Name ) ) . Name ;
221
- if ( ! assemblyName . Equals ( "Unity.iOS.Extensions.Xcode" ) ) {
220
+ if ( ! ( assemblyName . Equals ( "Unity.iOS.Extensions.Xcode" ) ||
221
+ assemblyName . Equals ( "UnityEditor.iOS.Extensions.Xcode" ) ) ) {
222
222
return null ;
223
223
}
224
+ Log ( "Trying to load assembly: " + assemblyName , verbose : true ) ;
224
225
iOSXcodeExtensionLoaded = false ;
225
226
string fixedAssemblyName =
226
227
assemblyName . Replace ( "Unity." , "UnityEditor." ) + ".dll" ;
228
+ Log ( "Redirecting to assembly name: " + fixedAssemblyName ,
229
+ verbose : true ) ;
227
230
228
- // Find the playback engines folder.
231
+ // Get the managed DLLs folder.
229
232
string folderPath = Path . GetDirectoryName (
230
233
Assembly . GetAssembly (
231
234
typeof ( UnityEditor . AssetPostprocessor ) ) . Location ) ;
232
- if ( UnityEngine . RuntimePlatform . OSXEditor ==
233
- UnityEngine . Application . platform ) {
234
- // Unity likes to move their DLLs around between releases to keep
235
- // us on our toes, so search for the PlaybackEngines folder under
236
- // the package path.
235
+ // Try searching a common install location.
236
+ folderPath = Path . Combine (
237
+ ( new DirectoryInfo ( folderPath ) ) . Parent . FullName ,
238
+ IOS_PLAYBACK_ENGINES_PATH ) ;
239
+ string assemblyPath = Path . Combine ( folderPath , fixedAssemblyName ) ;
240
+ if ( ! File . Exists ( assemblyPath ) ) {
237
241
string searchPath = ( new DirectoryInfo ( folderPath ) ) . FullName ;
238
- searchPath = Path . GetDirectoryName (
239
- searchPath . Substring ( 0 , searchPath . LastIndexOf ( ".app" ) ) ) ;
240
- foreach ( var directory in
241
- FindDirectory (
242
- searchPath ,
243
- Path . GetFileName ( IOS_PLAYBACK_ENGINES_PATH ) , 3 ) ) {
244
- if ( File . Exists ( Path . Combine ( directory , fixedAssemblyName ) ) ) {
245
- folderPath = directory ;
246
- break ;
247
- }
242
+ if ( UnityEngine . RuntimePlatform . OSXEditor ==
243
+ UnityEngine . Application . platform ) {
244
+ // Unity likes to move their DLLs around between releases to
245
+ // keep us on our toes, so search for the DLL under the
246
+ // package path.
247
+ searchPath = Path . GetDirectoryName (
248
+ searchPath . Substring ( 0 , searchPath . LastIndexOf ( ".app" ) ) ) ;
249
+ } else {
250
+ // Search under the Data directory.
251
+ searchPath = Path . GetDirectoryName (
252
+ searchPath . Substring (
253
+ 0 , searchPath . LastIndexOf (
254
+ "Data" + Path . DirectorySeparatorChar . ToString ( ) ) ) ) ;
248
255
}
249
- } else {
250
- folderPath = Path . Combine (
251
- ( new DirectoryInfo ( folderPath ) ) . Parent . FullName ,
252
- IOS_PLAYBACK_ENGINES_PATH ) ;
256
+ Log ( "Searching for assembly under " + searchPath , verbose : true ) ;
257
+ var files = FindFile ( searchPath , fixedAssemblyName , 5 ) ;
258
+ if ( files . Count > 0 ) assemblyPath = files . ToArray ( ) [ 0 ] ;
253
259
}
254
-
255
260
// Try to load the assembly.
256
- string assemblyPath = Path . Combine ( folderPath , fixedAssemblyName ) ;
257
261
if ( ! File . Exists ( assemblyPath ) ) {
258
- return null ;
262
+ Log ( assemblyPath + " does not exist" , verbose : true ) ;
263
+ return null ;
259
264
}
265
+ Log ( "Loading " + assemblyPath , verbose : true ) ;
260
266
Assembly assembly = Assembly . LoadFrom ( assemblyPath ) ;
261
267
if ( assembly != null ) {
268
+ Log ( "Load succeeded from " + assemblyPath , verbose : true ) ;
262
269
iOSXcodeExtensionLoaded = true ;
263
270
}
264
271
return assembly ;
@@ -268,10 +275,22 @@ private static Assembly ResolveUnityEditoriOSXcodeExtension(
268
275
/// Initialize the module.
269
276
/// </summary>
270
277
static IOSResolver ( ) {
278
+ // NOTE: We can't reference the UnityEditor.iOS.Xcode module in this
279
+ // method as the Mono runtime in Unity 4 and below requires all
280
+ // dependencies of a method are loaded before the method is executed
281
+ // so we install the DLL loader first then try using the Xcode module.
271
282
RemapXcodeExtension ( ) ;
283
+ InitializeTargetName ( ) ;
284
+ }
285
+
286
+ /// <summary>
287
+ /// Initialize the TARGET_NAME property.
288
+ /// </summary>
289
+ private static void InitializeTargetName ( ) {
272
290
try {
273
- TARGET_NAME = PBXProject . GetUnityTargetName ( ) ;
291
+ TARGET_NAME = UnityEditor . iOS . Xcode . PBXProject . GetUnityTargetName ( ) ;
274
292
} catch ( Exception exception ) {
293
+ Debug . Log ( "Failed: " + exception . ToString ( ) ) ;
275
294
if ( exception is FileNotFoundException ||
276
295
exception is TypeInitializationException ||
277
296
exception is TargetInvocationException ) {
@@ -561,10 +580,9 @@ public static void OnPostProcessPatchProject(BuildTarget buildTarget,
561
580
String . Join ( ", " , podsWithoutBitcode . ToArray ( ) ) + ")" ,
562
581
level : LogLevel . Warning ) ;
563
582
}
564
-
565
583
// Configure project settings for Cocoapods.
566
584
string pbxprojPath = GetProjectPath ( pathToBuiltProject ) ;
567
- PBXProject project = new PBXProject ( ) ;
585
+ var project = new UnityEditor . iOS . Xcode . PBXProject ( ) ;
568
586
project . ReadFromString ( File . ReadAllText ( pbxprojPath ) ) ;
569
587
string target = project . TargetGuidByName ( TARGET_NAME ) ;
570
588
project . SetBuildProperty ( target , "CLANG_ENABLE_MODULES" , "YES" ) ;
@@ -680,7 +698,7 @@ public static void OnPostProcessUpdateProjectDeps(
680
698
"Resources" ) ) ;
681
699
682
700
string pbxprojPath = GetProjectPath ( pathToBuiltProject ) ;
683
- PBXProject project = new PBXProject ( ) ;
701
+ var project = new UnityEditor . iOS . Xcode . PBXProject ( ) ;
684
702
project . ReadFromString ( File . ReadAllText ( pbxprojPath ) ) ;
685
703
string target = project . TargetGuidByName ( TARGET_NAME ) ;
686
704
@@ -707,10 +725,11 @@ public static void OnPostProcessUpdateProjectDeps(
707
725
PlayServicesSupport . DeleteExistingFileOrDirectory (
708
726
destFrameworkFullPath ) ;
709
727
Directory . Move ( frameworkFullPath , destFrameworkFullPath ) ;
710
- project . AddFileToBuild ( target ,
711
- project . AddFile ( destFrameworkPath ,
712
- destFrameworkPath ,
713
- PBXSourceTree . Source ) ) ;
728
+ project . AddFileToBuild (
729
+ target ,
730
+ project . AddFile ( destFrameworkPath ,
731
+ destFrameworkPath ,
732
+ UnityEditor . iOS . Xcode . PBXSourceTree . Source ) ) ;
714
733
715
734
string moduleMapPath =
716
735
Path . Combine ( Path . Combine ( destFrameworkFullPath , "Modules" ) ,
@@ -752,8 +771,9 @@ public static void OnPostProcessUpdateProjectDeps(
752
771
File . Copy ( resFile , Path . Combine ( pathToBuiltProject ,
753
772
destFile ) , true ) ;
754
773
project . AddFileToBuild (
755
- target , project . AddFile ( destFile , destFile ,
756
- PBXSourceTree . Source ) ) ;
774
+ target , project . AddFile (
775
+ destFile , destFile ,
776
+ UnityEditor . iOS . Xcode . PBXSourceTree . Source ) ) ;
757
777
}
758
778
foreach ( var resFolder in resFolders ) {
759
779
string destFolder =
@@ -765,8 +785,9 @@ public static void OnPostProcessUpdateProjectDeps(
765
785
destFolderFullPath ) ;
766
786
Directory . Move ( resFolder , destFolderFullPath ) ;
767
787
project . AddFileToBuild (
768
- target , project . AddFile ( destFolder , destFolder ,
769
- PBXSourceTree . Source ) ) ;
788
+ target , project . AddFile (
789
+ destFolder , destFolder ,
790
+ UnityEditor . iOS . Xcode . PBXSourceTree . Source ) ) ;
770
791
}
771
792
}
772
793
}
0 commit comments