Unity3D说明文档翻译-Prefabs

Prefabs

预设对象

It is convenient to build a GameObject in the scene by adding components and setting their properties to the appropriate values. This can create problems, however, when you have an object like an NPC, prop or piece of scenery that is reused in the scene several times. Simply copying the object will certainly produce duplicates but they will all be independently editable. Generally, you want all instances of a particular object to have the same properties, so when you edit one object in the scene, you would prefer not to have to make the same edit repeatedly to all the copies.

在场景内通过添加组件和设置它们的属性值可以方便添加游戏对象.这可能造成麻烦,即当你有一个对象项NPC,道具或风景块,在场景内多次再利用.简单的拷贝对象当然可制作复制品,但它们将要单独去编辑.

Fortunately, Unity has a Prefab asset type that allows you to store a GameObject object complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. Any edits made to a prefab asset are immediately reflected in all instances produced from it but you can also override components and settings for each instance individually.

幸运的是,Unity有一个预设资源类型,允许你存储一个完整的游戏对象包括组件和属性.预设表现为一个模版你可以用它在场景内新建对象.任何对一个预设资源的编辑会立即作用到所有它的实例,但你也可以对每个实例单独的覆盖组件和设置.

Note: When you drag an asset file (eg, a Mesh) into the scene, it will create a new object instance and all such instances will change when the original asset is changed. However, although its behaviour is superficially similar, the asset is not a prefab, so you won’t be able to add components to it or make use of the other prefab features described below.

注意:当你拖拽一个资源文件(比如一个网格)到场景内,它将创建一个新对象实例,并且当原始资源改变时所有实例都将改变.然而,尽管它的行为表面上相似,但此资源不是一个预设,所以你不能给它添加组件或使用上面介绍的其他预设对象特性.

Using Prefabs

使用预设对象

You can create a prefab by selecting Asset > Create Prefab and then dragging an object from the scene onto the “empty” prefab asset that appears. If you then drag a different GameObject onto the prefab you will be asked if you want to replace your current gameobject with the new one. Simply dragging the prefab asset from the project view to the scene view will then create instances of the prefab. Objects created as prefab instances will be shown in the hierarchy view in blue text. (Normal objects are shown in black text.)

你可以通过选择资源>创建预设创建一个预设对象,然后从场景拖拽一个对象到出现的空预设资源上.如果你然后拖拽一个不同游戏对象到此预设对象上,你将被问及你是否想要用新游戏对象替换当前的.简单地从项目视图拖拽预设资源到场景视图接着将创建此预设的实例.预设创建的实例将以蓝色文本显示在层级视图上.(正常对象是黑色文本显示)

As mentioned above changes to the prefab asset itself will be reflected in all instances but you can also modify individual instances separately. This is useful, say, when you want to create several similar NPCs but introduce variations to make them more realistic. To make it clear when a property has been overridden, it is shown in the inspector with its name label in boldface. (When a completely new component is added to a prefab instance, all of its properties will be shown in boldface.)

如上所述修改预设资源将作用到所以实例,但你也可以分别的单独修改实例.这非常有用,表示,当你想创建几个相同的NPC但引入变化来使它们更逼真.须明白当一个属性被覆盖,它在检视面板上的名称标签将用粗体显示.(当一个完整的新组件添加到预设实例上,所有的属性都将用粗体显示.)

Mesh Renderer on a prefab instance with “Cast Shadows” overridden

预设实例的网格渲染组件的”投射阴影”被覆盖.

 

You can also create instances of prefabs at runtime from your scripts. See the manual page aboutInstantiating Prefabs for further details.

你也可以通过脚本实时创建预设实例.查看手册页面实例化预设获取更详细信息.

Editing a Prefab from its Instances

从实例编辑预设对象

The inspector for a prefab instance has three buttons not present for a normal object: SelectRevert and Apply.

预设对象实例的检视面板上有3个标准对象没有的按钮:选定,恢复和应用.

The Select button selects the prefab asset from which the instance was generated. This allows you to edit the main prefab and thereby change all its instances. However, you can also save overridden values from an instance back to the originating prefab using the Apply button (modified Transform position and rotation values are excluded for obvious reasons). This effectively lets you edit all instances via any single instance and is a very quick and convenient way to make global changes. If you experiment with overriding properties but then decide you preferred the default values, you can use the Revert button to realign the instance with its prefab.

选定按钮选定生成此实例预设资源.这允许你编辑主预设从而改变所有它的实例.然而,你也可以使用应用按钮保存覆盖值从实例返回到原始预设(改变变换组件的位置和旋转值明显是会被拒绝的).这有效地让你通过任何单独实例编辑所有实例且是非常快速和方便的做全局改变的方法.如果你尝试覆盖属性但然后你发现你更倾向于默认值,你可以使用恢复按钮.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值