文档

Unity 引擎

Unity 引擎

程序Assembly DefinitionFile Format参考

程序Assembly DefinitionFile Format参考。
阅读时间5 分钟最后更新于 7 天前

Assembly Definition 和 Assembly Definition Reference Assets 是 json 文件。可以使用
Inspector員

?

窗口在 Unity Editor 中编辑资源文件,但也可以使用 External 工具直接修改 json 内容。

Assembly Definition json

Assembly Definition 是具有以下字段的 json Object:

密钥

Type(类型)

必需

描述

allowUnsafeCode
bool可选默认情况下为 false。ON 选项含义的更多信息,请参阅 General 选项中的 Allow 'unsafe' 代码。
autoReferenced
bool可选默认情况下为 true。ON 选项含义的更多信息,请参阅 General 选项中的自动引用。
defineConstraints
string[]可选可以为空。有关更多信息,请参阅定义约束。
excludePlatforms
string[]可选要排除的平台 Name 字符串或空 Array。如果
includePlatforms
包含值,则
excludePlatforms
Array 必须为空。有效平台名称字符串是
CompilationPipeline.GetAssemblyDefinitionPlatforms
返回的
AssemblyDefinitionPlatform
对象数组的
AssemblyDefinitionPlatform.Name
Properties。只有为当前 Editor 安装了版本 Support 的平台才有效。有关更多信息,请参阅平台。
includePlatforms
string[]可选要包含的平台 Name 字符串或空 Array。如果
excludePlatforms
包含值,则
includePlatforms
Array 必须为空。有效平台名称字符串是
CompilationPipeline.GetAssemblyDefinitionPlatforms
返回的
AssemblyDefinitionPlatform
对象数组的
AssemblyDefinitionPlatform.Name
Properties。只有为当前 Editor 安装了版本 Support 的平台才有效。有关更多信息,请参阅平台。
name
字符串必需有关更多信息,请参阅 Name。
noEngineReferences
bool可选默认情况下为 false。ON 选项含义的更多信息,请参阅 General 选项中的 No Engine引用。
overrideReferences
bool可选默认情况下为 false。如果
precompiledReferences
包含值,则设置为 true。ON 选项含义的更多信息,请参阅 General 选项中的覆盖引用。
precompiledReferences
string[]可选引用的 DLL 库的文件名,包括扩展名,但没有 Other 路径元素。可以为空。除非将
overrideReferences
设置为 true,否则将忽略此 Array。有关更多信息,请参阅引用程序集。
references
string[]可选对使用程序Assembly DefinitionAssets创建的Other程序集的引用。可以使用 Assembly Definition 资源文件的 GUID 或 Assembly Definition 的
name
Field 定义的程序集 Name。必须对列表中的All引用使用相同的表单。可以为空。

您可以使用
AssetDatabase.AssetPathToGUID
函数检索资源的 GUID。GUID 也是与每个资源关联的元数据的一部分。

请注意,Editor 在 Assembly Definition Inspector 中显示 Use GUIDs 选项。此选项不会在关联的 json 文件中序列化。而是根据文件中的引用形式推断选择。有关更多信息,请参阅引用程序集。
versionDefines
对象可选包含每个版本定义的 Object。此 Object 有三个字段:
  • name
    :string -- 资源的名称。
  • expression
    :string -- 定义资源版本或范围的表达式。
  • define
    :string -- 要定义的符号。
有关更多信息,请参阅版本定义。

包含程序集名称和包含平台的示例

以下程序集定义示例 Json 使用程序集名称来引用 Other 程序集定义,并使用
includePlatforms
Key 指定包含的平台数组:
{ "name": “BeeAssembly”, "references": [ "Unity.CollabProxy.Editor", "AssemblyB", "UnityEngine.UI", "UnityEngine.TestRunner", "UnityEditor.TestRunner" ], "includePlatforms": [ "Android", "LinuxStandalone64", "WebGL" ], "excludePlatforms": [], "overrideReferences": true, "precompiledReferences": [ "Newtonsoft.Json.dll", "nunit.framework.dll" ], "autoReferenced": false, "defineConstraints": [ "UNITY_2019", "UNITY_INCLUDE_TESTS" ], "versionDefines": [ { "name": "com.unity.ide.vscode", "expression": "[1.7,2.4.1]", "define":"MY_SYMBOL" }, { "name": "com.unity.test-framework", "expression": "[2.7.2-preview.8]", "define":TESTS(测试) } ], "noEngineReferences": false}

包含 GUID 和排除平台的示例

以下程序集定义示例 json 使用程序集 GUID 引用其他程序集定义,并使用
excludePlatforms
Key 指定排除平台的 Array:
{ "name": “BeeAssembly”, "references": [ "GUID:17b36165d09634a48bf5a0e4bb27f4bd", "GUID:b470eee7144904e59a1064b70fa1b086", "GUID:2bafac87e7f4b9b418d9448d219b01ab", "GUID:27619889b8ba8c24980f49ee34dbb44a", "GUID:0acc523941302664db1f4e527237feb3" ], "includePlatforms": [], "excludePlatforms": [ "iOS", "macOSStandalone", "tvOS" ], "allowUnsafeCode": false, "overrideReferences": true, "precompiledReferences": [ "Newtonsoft.Json.dll", "nunit.framework.dll" ], "autoReferenced": false, "defineConstraints": [ "UNITY_2019", "UNITY_INCLUDE_TESTS" ], "versionDefines": [ { "name": "com.unity.ide.vscode", "expression": "[1.7,2.4.1]", "define":"MY_SYMBOL" }, { "name": "com.unity.test-framework", "expression": "[2.7.2-preview.8]", "define":TESTS(测试) } ], "noEngineReferences": false}

程序Assembly Definition参考 json

Assembly Definition 引用是只有一个必需 Field 的 json 对象:名为
reference
的字符串。它通过程序Nameme称或程序Assembly Definition资源 GUID 指定要引用的程序集。您可以使用
AssetDatabase.AssetPathToGUID
函数检索资源的 GUID。GUID 也是与每个资源关联的元数据的一部分。
以下 Assembly Definition Reference 示例按 Name 引用其他资源:
{ "reference":"AssemblyA"}
以下 Assembly Definition Reference 示例按资源 GUID 引用其他资源:
{ "reference":"GUID:f4de40948f4904ecb94b59dd38aab8a1"}

其他资源