private void SearchForSourceFiles(List <SourceFileInfo> sourceFiles, DirectoryInfo directory) { if (directory.GetFiles("*.asmdef", SearchOption.TopDirectoryOnly).Length > 1) { // Source file is managed by another asmdef return; } foreach (FileInfo fileInfo in directory.GetFiles("*.cs", SearchOption.TopDirectoryOnly)) { sourceFiles.Add(SourceFileInfo.Parse(fileInfo, null)); } foreach (DirectoryInfo subDirectory in directory.GetDirectories("*", SearchOption.TopDirectoryOnly)) { SearchForSourceFiles(sourceFiles, subDirectory); } }
private void ProcessSourceFile(SourceFileInfo sourceFile, string sourceIncludeTemplate, List <string> sourceIncludes, Dictionary <Guid, string> sourceGuidToClassName) { // Get the entry for the map sourceGuidToClassName.Add(sourceFile.Guid, sourceFile.ClassType?.FullName); string linkPath = Utilities.GetRelativePath(AssemblyDefinitionInfo.Directory.FullName, sourceFile.File.FullName); string relativeSourcePath; switch (sourceFile.AssetLocation) { case AssetLocation.BuiltInPackage: relativeSourcePath = sourceFile.File.FullName; return; case AssetLocation.Project: relativeSourcePath = $"..\\..\\{Utilities.GetAssetsRelativePathFrom(sourceFile.File.FullName)}"; break; case AssetLocation.Package: relativeSourcePath = $"..\\..\\{Utilities.GetPackagesRelativePathFrom(sourceFile.File.FullName)}"; break; case AssetLocation.PackageCopy: relativeSourcePath = $"..\\{Utilities.GetPackagesRelativePathFrom(sourceFile.File.FullName)}"; break; case AssetLocation.External: relativeSourcePath = sourceFile.File.FullName; Debug.LogWarning($"Referencing external source file with full path '{sourceFile.File.FullName}'"); break; default: throw new InvalidDataException("Unknown asset location."); } sourceIncludes.Add(Utilities.ReplaceTokens(sourceIncludeTemplate, new Dictionary <string, string>() { { "##RELATIVE_SOURCE_PATH##", relativeSourcePath }, { "##PROJECT_LINK_PATH##", linkPath } })); }
/// <summary> /// Gets the source files for this assembly definition. /// </summary> /// <returns>The array of <see cref="SourceFileInfo"/>.</returns> public SourceFileInfo[] GetSources() { if (sourceFiles == null) { List <SourceFileInfo> sourceFiles = new List <SourceFileInfo>(); if (assembly != null) { foreach (string sourceFile in assembly.sourceFiles) { MonoScript asset = AssetDatabase.LoadAssetAtPath <MonoScript>(sourceFile); sourceFiles.Add(SourceFileInfo.Parse(new FileInfo(Utilities.GetFullPathFromKnownRelative(sourceFile)), asset.GetClass())); } } else { SearchForSourceFiles(sourceFiles, file.Directory); } this.sourceFiles = sourceFiles.ToArray(); } return(sourceFiles); }