__实例覆盖__允许在预制件实例之间创建变化,同时仍将这些实例关联到同一预制件资源。
修改预制件资源时,更改将反映在其所有实例中。但是,也可以直接对单个实例进行修改。这样做会在该特定实例上创建__实例覆盖__。
例如,假设有一个预制件资源“Robot”,放置在游戏中的多个关卡中。但是,“Robot”的每个实例都有不同的速度值,并分配了不同的音频剪辑。
有四种不同的__实例覆盖__类型:
覆盖属性的值
添加组件
删除组件
添加子游戏对象
预制件实例存在一些限制:无法更改属于预制件的游戏对象的父级,且无法删除属于预制件的游戏对象。但是,可以停用游戏对象,这种操作很适合取代游戏对象删除操作(这算作属性覆盖)。
在 Inspector 窗口中,实例覆盖的名称标签以粗体显示,左边距使用蓝线显示。向预制件实例添加新组件时,边距位置的蓝线将涵盖整个组件。
添加和删除的组件在 Inspector 中的相应图标上也有加减符号标示,而添加的游戏对象在 Hierarchy 窗口中的相应图标上有一个加号标示。
In the Hierarchy window, Prefab instances with overridden or non-default values have an override indicator to show that they have been edited, which Unity displays with a blue line in the left margin with the same appearance as the lines for instance overrides in the Inspector window. For more information, see Hierarchy.
预制件实例上覆盖的属性值始终优先于预制件资源的值。这意味着,如果更改预制件资源的属性,对覆盖该属性的实例没有任何影响。
如果对预制件资源进行更改,但未按预期更新所有实例,则应检查实例上是否覆盖了该属性。最好仅在确实必要时才使用实例覆盖,因为如果整个项目中有大量实例覆盖,则很难判断对预制件资源的更改是否对所有实例都有影响。
预制件实例的__对齐__是一种特殊情况,与其他属性的处理方式不同。对齐__值绝不会从预制件资源传递到预制件实例。这意味着对齐值始终可与预制件资源的对齐不同,而不是作为显式实例覆盖。具体而言,对齐表示预制件实例的根变换的 Position__ 和 Rotation 属性,对于矩形变换,还包括 Width、Height、Margins、Anchors 和 Pivot 属性。
这是因为要求预制件的多个实例采用相同的位置和旋转是极其罕见的情况。更常见的情况是希望预制件实例具有不同的位置和旋转,因此 Unity 不会将它们视为预制件覆盖。
The data representing the values of your instance overrides can become unused if the script which declares them is modified or deleted. If this occurs, you can remove the unused override data.
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.