Unity3D基础教程2-3:预制品(Prefabs)

2014-08-08 17:58:11|?次阅读|上传:huigezrx【已有?条评论】发表评论

关键词:Unity3D, 游戏, 虚拟现实|来源:唯设编程网

This allows you to modify Prefab instances to make them unique from their source Prefabs without breaking the Prefab link.

允许你修改预制品实例使它们独立从它们源预制品,没有打破预制品连接。

Unity3D基础教程2-3:预制品(Prefabs)

A linked GameObject with no overrides enabled. 一个没有覆盖GameObject连接启用

Unity3D基础教程2-3:预制品(Prefabs)

A linked GameObject with one override enabled. 一个有覆盖GameObject的连接启用

If you want to update the source Prefab and all instances with the new overridden values, you can click the Apply button in the Inspector.

如果你想更新源预制品以及所有的实例用新覆盖值,你可以点击Apply(应用)按钮在检视器里。

If you want to discard all overrides on a particular instance, you can click the Revert button.

如果你想放弃所有的覆盖在一个特殊的实例上,你可以点击Revert(还原)按钮

Breaking and Restoring Prefab Links 断开与恢复预制品连接

There are certain actions which will break the link between a single instance and its source prefab, but the link can always be restored. Actions that will break the link:

有确定的操作将断开一个单一实例与它们源预制品之间的连接,但连接可以总被恢复。端开连接的方法:

  • Adding or removing a Component 添加或移除一个组件
  • Adding or removing a child GameObject 添加或移除一个子GameObject

These actions will prompt a warning/confirmation message about breaking the link. Confirming the action will break the link so changes to the source Prefab will no longer affect the broken instance. To restore the link, you can click either the Reconnect or Apply buttons in the Inspector of the instance.

这些操作将提示一个警告/确认断开连接消息框。确定操作将断开连接使改变源预制品将不在影响端口的实例。恢复连接,你可以点击任一的Reconnect(重新连接)或Apply(应用)按钮在实例的检视器里。

  • Reconnect will discard all differences from the source Prefab. Reconnect(重新连接)将放弃从源预制品的所有差异。
  • Apply will copy all differences into the source Prefab (and therefore, all other Prefab instances)
  • Apply(应用)将复制所有差异到源预制品(因此,含有所有其它预制品实例)

Imported Prefabs 引入预制品

When you place a mesh asset into your Assets folder, Unity automatically imports the file and generates something that looks similar to a Prefab out of the mesh. This is not actually a Prefab, it is simply the asset file itself. Instancing and working with assets introduces some limitations that are not present when working with normal Prefabs.

当你放置一个网格资产到你的资产文件夹,Unity自动的引入文件和生成一些类似于一个用网格制成的预制品。这不是一个实际的预制品,仅仅是一个资产文件本身。实例和资产的工作引入了一些限制,当与正常预制品一起工作时不存在。

Unity3D基础教程2-3:预制品(Prefabs)
Notice the asset icon is a bit different from the Prefab icons 注意资产图标是异于预制品图标。

The asset is instantiated in the scene as a GameObject, linked to the source asset instead of a normal Prefab. Components can be added and removed from this GameObject as normal. However, you cannot apply any changes to the asset itself since this would add data to the asset file itself! If you're creating something you want to re-use, you should make the asset instance into a Prefab following the steps listed above under "Creating Prefabs".

资产是在场景里作为一个GameObject实例,连接到源资产而不是一个正常的预制品。组件可以正常的从一个GameObject被添加和移除。然而,你不能应用任何改变到资产它本身因为这将添加数据到资产文件本身。如果要创建的东西想重复使用,你应该使资成为一个预制品,跟随在“创建预制品”栏目下列出的步骤。

  • When you have selected an instance of an asset, the Apply button in the Inspector is replaced with an Edit button. Clicking this button will launch the editing application for your asset (e.g. Maya or Max).

当以已经选取了一个资产实例,在检视器里的Apply(应用)按钮被替换为一个Edit(编辑)按钮。点击这个按钮将启动你的资产编辑应用程序(例如 Maya 或MAX)。

<12>
发表评论0条 】
网友评论(共?条评论)..
Unity3D基础教程2-3:预制品(Prefabs)