可以在其他预制件内包含预制件实例。这称为嵌套预制件。嵌套预制件保留与自己的预制件资源的链接,同时也构成另一个预制件资源的一部分。
在预制件模式下,可以像在场景中一样添加和使用预制件实例。可以将预制件资源从 Project 窗口拖动到 Hierarchy 窗口或 Scene 视图,由此从已打开的预制件中的该资源创建预制件实例。
注意:在预制件模式下打开的预制件的根游戏对象不会显示蓝色立方体预制件图标,但是其他预制件的所有实例都会显示该图标。还可以为这些预制件实例添加覆盖,就像在场景中使用预制件实例一样。
还可以将预制件实例作为子项添加到场景中的另一个预制件实例,而无需进入预制件模式,就像可以添加任何其他游戏对象一样。这样添加的预制件实例在 Hierarchy 窗口中的图标上会叠加一个加号标示,表示这是对外层预制件的特定实例的覆盖。
添加的预制件可以按照与其他覆盖相同的方式(通过 Overrides 下拉窗口,或通过 Hierarchy 中游戏对象的上下文菜单)还原或应用于外层预制件,如通过预制件的实例编辑预制件中所述。Overrides 下拉选单按钮仅位于外层预制件上。应用后的预制件不再显示加号标示,因为它不再是覆盖,而是已经嵌套在外层预制件资源本身中。但是,该预制件却会保留蓝色立方体图标,因为它本身是一个预制件实例,并会保留与自己的预制件资源的连接。
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.