递增 Unity 用于确定是否允许自动 AssetDatabase 刷新行为的内部计数器。
Unity 在内部将此方法和对应的 AssetDatabase.AllowAutoRefresh 一起使用,以防止在某些操作过程中发生自动刷新。例如,Unity 的版本控制集成使用它来防止在获取新变更集时发生自动刷新。
如果要构建自己的编辑器工具,并且需要防止在自己的操作过程中发生自动刷新(例如,如果要构建与版本控制系统的自定义集成),此方法很有用。
此方法不只是简单地禁用自动刷新功能。而是递增计数器,仅当计数器恢复为零时才允许自动刷新。因此,每次调用 DisallowAutoRefresh 时,都必须确保也对应地调用 AllowAutoRefresh。例如:
AssetDatabase.DisallowAutoRefresh(); // your code here, performed while auto-refresh is not allowed AssetDatabase.AllowAutoRefresh();
使用此内部计数器,以便如果代码执行多个嵌套的“disable”和“enable”对,内部对不会意外地过早重新启用自动刷新。相反,每对会将计数器加一或减一,如果代码正确嵌套,则对 AllowAutoRefresh 的最终外部调用会将计数器设置为零。
重要注意事项:
此方法不会影响 AssetDatabase.Refresh 的行为。如果调用 AssetDatabase.Refresh,则资源数据库会始终执行刷新,无论是否使用此方法及其内部计数器。
此方法与 Unity Preferences 窗口中的自动刷新设置不同,该设置不修改此内部计数器。如果禁用了 Unity 的自动刷新偏好设置,则调用 Allow 和 Disallow 仍会修改内部计数器,但是编辑器不会自动刷新,无论内部计数器是否为零。
另请参阅:AssetDatabase.AllowAutoRefresh。
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.