private List <string> GetAssetsReferencedFromAssemblyDefinition(string assetPath) { var result = new List <string>(); var asset = AssetDatabase.LoadAssetAtPath <UnityEditorInternal.AssemblyDefinitionAsset>(assetPath); var data = JsonUtility.FromJson <AssemblyDefinitionData>(asset.text); if (data.references != null && data.references.Length > 0) { foreach (var reference in data.references) { #if !UNITY_2019_1_OR_NEWER var assemblyDefinitionFilePathFromAssemblyName = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName(reference); #else var assemblyDefinitionFilePathFromAssemblyName = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyReference(reference); #endif if (!string.IsNullOrEmpty(assemblyDefinitionFilePathFromAssemblyName)) { assemblyDefinitionFilePathFromAssemblyName = CSPathTools.EnforceSlashes(assemblyDefinitionFilePathFromAssemblyName); result.Add(assemblyDefinitionFilePathFromAssemblyName); } } } data.references = null; return(result); }
private List <string> GetAssetsReferencedFromAssemblyDefinitionReference(string assetPath) { var result = new List <string>(); var asset = AssetDatabase.LoadAssetAtPath <UnityEditorInternal.AssemblyDefinitionReferenceAsset>(assetPath); var data = JsonUtility.FromJson <AssemblyDefinitionReferenceData>(asset.text); if (!string.IsNullOrEmpty(data.reference)) { var assemblyDefinitionPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyReference(data.reference); if (!string.IsNullOrEmpty(assemblyDefinitionPath)) { assemblyDefinitionPath = CSPathTools.EnforceSlashes(assemblyDefinitionPath); var guid = AssetDatabase.AssetPathToGUID(assemblyDefinitionPath); if (!string.IsNullOrEmpty(guid)) { result.Add(guid); } } } data.reference = null; return(result); }
static ScraperEntry ScrapeIfConfigured(string path) { string asmdefPath; using (s_GetAssemblyDefinitionFilePathMarker.Auto()) { asmdefPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyReference(path); } if (asmdefPath != null && IsConfiguredToScrape(asmdefPath)) { var fullOutputPath = Path.GetFullPath(path); var scrapeFilePath = Path.Combine(Path.GetDirectoryName(asmdefPath), Path.GetFileNameWithoutExtension(path) + ".api"); using (s_TimestampMatchesMarker.Auto()) { if (s_Scraper.TimestampMatches(fullOutputPath) && File.Exists(scrapeFilePath)) { return(null); } } using (s_GetReferenceDirectoriesMarker.Auto()) { // CompilationPipeline.GetAssemblies() is very slow, so instead we use the paths returned by // CompilationPipeline.GetPrecompiledAssemblyPaths and the path of the assembly being scraped. // There are plans to make a version of GetAssemblies that returns just one assembly and should be much faster. // var actualAssembly = assembly ?? CompilationPipeline.GetAssemblies().First(a => a.outputPath == path); // var referenceDirectories = actualAssembly.allReferences.Select(Path.GetDirectoryName).Distinct().ToArray(); var extensionsFolder = Path.Combine(EditorApplication.applicationContentsPath, "UnityExtensions/Unity"); if (s_ReferenceDirectories == null) { s_ReferenceDirectories = CompilationPipeline .GetPrecompiledAssemblyPaths(CompilationPipeline.PrecompiledAssemblySources.All) .Append(path) .Select(Path.GetDirectoryName) .Append(Path.Combine(extensionsFolder, "TestRunner")) .Append(Path.Combine(extensionsFolder, "TestRunner/net35/unity-custom")) .Append(Path.Combine(extensionsFolder, "GUISystem")) .Append(Path.Combine(extensionsFolder, "GUISystem/Editor")) .Append(Path.Combine(extensionsFolder, "UnityVR/Editor")) .Distinct() .Where(Directory.Exists) .ToArray(); } } return(new ScraperEntry(fullOutputPath, scrapeFilePath, s_ReferenceDirectories)); } return(null); }
public void Load(string reference, bool useGUID) { var referencePath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyReference(reference); if (!string.IsNullOrEmpty(referencePath)) { asset = AssetDatabase.LoadAssetAtPath <AssemblyDefinitionAsset>(referencePath); if (useGUID) { var fileData = CustomScriptAssemblyData.FromJson(asset.text); name = fileData.name; } } }
private void UpgradeAssemblyDefinitionFile(string path) { if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(textMeshProAssemblyDefinitionName)) { return; } if (AssetDatabase.GetMainAssetTypeAtPath(path) != typeof(UnityEditorInternal.AssemblyDefinitionAsset)) { return; } AssemblyDefinitionFileContents asmFile = JsonUtility.FromJson <AssemblyDefinitionFileContents>(File.ReadAllText(path)); if (asmFile.references != null) { for (int i = 0; i < asmFile.references.Length; i++) { #if UNITY_2019_1_OR_NEWER string assemblyPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyReference(asmFile.references[i]); #else string assemblyPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName(asmFile.references[i]); #endif if (assemblyPath == textMeshProAssemblyDefinitionName) { return; } } } if (asmFile.references == null) { asmFile.references = new string[1] { textMeshProAssemblyDefinitionName } } ; else { Array.Resize(ref asmFile.references, asmFile.references.Length + 1); asmFile.references[asmFile.references.Length - 1] = textMeshProAssemblyDefinitionName; } stringBuilder.AppendLine("Upgrading Assembly Definition File: " + path); File.WriteAllText(path, JsonUtility.ToJson(asmFile, true)); }