In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Each game object (GameObject), which exists in the game world, has a location, orientation, size and other basic positioning information; it is stored in the Hierarchy panel, but also has a relative relationship with other GameObject, such as father-son relationship, brotherly relationship. Transform is used in Unity to describe and manipulate these properties.
Transform literally means "transform". All GameObject, when it is created, automatically creates such a transformation component, you do not need to create this component manually, and you cannot delete it.
Next, we will explain the main properties and functions of the transformation component one by one.
3.3.1, hierarchy-related attributes and methods
Hierarchical panel
ChildCount: represents how many child nodes are below the current GameObject node
HierarchyCount: represents the number of layers that exist in the interrelated tree structure of the current GameObject.
The interrelated tree structure refers to a tree starting from a top-level GameObject in the Hierarchy panel as the root node. Any GameObject will exist in a tree.
Predictably, the hierarchyCount attribute of any node in this tree structure is the same.
HierarchyCapacity: represents the hierarchical capacity of the current tree. This is the maximum number of nodes that the tree can hold, and the hierarchical capacity obtained by accessing this attribute from any node in the tree is the same.
This parameter grows automatically, that is, when a hierarchical change occurs in the GameObject, if the capacity of the current tree is insufficient, it will be automatically expanded.
It can be inferred that the query results of all nodes in the tree actually come from the attributes of the top-level nodes, and when the hierarchy changes, the Unity only needs to modify this attribute of the top-level nodes.
It is important to note that when the hierarchyCapacity changes frequently, it requires additional memory consumption and performance consumption, which is the same as the memory expansion of the List class. Therefore, a large capacity should be set at the beginning for the root node of a frequently growing tree.
Parent: represents the parent of the current node and returns a Transform object. When this parent is null, it means that you are already the top-level node, that is, the root node in the tree.
Root: gets the root node in the current tree structure.
DetachChildren (): sub-ion node, which means that all the direct child nodes below the current node are separated, making them the root node. If there are n child nodes, n new trees will be generated.
Find (string name): look for child nodes based on the path. Although the parameter here appears as name on the document, it actually represents a path. It can be in the format of "magazine/ammo", that is, you can query multiple levels in the depth direction of the leaf node, find the target Transform and return it. If you can't find it, return empty.
GetChild (int index): returns the immediate child nodes of the current node based on the index index.
GetSiblingIndex (): gets the numbered index of the current node under its parent, that is, the Index in the sibling list.
SetAsFirstSibling (): sets the current node to be the first node in the sibling list.
SetAsLastSibling (): sets the current node to be the last node in the sibling list.
SetSiblingIndex (int index): sets the current node to the index location in its sibling list.
SetParent (Transform parent, bool worldPositionStays): sets the parent of the current node and, if worldPositionStays is set to true, maintains its position, rotation, and scaling in its world coordinates. This modifies its local coordinates, rotation, and scaling information accordingly. (the concepts of world and local coordinates will be covered in subsequent chapters)
3.3.2. Transform related properties and methods
The transformation here refers to the position, rotation (orientation), scaling (size) and other information.
The unit under Unity is meters, for example, if you create a new Cube, then its default size is the size of 1x1x1, then we want to set the Cube to the desired size, just modify the Scale 3D vector parameter under its Trasform, which represents the scaling on the basis of 1x1x1.
Those 3D model objects imported from the outside have a local coordinate system and the size and position of the 3D object relative to the local coordinate system. To change its size, scale accordingly based on the size and position of the object in its imported local coordinate system.
Because a tree represents the existence of many levels, each node has its own scaling, rotation, position and other information. And the transformation state of the child node will change with the change of the transformation state of the parent node, so there is the concept of local coordinates and global coordinates in Unity. The local coordinate refers to the transformation information of its relative direct parent node, while the global coordinate refers to the state result of the current node superimposed by the cumulative transformation of all the parent nodes.
Next, learn more about the properties and methods related to transformations.
Vector3 localPosition: position in local coordinate system
Vector3 position: location in the global coordinate system
Quaternion localRotation: rotation in local coordinate system
Quaternion rotation: rotation in global coordinate system
Vector3 localScale: scaling in local coordinate system
Vector3 lossyScale: scaling in the global coordinate system
Vector3 localEulerAngles: Euler angle in local coordinate system
Euler Angle in Vector3 eulerAngles Global coordinate system
Vector3 forward: front vector in the global coordinate system
Vector3 up: upper vector in the global coordinate system
Vector3 right: the right vector in the global coordinate system
As can be seen from the above attributes, each transformation attribute is divided into local and global. Position and zoom are easier to understand. However, there are two forms of scaling, one is the Euler angle, and the other is the quaternion. In fact, the quaternion is calculated using the Euler angle. Students who are not familiar with this part of mathematics need not be nervous, we do not need to understand the principle of quaternion in detail, just learn to use it. In the following chapters, we will gradually become familiar with some of the use of quaternions, but for Euler angle, we only need to know its concept: Euler angle is a way to represent rotation by a certain degree relative to the Z, X, Y axes. Please remember that it rotates in the order of Z, X, and Y.
Unity documentation says that if you are not familiar with Euler angle, do not use it, quaternions can meet your requirements. In fact, for some simple rotation calculation, using Euler angle is more convenient and faster, for example, we only need an object to rotate around a single axis in X, Y, Z relative to its parent node, at this time the document is relatively simple, we can use Euler angle to deal with, a slightly more complex case, the following quaternion chapter is explained.
There are also a few points to pay attention to:
1. Vector and Quaternion are structures, and the results obtained by the above functions such as localRotation and position all exist in a structure, and the returned results exist in the new memory opened up separately, so the direct modification of them can not affect their original values. We must assign values to them in the form of localRotation=Vector and let them carry out the actual assignment operation in the function.
2. Transform is also a component. Although there is a member of transform in every GameObject class, its internal implementation is still a function call of getComponent, which is time-consuming. Considering the frequent need to operate on Transform, we should get a Transform reference in the initialization process of the script and retain it, so that subsequent calls can avoid frequent use of getComponent. That's what we did in the last section of the code.
This article is the original article of the blogger, welcome to reprint. Please keep the blogger link http://blog.csdn.net/andrewfan
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Vim / HomeZababixUnix SMTP username='m14718177839'. SMTP server server SMT #
© 2024 shulou.com SLNews company. All rights reserved.