2014-08-08 17:58:11|?次阅读|上传:huigezrx【已有?条评论】发表评论
关键词:Unity3D, 游戏, 虚拟现实|来源:唯设编程网
Unity Manual > User Guide > Building Scenes > Prefabs
用户手册->用户指南->建立场景->预制品
A Prefab is a type of asset -- a reusable GameObject stored in Project View. Prefabs can be inserted into any number of scenes, multiple times per scene. When you add a Prefab to a scene, you create an instance of it. All Prefab instances are linked to the original Prefab and are essentially clones of it. No matter how many instances exist in your project, when you make any changes to the Prefab you will see the change applied to all instances.
预制品是一个资产的类型—一个存储在项目视图(面板)里可以重复使用的GameObject(游戏物体)。预制品可以被插入任何数量的场景、每个场景多次。当你添加以讹预制品到一个场景,你创建一个预制品的实例。所有的预制品实例被连接到原始的预制品,本质上是它自己的复制品(克隆)。不管如何许多实例存在于你的项目里,当你做任何更改到预制品你将看到更改被应用于所有的实例。
Creating Prefabs 创建预制品
In order to create a Prefab, you must make a new blank Prefab using the menu. This blank Prefab contains no GameObjects, and you cannot create an instance of it. Think of a new Prefab as an empty container, waiting to be filled with GameObject data.
为了创建一个预制品,你必须使用菜单件建一个新的空白预制品。这个空的预制品不包含GameObject(游戏物体),你也不能创建一个它的实例。把一个新的预制品作想象为一个空的容器,等待被用GameObject数据填充。
A new, empty Prefab. It cannot be instanced until you fill it with a GameObject.
一个新的空预制品,它不能被实例化直到你用一个GameObject填充它
To fill the Prefab, you use a GameObject that you've created in the scene.
去填充这个预制品,你使用一个你已经在场景里创建的GameObject。
从菜单条选择Assets->Create->Prefab并命名你新的预制品。
在层次视图(面板)里,选取你希望去制成一个预制品的GameObject
从层次拖放这个GameObject 到在项目视图里的那个新的预制品上。
After you have performed these steps, the GameObject and all its children have been copied into the Prefab data. The Prefab can now be re-used in multiple instances. The original
你处理完这些步骤之后,GameObject以及所有它的子已经被复制到预制品的数据里。预制品现在可以被重复使用在多个实例里。在层次里的原始GameObject现在已经变成预制品的一个实例。
Prefab Instances 预制品实例
GameObject in the Hierarchy has now become an instance of the Prefab.
To create a Prefab instance in the current scene, drag the Prefab from the Project View into the Scene or Hierarchy View. This instance is linked to the Prefab, as displayed by the blue text used for their name in the Project View.
在当前场景创建一个预制品实例,从项目视图里拖动预制品到场景里或层次视图里。这个实例被连接到预制品,在项目视图里它们的名称用蓝色文本显示。
Three of these GameObjects are linked to Prefabs. One of them is not. GameObjects中的三个连接到预制品,有一个没有连接。
Inheritance 继承
Inheritance means that whenever the source Prefab changes, those changes are applied to all linked GameObjects. For example, if you add a new script to a Prefab, all of the linked GameObjects will instantly contain the script as well. However, it is possible to change the properties of a single instance while keeping the link intact. Simply change any property of a prefab instance, and watch as the variable name becomes bold. The variable is now overridden. All overridden properties will not be affected by changes in the source Prefab.
集成意味着只要源预制品改变,这些改变都适用于所有连接的GameObject。例如,如果你添加一个新的脚本到预制品,所有连接的GameObject将也立即包含脚本。然而,它是有可能改变一个单一实例的属性,同时保持原有的连接。简单改变任意的一个预制品实例的属性,变量名称变为粗体显示。这个变量现在是覆盖。所有覆盖的变量将不受更改影响在源预制品里。