Skip to content

Common.Transform

DucNV_2000 edited this page Jul 10, 2024 · 1 revision

Common.Transform

  • ClearTransform Clear all child game object of transform
    // API
    Transform ClearTransform(this Transform transform)

Example

    public GameObject container;
    public void ClearContainer()
    {
        container.transform.ClearTransform();
        // or
        Common.ClearTransform(container.transform);
    }
  • ToWorldPosition Convert UI position to world position
    // API
    Vector2 ToWorldPosition(this RectTransform transform, Camera camera = null)

Note: if camera is null, then camera is equal to main camera (Camera.main)

Example

      public RectTransform rect;
      public Camera camera;
      
      Vector2 GetPos()
      {
          return rect.ToWorldPosition(camera);
          // or return Common.ToWorldPosition(rect, camera);
      }
  • SetPositionX Set position x, y or z
    // API
    void SetPositionX(this Transform transform, float x)
    void SetPositionY(this Transform transform, float y)
    void SetPositionZ(this Transform transform, float z)

Example

    public Transform trans;

    public void SetPositionX()
    {
        trans.SetPositionX(1.2f);
        // or
        Common.SetPositionX(trans, 1.2f);
    }
  • SetPositionXY Set position x and y
    // API
    void SetPositionXY(this Transform transform, in Vector2 v2)
    void SetPositionXY(this Transform transform, float x, float y)
    void SetPositionXY(this Transform transform, Transform target)
  • Similar to SetPositionXY, there is also SetPositionYZ and SetPositionXZ

Example

        public Transform trans;
        public Vector2 v2;
        public Transform transTarget;

        public void SetPositionXY()
        {
            trans.SetPositionXY(1.2f, 3.1f);
            trans.SetPositionXY(v2);
            trans.SetPositionXY(transTarget);
        }
  • SetRelativePositionX Add an amount to the x coordinate (Similar api for y and z coordinates)
    // API
    void SetRelativePositionX(this Transform transform, float x)
    void SetRelativePositionY(this Transform transform, float y)
    void SetRelativePositionZ(this Transform transform, float z)

Example

        public Transform trans;

        /// <summary>
        /// Suppose: trans.position.x: 1
        /// After SetRelativePositionX: 1 + 1.2f = 2.2f
        /// </summary>
        public void SetPosition()
        {
            trans.SetRelativePositionX(1.2f);
        }
  • SetRelativePositionXY Add an amount to the x and y coordinate
    // API
    void SetRelativePositionXY(this Transform transform, in Vector2 v2)
    void SetRelativePositionXY(this Transform transform, float x, float y)
    void SetRelativePositionXY(this Transform transform, Transform target)
  • Similar to SetRelativePositionXY, there is also SetRelativePositionXZ and SetRelativePositionYZ

Example

        public Transform trans;
        public Vector2 v2;
        public Transform transTarget;

        public void SetPosition()
        {
            trans.SetRelativePositionXY(1.2f, 3.1f);
            trans.SetRelativePositionXY(v2);
            trans.SetRelativePositionXY(transTarget);
        }
  • SetLocalPositionX Set local position x , y or z coordinate
    // API
    void SetLocalPositionX(this Transform transform, float x)
    void SetLocalPositionY(this Transform transform, float y)
    void SetLocalPositionZ(this Transform transform, float z)

