资源导入器,包括您编写的任何脚本化导入器,应产生一致(确定性)的结果。这意味着它们应始终从相同的输入和依赖集产生相同的输出。
为了验证您的导入器是否如此,资源数据库提供了两种方法检查当前项目中资源的导入结果的一致性。检查一致性的两种方法是:
在编辑器中手动重新导入一项或多项资源
使用 -consistencyCheck 命令行参数打开编辑器。
手动重新导入资源会使 Unity 检查新的导入结果是否与之前缓存的导入结果匹配。
要开始手动重新导入,请右键单击资源并从上下文菜单选择 Reimport。
Unity 会检查导入结果的一致性。如果检测到不一致的结果,Unity 会在控制台窗口中打印警告,详细说明导致问题的导入器,例如:
Importer(<name of importer>) generated inconsistent result for asset(guid:<guid of the asset>) "<name of asset>"
当您重新导入根资源时,Unity 还会对子资源进行重新导入并执行一致性检查。
进行一致性检查的第二种方法是使用 -consistencyCheck 命令行参数打开 Unity。这会对项目中的所有资源和导入器执行一致性检查。
命令行参数 | 描述 | 示例: |
---|---|---|
-consistencyCheck |
告诉编辑器在启动时执行一致性检查。默认情况下,它执行一个“本地”检查(见下文)。 | -consistencyCheck |
-consistencyCheckSourceMode string |
设置一致性检查器在对资源导入进行检查时所参照的源。有两个可能的值:“local” 或 “cacheserver”。 “local” 意味着它强制在本地重新导入所有资源并检查导入结果是否与之前的导入不同。 “cacheserver” 意味着它向 cacheserver(缓存服务器)询问资源的元数据,并比较本地结果是否与 cacheserver 上的匹配。在这种情况下,不会重新导入所有资源。 |
-consistencyCheckSourceMode local -consistencyCheckSourceMode cacheserver |
启动期间发现的任何不一致都会记录到控制台以及编辑器日志文件中。
一致性检查器只检查可缓存的资源导入。因此,如果您禁用 ScriptedImporter 的缓存,则该导入的一致性检查也将被禁用。有关如何禁用脚本化导入器缓存的详细信息,请参阅 AssetImporters.ScriptedImporterAttribute。
要将缓存服务器用作验证源,请参阅 Unity 加速器文档。
当检测到导入器不一致时,您可以在编辑器日志中找到有关该问题的更多信息。其中包括:
哪个资源导致一致性检查失败
该资源的 GUID
资源导入结果的内容哈希
它与资源的先前修订的比较结果
以下是显示导入器不一致的编辑器日志示例:
ConsistencyChecker - guid: a1945cd7aab67441ba89015f97494624, dependenciesHash.value: fb8cfb407bba82d4daded6031688ba9b, artifactid: 07078a054d3f597b4c2cc47e8e4c0bde, producedFiles[0].extension: , producedFiles[0].contentHash: 8490a5ed35a4361d679e6055a386969e
ConsistencyChecker - guid: a1945cd7aab67441ba89015f97494624, dependenciesHash.value: fb8cfb407bba82d4daded6031688ba9b, artifactid: 07078a054d3f597b4c2cc47e8e4c0bde, producedFiles[1].extension: .info, producedFiles[1].contentHash: 4bd9140e19d2e44782f1131172e514ba
ConsistencyChecker - guid: a1945cd7aab67441ba89015f97494624, dependenciesHash.value: fb8cfb407bba82d4daded6031688ba9b, artifactid: 646d6432767729ea7d288c636183de97, producedFiles[0].extension: , producedFiles[0].contentHash: 5ca760170f85012ce16aa8c22e8d9ea1
ConsistencyChecker - guid: a1945cd7aab67441ba89015f97494624, dependenciesHash.value: fb8cfb407bba82d4daded6031688ba9b, artifactid: 646d6432767729ea7d288c636183de97, producedFiles[1].extension: .info, producedFiles[1].contentHash: 4bd9140e19d2e44782f1131172e514ba
Importer(ScriptedImporter:Assembly-CSharp::RandomImporter) generated inconsistent result for asset(guid:a1945cd7aab67441ba89015f97494624) "Assets/first.rand"
如果缓存服务器不可用,一致性检查器会在编辑器日志中打印警告。
如果尚未为项目设置缓存服务器,则会打印以下消息。
ConsistencyChecker - Cacheserver is not enabled
如果 Unity 无法连接到缓存服务器,则会打印以下消息。
ConsistencyChecker - Not connected to accelerator/cacheserver
您可以使用‘binary2text’工具(位于 Unity 编辑器安装位置下的 Data/Tools 文件夹中)检查 library 文件夹的内容以查看导入器生成的准确结果。
例如:
./Data/Tools/binary2text ./myProject/Library/Artifacts/84/8490a5ed35a4361d679e6055a386969e output_file
哈希值是资源的内容哈希。要查找所报告的不一致之处并查看检查期间生成的内容,请查看编辑器日志。
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.