UGUI RectTransformUtility
RectTransformUtility:
public static Bounds CalculateRelativeRectTransformBounds (Transform root, Transform child);
public static Bounds CalculateRelativeRectTransformBounds (Transform trans) ;
计算包围盒
// 计算 child 在 target 的局部坐标系的包围盒
RectTransformUtility.CalculateRelativeRectTransformBounds(target, child);
// 计算 child 在自身坐标系的包围盒
RectTransformUtility.CalculateRelativeRectTransformBounds(child);
public static bool ScreenPointToLocalPointInRectangle (RectTransform rect, Vector2 screenPoint, Camera cam, out Vector2 localPoint);
// Canvas.RenderMode 为 Screen Space - Overlap 时,rectTransform.position 指的是屏幕坐标
Vector2 screenPoint = rectTransform.position;
// 计算 screenPoint 在 target 的局部坐标
RectTransformUtility.ScreenPointToLocalPointInRectangle(target, screenPoint, null, out Vector2 localPoint);