"Unity_api Analysis" 12th Chapter transform Class

Source: Internet
Author: User
Tags instance method

The transform class inherits from the component class and implements the Ienumberable interface. Transform is a component that gameobject must have to manage the coordinate position, rotation angle, and size scaling of Gameobject objects. Since the transform implements the Ienumberable interface, it is possible to use the foreach () method in the program to quickly traverse the transform structure of the sub-object. That

 void Start ()     {        foreach (Transform item in Transform)       &NB Sp {        }   } transform class Instance Properties Eulerangles properties: Euler angle public Vector3 eulerangles{get ; Set;} This feature is used to return and set the Euler angle of the Gameobject object.  forward properties: Z-axis unit vector public Vector3 forward{get; set;} This property is used to return or set the unit vector in the world coordinate system corresponding to the unit vector of the z-axis in the transform's own coordinate system, Transform.forward is Transform.transformdirection (new Vector3 ( 0.0f, 0.0f, 0.0f) are simplified.  haschanged Property: Transform Whether the component is modified public bool haschanged{get; set;} This property is used to determine whether this property of the transform component has been modified since the Gameobject object last set this property to False, and the default value is true.  localposition Property: Local coordinate system is value public Vector3 localposition{get; set;} This property is used to set or return the position of the Gameobject object in the local coordinate system, and if no parent object is the same as the property Transform.positon. The value of the transform.localposition is affected by the parent object Lossyscale.  localtoworldmatrix Property: Conversion matrix public matrix4x4 Localtoworldmatrix{get;} This property is used to return the matrix4x4 matrix converted from the transofrm local coordinate system to the world coordinate system. The example set a is vector3,b as the transform instance, and the x, Y, Z axis direction of B is consistent with the world coordinate system. Vector3 vec3 = b.localtoworldmatrix.multiplypoint3x4 (A), the component value vec3.x = b.position.x + a.x * b.lossyscale.x. In general, Transformpoint (POSITON:VECTOR3) can be used to convert Vector3 instances from a transform local coordinate system to a world coordinate system.  parent Property: Parent Object Transform Instance public Transform parent{get; set;} This property is used to return the transform instance of the parent object. To return the topmost parent of transform, you can use the Transform.root property.  worldtolocalmatrix Property: Conversion matrix public matrix4x4 Worldtolocalmatrix{get;} This property is used to return the matrix4x4 matrix in which the object is converted from the world coordinate system to the transform self coordinate system. Methods Inversetransformpoint (POSITION:VECTOR3) are generally available to enable Vector3 instances to transform from the world coordinate system to the transform own coordinate system.  transform class Instance method Detachchildren method: Separate object hierarchy relationship public void Detachchidren (); The function of this method is to separate the hierarchical relationship between all the child objects of the Gameobject object and itself.  getchild method: Gets the Gameobject object subclass public Transform getchild (int index), and the parameter is the index value of the sub-object. This method is used to return an index value of transform to the subclass Transfrom instance of index. The value of the parameter index is less than the value of the childcount of transform.  inversetransformdirection method: Coordinate system conversion public Vector3 Inversetransformdirection (Vector3 direction);p ublic Vector3 Inversetransformdirection (float x, float y, float z); This method is used to convert the parameter direction from the world coordinate system to the local coordinate system of the Gameobject object.  inversetransfrompoint method: The relative coordinate vector of points public Vector3 Inversetransformpoint (Vector3 position);p ublic  vector3 inversetransformpoint (float x, float y, float z); This method is used to return the difference vector of the parameter position vector relative to the Gameobject object's local coordinate system, and the return value is affected by Transform.lossyscale and transform.rotation.  ischildof method: Is the child object public bool Ischildof (Transform parent), and the parameter parent is the Transform instance of the parent object. This method is used to determine if the transform corresponding Gameobject object is a child of the parent parameter.  lookat method: Object toward public void LookAt (Transform target);p ublic void LookAt (Vector3 worldposition);p ublic void LookAt ( Transform target, Vector3 worldup);  public void LookAt (Vector3 worldposition, Vector3 worldup); Where the parameter target is the target of transform's own coordinate system, the parameter worldup is the direction that the Y axis in transform's own coordinate system points to the maximum. The function of this method is to point the z axis of the Gameobject object to target, and if you customize the direction of the Worldup, the ForWord direction of the Gameobject object always points to target. The transform then rotates around the z-axis of its coordinate system, which is forward direction, to a place where the y-axis of the direction closest to Worldup is made.  rotate method: Rotates public void Rotate (Vector3 eulerangles) around an axis or a vector;p ublic void Rotate (Vector3 eulerangles, Space relativeto);p ublic void Rotate (float xangle, float yangle, float zangle);p ublic void Rotate (float xangle, float yangle, FL Oat Zangle, space RelATiveto);p ublic void Rotate (Vector3 axis, float angle);p ublic void Rotate (Vector3 axis, float angle, Space relativeto); The first four overloads are to enable the transform instance to rotate the Euler angle eulerangles in the coordinate system of the relative parameter relativeto, and the latter two overloads to enable the Gameobject object to rotate relativeto degrees around the axis vector axis in the angle coordinate system. , Rotatearound method: Rotates the public void Rotatearound (Vector3 axis, float angle) around the pivot point;p ublic void Rotatearound (Vector3 points, Vector3 axis, float angle); where the parameter point is the reference coordinate, the axis is the axis of rotation and the parameter angle is the rotation angle.  transfromdirection method: Coordinate system conversion public Vector3 Transformdirection (Vector3 direction);p ublic Vector3 Transformdirection (float x, float y, float z); This method is used to convert a vector direction from a transform local coordinate system to a world coordinate system.  transformpoint method: Point World coordinates location public Vector3 transformpoint (Vector3 position);p ublic Vector3 transformpoint (float x , float y, float z); This method returns the position of position in the world coordinate system in the local coordinate system of the Gameobject object.  translate method: Move the relative coordinate system or move the public void Translate (Vector3 translation);p ublic void Translate (VECTOR3) relative to other objects Translation, Space relativeto);p ublic void Translate (float x, float y, float z);p ublic void Translate (float x, floAt Y, float z, space relativeto);p ublic void Translate (Vector3 translation, Transform relativeto);p ublic void transl Ate (float x, float y, float z,  transform relativeto);  The first four overloads of this method enable the Gameobject object to move the specified vector in the coordinate system space of the relativeto, translation The function of the latter two overloads is to enable the Gameobject object to move the vector translation in a relative relativeto coordinate system.   Notes on Localscale and Lossyscale: When Gameobject object A is the parent of the Gameobject object B, the size of the parent object A is reduced by the scale of X, Y, and Z, which should be kept in proportion to 1:1:1. Otherwise, when the rotation value of sub-object B is not 1:1:1, the B object will deform. The Gameobject object A is a parent of B, and when the 1:1:1 of each component of a object is maintained, the Lossyscale return value of sub-object B is the indent value of the B object relative to the world coordinate system, the relationship is B.localscale = b.lossyscale/ A.localscale.  

Unity_api resolution 12th transform class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.