层次结构和继承
Properties in UNIGINE can form a hierarchy. However, there are certain rules and constraints described below, that must be taken into account.UNIGINE中的属性可以形成层次结构。但是,必须考虑以下某些规则和约束。
Properties Hierarchy属性层次结构#
Properties hierarchy is formed by inheriting one property from another. A parent property passes all its parameters to its children so that they can be overridden, much like in object-oriented programming.属性层次结构是通过从另一个属性继承一个属性而形成的。父属性将其所有参数传递给其子对象,以便可以覆盖它们,就像在面向对象的编程中一样。
At the top of the hierarchy there are base properties. Unigine provides 2 built-in read-only base properties: node_base and surface_base. You can also make custom base properties of your own.在层次结构的顶部,有 基本属性 。 Unigine提供了2内置的只读基本属性:node_base和surface_base。您还可以创建自己的自定义基本属性。
It is also recommended to inherit properties that will be assigned to nodes from the node_base property. However, you can also assign any custom base property or its children to a node.如果需要将属性分配给单个表面,建议从 surface_base 属性继承。
建议从node_base属性继承将分配给节点的属性。 但是,您也可以将任何自定义基本属性或其子级分配给节点。
Base properties cannot have a parent: no base property can be inherited from another base property. The values of parameters of manual properties (including base ones) cannot be changed. So, to modify parameters of a manual property via the UnigineEditor, you should inherit a user property from it. 基础属性不能具有父级:不能从其他基础属性继承基础属性。 手动属性 (包括基本属性)的参数值无法更改。因此,要通过UnigineEditor修改手动属性的参数,您应该从中继承 用户属性 。
The parent of a user property can be changed by dragging it to a new parent in the Properties Hierarchy window.可以通过将用户属性的父级拖动到Properties Hierarchy窗口中的新父级来进行更改。
Taking all abovementioned into account, there are the following reasons to create properties hierarchy:考虑到上述所有因素,创建属性层次结构的原因如下:
- Inheriting from a base property allows editing its parameters via the UnigineEditor.从基本属性继承可以通过UnigineEditor编辑其参数。
- Inheriting from a user property allows for mass controlling values of multiple property parameters.从用户属性继承可以批量控制多个属性参数的值。
Properties Loading Order属性加载顺序#
Properties hierarchy doesn't affect the loading order of properties.属性层次结构不会影响属性的加载顺序。
Referring to Properties by GUIDs通过GUID引用属性#
A GUID (Globally Unique Identifier) is an identifier for a property. It represents a 40-character hexadecimal string generated using the SHA-1 hash algorithm. GUID (全局唯一标识符)是属性的标识符。它表示使用SHA-1哈希算法生成的40个字符的十六进制字符串。
Properties hierarchy is based on GUIDs: all properties are referred to using GUIDs, even base and manual ones (the GUIDs for such properties are generated at run time and are uniquely determined by their names). However, only user properties store their GUIDs explicitly: a GUID is generated automatically on user property creation and is written to the corresponding *.prop file.属性层次结构基于GUID:所有属性都使用GUID引用,甚至 base 和 manual 都一样(此类属性的GUID在运行时生成,并由他们的名字)。但是,只有用户属性会明确存储其GUID:在用户属性创建时会自动生成一个GUID,并将其写入相应的*.prop文件。
For example:例如:
<property version="2.13.0.1" name="surface_base_0" guid="2750c68c5a8d5e01198c9a32ba6ffaa46ae31b8c" parent="d99ebc8ef5769d70b1e46992309cc3e7d1aa2faa"/>
The GUID of a user property is stored in the guid attribute. If user property is inherited from another user property, it will refer to the parent by its GUID (see the parent attribute in the example above).用户属性的GUID存储在guid属性中。如果用户属性是从另一个用户属性继承的,则它将通过其GUID引用父级(请参见上面示例中的parent属性)。
Using GUIDs makes it difficult to edit user properties manually. For example, to rename such property, it is required to generate a GUID for the new name and replace the current GUID.使用GUID使手动编辑用户属性变得困难。例如,要重命名该属性,需要为新名称生成一个GUID并替换当前的GUID。
As GUIDs for manual properties (including base ones) are uniquely determined by their names, changing the name of such property will also change its GUID. That is why manual properties cannot be renamed at run time. For the same reason, *.prop files of such properties store only their names, not GUIDs. Manual properties usually use name-based references to other manual properties (including base ones).因为手动属性(包括基本属性)的GUID由它们的名称唯一地确定,所以更改此类属性的名称也会更改其GUID。这就是为什么无法在运行时重命名手动属性的原因。出于相同的原因,具有此类属性的*.prop文件仅存储其名称,而不存储GUID。手动属性通常使用基于名称的引用其他手动属性(包括基本属性)。
Types of Inheritance继承类型#
As it was mentioned above, base properties, which are all manual, are always at the top of the hierarchy, while other properties are inherited from them. You can inherit:如上所述,基本属性都是手动的,始终位于层次结构的顶部,而其他属性是从它们继承的。您可以继承:
- a new user property from any other property via the UnigineEditor. 通过UnigineEditor从任何其他属性创建新的用户属性。
- a new manual property from another manual property (including base one) by creating a new *.prop file with a name-based reference to the parent.通过创建一个新的 *.prop文件并使用基于父项的基于名称的引用来从另一个手动属性(包括基础属性)创建一个新的手动属性。
So, basically we can have the following types of inheritance:因此,基本上,我们可以具有以下类型的继承:
- Manual Parent - Manual Child父级人工-子级人工
- Manual Parent - User Child手动父级-用户子级
- User Parent - User Child用户父母-使用孩子
Thus, depending on the type of inheritance, the *.prop file of a child property will store a reference to its parent as follows:因此,根据继承的类型,子属性的*.prop文件将存储对其父项的引用,如下所示:
- Parent: manual property (including base ones).
- If the inherited property is also manual, the corresponding *.prop file stores the name of the property, and the name of its parent in the parent_name attribute.
Only manual properties can refer to their parent manual property by name.Only manual properties can refer to their parent manual property by name.Only manual properties can refer to their parent manual property by name.If the inherited property is also manual, the corresponding *.prop file stores the name of the property, and the name of its parent in the parent_name attribute.
<property version="2.13.0.1" name="my_node_base1" parent_name="node_base" manual="1"/>
Only manual properties can refer to their parent manual property by name.Only manual properties can refer to their parent manual property by name.<property version="2.13.0.1" name="my_node_base1" parent_name="node_base" manual="1"/>
- If the inherited property is not manual (i.e it is a user property), the corresponding *.prop file stores a GUID of the user property, and the GUID of its parent (generated at run time from the parent's name) in the parent attribute.
If the inherited property is not manual (i.e it is a user property), the corresponding *.prop file stores a GUID of the user property, and the GUID of its parent (generated at run time from the parent's name) in the parent attribute.
<property version="2.13.0.1" name="my_node_base2" guid="cccd50e4431ddaeaf01dcb394fc988def578b380" parent="d99ebc8ef5769d70b1e46992309cc3e7d1aa2faa"/>
<property version="2.13.0.1" name="my_node_base2" guid="cccd50e4431ddaeaf01dcb394fc988def578b380" parent="d99ebc8ef5769d70b1e46992309cc3e7d1aa2faa"/>
Only manual properties can refer to their parent manual property by name.Only manual properties can refer to their parent manual property by name.Only manual properties can refer to their parent manual property by name.If the inherited property is not manual (i.e it is a user property), the corresponding *.prop file stores a GUID of the user property, and the GUID of its parent (generated at run time from the parent's name) in the parent attribute.<property version="2.13.0.1" name="my_node_base1" parent_name="node_base" manual="1"/>
父级: 手动属性(包括基本属性)。<property version="2.13.0.1" name="my_node_base2" guid="cccd50e4431ddaeaf01dcb394fc988def578b380" parent="d99ebc8ef5769d70b1e46992309cc3e7d1aa2faa"/>
- If the inherited property is also manual, the corresponding *.prop file stores the name of the property, and the name of its parent in the parent_name attribute.
Only manual properties can refer to their parent manual property by name.Only manual properties can refer to their parent manual property by name.Only manual properties can refer to their parent manual property by name.如果继承的属性也是手动属性,则相应的*.prop文件将属性的名称及其父项的名称存储在parent_name属性中。
<property version="2.13.0.1" name="my_node_base1" parent_name="node_base" manual="1"/>
Only manual properties can refer to their parent manual property by name.只有手册属性可以按名称引用其父级手册属性。<property version="2.13.0.1" name="my_node_base1" parent_name="node_base" manual="1"/>
- If the inherited property is not manual (i.e it is a user property), the corresponding *.prop file stores a GUID of the user property, and the GUID of its parent (generated at run time from the parent's name) in the parent attribute.
如果继承的属性不是手动属性(即它是用户属性),则对应的*.prop文件将用户属性的GUID和其父项的GUID(在运行时根据父项的名称生成)存储在parent属性中。
<property version="2.13.0.1" name="my_node_base2" guid="cccd50e4431ddaeaf01dcb394fc988def578b380" parent="d99ebc8ef5769d70b1e46992309cc3e7d1aa2faa"/>
<property version="2.13.0.1" name="my_node_base2" guid="cccd50e4431ddaeaf01dcb394fc988def578b380" parent="d99ebc8ef5769d70b1e46992309cc3e7d1aa2faa"/>
- If the inherited property is also manual, the corresponding *.prop file stores the name of the property, and the name of its parent in the parent_name attribute.
- Parent: user property. The *.prop file of the inherited user property stores a GUID of the user property, and the GUID of its parent in the parent attribute.
父级:用户属性。继承的用户属性的*.prop文件在parent属性中存储用户属性的GUID及其父项的GUID。
<property version="2.13.0.1" name="my_node_base3" guid="cd3ebc8ef5769d70b1e46452309cc3e7d1aa2ccd" parent="cccd50e4431ddaeaf01dcb394fc988def578b380"/>
<property version="2.13.0.1" name="my_node_base3" guid="cd3ebc8ef5769d70b1e46452309cc3e7d1aa2ccd" parent="cccd50e4431ddaeaf01dcb394fc988def578b380"/>