private static Assembly ResolveUnityEditoriOSXcodeExtension(
object sender, ResolveEventArgs args)
{
// The UnityEditor.iOS.Extensions.Xcode.dll has the wrong name baked
// into the assembly so references end up resolving as
// Unity.iOS.Extensions.Xcode. Catch this and redirect the load to
// the UnityEditor.iOS.Extensions.Xcode.
string assemblyName = (new AssemblyName(args.Name)).Name;
if (!(assemblyName.Equals("Unity.iOS.Extensions.Xcode") ||
assemblyName.Equals("UnityEditor.iOS.Extensions.Xcode"))) {
return null;
}
Log("Trying to load assembly: " + assemblyName, verbose: true);
iOSXcodeExtensionLoaded = false;
string fixedAssemblyName =
assemblyName.Replace("Unity.", "UnityEditor.") + ".dll";
Log("Redirecting to assembly name: " + fixedAssemblyName,
verbose: true);
// Get the managed DLLs folder.
string folderPath = Path.GetDirectoryName(
Assembly.GetAssembly(
typeof(UnityEditor.AssetPostprocessor)).Location);
// Try searching a common install location.
folderPath = Path.Combine(
(new DirectoryInfo(folderPath)).Parent.FullName,
IOS_PLAYBACK_ENGINES_PATH);
string assemblyPath = Path.Combine(folderPath, fixedAssemblyName);
if (!File.Exists(assemblyPath)) {
string searchPath = (new DirectoryInfo(folderPath)).FullName;
if (UnityEngine.RuntimePlatform.OSXEditor ==
UnityEngine.Application.platform) {
// Unity likes to move their DLLs around between releases to
// keep us on our toes, so search for the DLL under the
// package path.
searchPath = Path.GetDirectoryName(
searchPath.Substring(0, searchPath.LastIndexOf(".app")));
} else {
// Search under the Data directory.
searchPath = Path.GetDirectoryName(
searchPath.Substring(
0, searchPath.LastIndexOf(
"Data" + Path.DirectorySeparatorChar.ToString())));
}
Log("Searching for assembly under " + searchPath, verbose: true);
var files = FindFile(searchPath, fixedAssemblyName, 5);
if (files.Count > 0) assemblyPath = files.ToArray()[0];
}
// Try to load the assembly.
if (!File.Exists(assemblyPath)) {
Log(assemblyPath + " does not exist", verbose: true);
return null;
}
Log("Loading " + assemblyPath, verbose: true);
Assembly assembly = Assembly.LoadFrom(assemblyPath);
if (assembly != null) {
Log("Load succeeded from " + assemblyPath, verbose: true);
iOSXcodeExtensionLoaded = true;
}
return assembly;
}