程序程序集数据和编译细节信息
定义程序集的元数据。
阅读时间2 分钟最后更新于 6 天前
您可以为程序集定义其他元数据并检索项目版本中包含的程序集 ON 信息。
设置程序集Attributes
您可以使用程序Attributestributes为程序集设置元数Properties性。虽然不是要求,但最好将这些Attributes与程序集定义一起定义在名为 的单独文件中。
AssemblyInfo.cs例如,以下程序集Attributes 指定了几个 .NET 程序集元数据值和 Unity 定义的 属性,这些属性会影响在 Project 版本时已从程序集移除未使用的代码的方式:
Preserve[程序集:System"Bee Corp.")][程序集:程序集[程序集:System.Reflection.AssemblyCopyright("Copyright 2020.")][程序集:UnityEngine.Scripting.Preserve]
在版本脚本中获取程序集信息
使用 类可以检索有关 Unity 为项目构建的所有程序集的信息,包括基于 Assembly Definition Assets 创建的程序集。
CompilationPipeline例如,以下脚本使用 类列出 Project 中的所有当前 Player 程序集:
CompilationPipelineusing UnityEditor;using UnityEditor.Compilation;public static class AssemblyLister{ [MenuItem("工具/控制台中的列表 Player 程序集")] public static void PrintAssemblyNames() { UnityEngine.Debug.Log("== Player Assemblies =="); 程序集[] playerAssemblies = CompilationPipeline.GetAssemblies(AssembliesType.Player); foreach(在 playerAssemblies 中变化程序集) { UnityEngine.Debug.Log(assembly.name); } }}