Example

        public Transform trans;

        public void SetPosition()
        {
            trans.SetLocalPositionX(1.2f);
            // or
            Common.SetLocalPositionX(trans, 1.2f)
        }
  • SetLocalPositionXY, SetLocalPositionXZ, SetLocalPositionYZ Set local position for x and y coordinate
    // API
     void SetLocalPositionXY(this Transform transform, in Vector2 v2)
     void SetLocalPositionXY(this Transform transform, float x, float y)
     void SetLocalPositionXY(this Transform transform, Transform target)

     void SetLocalPositionXZ(this Transform transform, in Vector2 v2)
     void SetLocalPositionXZ(this Transform transform, float x, float z)
     void SetLocalPositionXZ(this Transform transform, Transform target)
    
     void SetLocalPositionYZ(this Transform transform, in Vector2 v2)
     void SetLocalPositionYZ(this Transform transform, float y, float z)
     void SetLocalPositionYZ(this Transform transform, Transform target)
  • SetRelativeLocalPositionX, SetRelativeLocalPositionY, SetRelativeLocalPositionZ Add an amount to the x, y or z local coordinate
    //API
     void SetRelativeLocalPositionX(this Transform transform, float x)
     void SetRelativeLocalPositionY(this Transform transform, float y)
     void SetRelativeLocalPositionZ(this Transform transform, float z)
  • SetRelativeLocalPositionXY Add an amount to x and y local coordinate
  • Similar to SetRelativeLocalPositionXY, there is also SetRelativeLocalPositionXZ and SetRelativeLocalPositionYZ
    // API
     void SetRelativeLocalPositionXY(this Transform transform, in Vector2 v2)
     void SetRelativeLocalPositionXY(this Transform transform, float x, float y)
     void SetRelativeLocalPositionXY(this Transform transform, Transform target)
    
     void SetRelativeLocalPositionXZ(this Transform transform, in Vector2 v2)
     void SetRelativeLocalPositionXZ(this Transform transform, float x, float z)
     void SetRelativeLocalPositionXZ(this Transform transform, Transform target)
    
     void SetRelativeLocalPositionYZ(this Transform transform, in Vector2 v2)
     void SetRelativeLocalPositionYZ(this Transform transform, float y, float z)
     void SetRelativeLocalPositionYZ(this Transform transform, Transform target)
  • SetScaleX Set scale x, y or z
    // API
     void SetScaleX(this Transform transform, float x)
     void SetScaleY(this Transform transform, float y)
     void SetScaleZ(this Transform transform, float z)
  • SetScaleXY, SetScaleXZ, SetScaleYZ Set scale x and y, x and z, y and z
    // API
     void SetScaleXY(this Transform transform, in Vector2 v2)
     void SetScaleXY(this Transform transform, float x, float y)
     void SetScaleXY(this Transform transform, float value) // scale x and y are the same value
     void SetScaleXY(this Transform transform, Transform target)
    
     void SetScaleXZ(this Transform transform, in Vector2 v2)
     void SetScaleXZ(this Transform transform, float x, float z)
     void SetScaleXZ(this Transform transform, float value)
     void SetScaleXZ(this Transform transform, Transform target)
    
     void SetScaleYZ(this Transform transform, in Vector2 v2)
     void SetScaleYZ(this Transform transform, float y, float z)
     void SetScaleYZ(this Transform transform, float value)
     void SetScaleYZ(this Transform transform, Transform target)
  • SetScale Set the x, y, and z scales to the same value
    // API
    static void SetScale(this Transform transform, float value)
  • SetRelativeScaleX, SetRelativeScaleY, SetRelativeScaleZ Add an amount to x, y or z scale
    // API
     void SetRelativeScaleX(this Transform transform, float x)
     void SetRelativeScaleY(this Transform transform, float y)
     void SetRelativeScaleZ(this Transform transform, float z)
  • SetRelativeScaleXY, SetRelativeScaleXZ , SetRelativeScaleYZ Add an amount to (x,y), (x,z) or (y,z) scale
    /// API
     void SetRelativeScaleXY(this Transform transform, in Vector2 v2)
     void SetRelativeScaleXY(this Transform transform, float x, float y)
     void SetRelativeScaleXY(this Transform transform, float value) // (x = x + value, y = y + value)
     void SetRelativeScaleXY(this Transform transform, Transform target)
    
     void SetRelativeScaleXZ(this Transform transform, in Vector2 v2)
     void SetRelativeScaleXZ(this Transform transform, float x, float z)
     void SetRelativeScaleXZ(this Transform transform, float value)
     void SetRelativeScaleXZ(this Transform transform, Transform target)
    
     void SetRelativeScaleYZ(this Transform transform, in Vector2 v2)
     void SetRelativeScaleYZ(this Transform transform, float y, float z)
     void SetRelativeScaleYZ(this Transform transform, float value)
     void SetRelativeScaleYZ(this Transform transform, Transform target)
   
  • SetRelativeScale Add an amount equal to value to x, y and z
    /// API
     void SetRelativeScale(this Transform transform, float value)
  • SetRotationX, SetRotationY and SetRotationZ Set eulerAngles x, y or z
    /// API
     void SetRotationX(this Transform transform, float x)
    
     void SetRotationY(this Transform transform, float y)
    
     void SetRotationZ(this Transform transform, float z)
  • SetRotationXY, SetRotationXZ and SetRotationYZ Set eulerAngles (x,y), (x,z) or (y, z)
    /// API
    void SetRotationXY(this Transform transform, in Vector2 v2)
    void SetRotationXY(this Transform transform, float x, float y)
    void SetRotationXY(this Transform transform, Transform target)
    
    void SetRotationXZ(this Transform transform, in Vector2 v2)
    void SetRotationXZ(this Transform transform, float x, float z)
    void SetRotationXZ(this Transform transform, Transform target)
    
    void SetRotationYZ(this Transform transform, in Vector2 v2)
    void SetRotationYZ(this Transform transform, float y, float z)
    void SetRotationYZ(this Transform transform, Transform target)
  • SetRelativeRotationX, SetRelativeRotationY and SetRelativeRotationZ Add an amount to x, y or z eulerAngles
    /// API
    void SetRelativeRotationX(this Transform transform, float x)
    
    void SetRelativeRotationY(this Transform transform, float y)
    
    void SetRelativeRotationZ(this Transform transform, float z)
  • SetRelativeRotationXY, SetRelativeRotationXZ, SetRelativeRotationYZ Add a amount to (x,y), (x,z) or (y, z) eulerAngles
    /// API
    void SetRelativeRotationXY(this Transform transform, in Vector2 v2)
    void SetRelativeRotationXY(this Transform transform, float x, float y)
    void SetRelativeRotationXY(this Transform transform, Transform target)
    
    void SetRelativeRotationXZ(this Transform transform, in Vector2 v2)
    void SetRelativeRotationXZ(this Transform transform, float x, float z)
    void SetRelativeRotationXZ(this Transform transform, Transform target)
    
    void SetRelativeRotationYZ(this Transform transform, in Vector2 v2)
    void SetRelativeRotationYZ(this Transform transform, float y, float z)
    void SetRelativeRotationYZ(this Transform transform, Transform target)
  • SetLocalRotationX, SetLocalRotationY and SetLocalRotationZ Set localEulerAngles x, y or z
    /// API
    void SetLocalRotationX(this Transform transform, float x)
    
    void SetLocalRotationY(this Transform transform, float y)
    
    void SetLocalRotationZ(this Transform transform, float z)
  • SetLocalRotationXY, SetLocalRotationXZ and SetLocalRotationYZ Set localEulerAngles (x, y), (x, z) or (y, z)
    /// API
    void SetLocalRotationXY(this Transform transform, in Vector2 v2)
    void SetLocalRotationXY(this Transform transform, float x, float y)
    void SetLocalRotationXY(this Transform transform, Transform target)
    
    void SetLocalRotationXZ(this Transform transform, in Vector2 v2)
    void SetLocalRotationXZ(this Transform transform, float x, float z)
    void SetLocalRotationXZ(this Transform transform, Transform target)
    
    void SetLocalRotationYZ(this Transform transform, in Vector2 v2)
    void SetLocalRotationYZ(this Transform transform, float y, float z)
    void SetLocalRotationYZ(this Transform transform, Transform target)
  • SetRelativeLocalRotationX, SetRelativeLocalRotationY and SetRelativeLocalRotationZ Add an amount x, y or z localEulerAngles
    /// API
    void SetRelativeLocalRotationX(this Transform transform, float x)
    
    void SetRelativeLocalRotationY(this Transform transform, float y)
    
    void SetRelativeLocalRotationZ(this Transform transform, float z)
  • SetRelativeLocalRotationXY, SetRelativeLocalRotationXZ and SetRelativeLocalRotationYZ Add an amount (x, y), (x, z) or (y, z) localEulerAngles
    /// API
    void SetRelativeLocalRotationXY(this Transform transform, in Vector2 v2)
    void SetRelativeLocalRotationXY(this Transform transform, float x, float y)
    void SetRelativeLocalRotationXY(this Transform transform, Transform target)
    
    void SetRelativeLocalRotationXZ(this Transform transform, in Vector2 v2)
    void SetRelativeLocalRotationXZ(this Transform transform, float x, float z)
    void SetRelativeLocalRotationXZ(this Transform transform, Transform target)
    
    void SetRelativeLocalRotationYZ(this Transform transform, in Vector2 v2)
    void SetRelativeLocalRotationYZ(this Transform transform, float y, float z)
    void SetRelativeLocalRotationYZ(this Transform transform, Transform target)
  • SetAnchoredPositionX, SetAnchoredPositionY and SetAnchoredPositionZ Set anchoredPosition x, y or z
    /// API
    void SetAnchoredPositionX(this RectTransform rectTransform, float x)
    
    void SetAnchoredPositionY(this RectTransform rectTransform, float y)
    
    void SetAnchoredPositionZ(this RectTransform rectTransform, float z)
  • SetRelativeAnchoredPositionX, SetRelativeAnchoredPositionY and SetRelativeAnchoredPositionZ Add an amount x, y or z anchoredPosition
    /// API
    void SetRelativeAnchoredPositionX(this RectTransform rectTransform, float x)
    
    void SetRelativeAnchoredPositionY(this RectTransform rectTransform, float y)
    
    void SetRelativeAnchoredPositionZ(this RectTransform rectTransform, float z)
Clone this wiki locally