程序集定义和程序集定义引用资源是 JSON 文件。可以使用 Inspector 窗口在 Unity 编辑器中编辑资源文件,不过也可以使用外部工具修改 JSON 内容。
程序集定义是具有以下字段的一种 JSON 对象:
可选。默认为 false。请参阅 Allow ‘unsafe’ Code。
"allowUnsafeCode" : true
可选。默认为 true。请参阅 Auto Referenced。
"autoReferenced": false
可选。用作约束的符号。可以为空。请参阅 Define Constraints。
"defineConstraints": [
"UNITY_2019",
"UNITY_INCLUDE_TESTS"
]
可选。要排除的平台名称字符串或空数组。如果 includePlatforms 包含值,则 excludePlatforms 数组必须为空。可以使用 CompilationPipeline.GetAssemblyDefinitionPlatforms 函数检索平台名称字符串(调用此函数时,必须为当前编辑器安装对平台的支持。)请参阅 Platforms。
"includePlatforms": [],
"excludePlatforms": [
"iOS",
"macOSStandalone",
"tvOS"
]
可选。要包含的平台名称字符串或空数组。如果 excludePlatforms 包含值,则 includePlatforms 数组必须为空。可以使用 CompilationPipeline.GetAssemblyDefinitionPlatforms 函数检索平台名称字符串(调用此函数时,必须为当前编辑器安装对平台的支持。)请参阅 Platforms。
"includePlatforms": [
"Android",
"LinuxStandalone64",
"WebGL"
],
"excludePlatforms": []
必需。任何合法程序集名称。
"name" : "MyAssemblyName"
可选。默认为 false。请参阅 No Engine References。
"noEngineReferences": false
可选。在较早版本的 Unity 中,此字段对用于将程序集指定为测试程序集的 Unity References : Test Assemblies 选项进行序列化。从 Unity 2019.3 开始,不再显示该选项。该字段仍受支持,但如果在较新版本的 Unity 编辑器中重新序列化资源,则该字段会替换为等效的程序集引用。
请参阅创建测试程序集以了解有关测试程序集的更多信息。
"optionalUnityReferences": [
"TestAssemblies"
]
可选。如果 precompiledReferences 包含值,则设置为 true。默认为 false。
请参阅 [Override References]。
"overrideReferences": true
可选。引用的 DLL 库的文件名,包括扩展名,但没有其他路径元素。可以为空。除非将 overrideReferences 设置为 true,否则会忽略此数组。
请参阅 Assembly References。
"overrideReferences": true,
"precompiledReferences": [
"Newtonsoft.Json.dll",
"nunit.framework.dll"
]
可选。对使用程序集定义资源创建的其他程序集的引用。可以使用程序集定义资源文件的 GUID 或程序集的名称(由程序集定义的 name 字段定义)。必须对列表中的所有引用使用相同格式。可以为空。
可以使用 AssetDatabase.AssetPathToGUID 函数检索资源的 GUID。(GUID 也是与每个资源关联的元数据的一部分。)
请注意,编辑器在 Assembly Definition Inspector 中显示一个 Use GUIDs 选项。此选项不在关联 JSON 文件中进行序列化。而是从文件中找到的引用格式推断选择。
请参阅引用另一个程序集。
使用 GUID:
"references": [
"GUID:17b36165d09634a48bf5a0e4bb27f4bd",
"GUID:b470eee7144904e59a1064b70fa1b086",
"GUID:2bafac87e7f4b9b418d9448d219b01ab",
"GUID:27619889b8ba8c24980f49ee34dbb44a",
"GUID:0acc523941302664db1f4e527237feb3"
]
使用程序集名称:
"references": [
"Unity.CollabProxy.Editor",
"AssemblyB",
"UnityEngine.UI",
"UnityEngine.TestRunner",
"UnityEditor.TestRunner"
]
可选。包含每个版本定义的对象。此对象具有三个字段:
请参阅 Version Defines。
"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"
}
]
使用对其他程序集定义的引用的程序集名称和 includePlatforms:
{
"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 和 excludePlatforms:
{
"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
}
程序集定义引用是具有以下字段的一种 JSON 对象:
必需。要引用的程序集定义。请参阅程序集定义引用。
可以使用程序集的名称或资源的 GUID 引用程序集定义资源。可以使用 AssetDatabase.AssetPathToGUID 函数检索资源的 GUID。(GUID 也是与每个资源关联的元数据的一部分。)
使用程序集名称:
{
"reference": "AssemblyA"
}
使用程序集定义资源 GUID
{
"reference": "GUID:f4de40948f4904ecb94b59dd38aab8a1"
}
请参阅创建程序集定义引用资源。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.