UnityEngine.RectTransformUtility.CalculateRelativeRectTransformBounds C# (CSharp) Method

CalculateRelativeRectTransformBounds() public static method

public static CalculateRelativeRectTransformBounds ( Transform root, Transform child ) : Bounds
root Transform
child Transform
return Bounds
        public static Bounds CalculateRelativeRectTransformBounds(Transform root, Transform child)
        {
            RectTransform[] componentsInChildren = child.GetComponentsInChildren<RectTransform>(false);
            if (componentsInChildren.Length > 0)
            {
                Vector3 rhs = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
                Vector3 vector2 = new Vector3(float.MinValue, float.MinValue, float.MinValue);
                Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix;
                int index = 0;
                int length = componentsInChildren.Length;
                while (index < length)
                {
                    componentsInChildren[index].GetWorldCorners(s_Corners);
                    for (int i = 0; i < 4; i++)
                    {
                        Vector3 lhs = worldToLocalMatrix.MultiplyPoint3x4(s_Corners[i]);
                        rhs = Vector3.Min(lhs, rhs);
                        vector2 = Vector3.Max(lhs, vector2);
                    }
                    index++;
                }
                Bounds bounds = new Bounds(rhs, Vector3.zero);
                bounds.Encapsulate(vector2);
                return bounds;
            }
            return new Bounds(Vector3.zero, Vector3.zero);
        }

Same methods

RectTransformUtility::CalculateRelativeRectTransformBounds ( Transform trans ) : Bounds

Usage Example

コード例 #1
0
 public static Bounds CalculateRelativeRectTransformBounds(Transform trans)
 {
     return(RectTransformUtility.CalculateRelativeRectTransformBounds(trans, trans));
 }