在其他预制件中使用预制件或使用预制件变体时,覆盖可存在于多个级别,且相同的覆盖可应用于多个不同的预制件。
当一个预制件实例的内部有嵌套的预制件或者是预制件变体时,可以选择应该将覆盖应用于哪个预制件。
假设一个预制件“Vase”嵌套在预制件“Table”中的,而且场景包含“Table”预制件的一个实例。
在此实例上,如果“Vase”上的属性被覆盖,则可以将此覆盖应用于多个预制件:“Vase”或“Table”。
Overrides 下拉窗口中的 Apply All 按钮仅允许将覆盖应用于外层预制件:在本例中为“Table”。但是,通过上下文菜单或通过 Overrides 下拉窗口中各个组件的比较视图应用覆盖时,可以选择应用目标。
在此示例中,如果选择 Apply to Prefab ‘Vase’,该值将应用于“Vase”预制件资源,并用于“Vase”预制件的所有实例。
另外,如果在选择 Apply as Override in Prefab ‘Table’,该值将成为“Table”预制件内的“Vase”实例上的覆盖。该属性不再标记为场景内实例上的覆盖,但如果在预制件模式下打开“Table”预制件,则“Vase”预制件实例上的属性将在此处标记为覆盖。
覆盖为“Table”预制件资源中的覆盖时,“Vase”预制件资源本身完全不受影响。这意味着“Table”预制件的所有实例现在都在其“Vase”预制件实例上具有新值,但不属于“Table”预制件的其他“Vase”预制件实例不受影响。
如果“Vase”预制件本身的属性稍后改变,此更改将影响“Vase”预制件的所有实例,但该属性被覆盖的实例除外。由于属性在“Table”预制件内的“Vase”实例上被覆盖,因此更改不会影响属于“Table”实例的任何“Vase”实例。
将一个或多个属性应用于内层预制件资源有时也可能修改外层预制件资源,因为这些属性会在外层预制件中恢复其覆盖。
在我们的示例中,如果选择 __Apply to Prefab ‘Vase’__,且“Table”预制件具有该值的覆盖,则“Table”预制件中的此覆盖将同时恢复,使实例上的属性保留刚应用的值。如果不是这种情况,则实例上的值将在应用后立即更改。
2018–07–31 页面已发布并只进行了有限的编辑审查
在 2018.3 版中添加了嵌套预制件和预制件变体
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.