7 public static class RectTransformExtension
13 public static Vector2 switchToRectTransform(
this RectTransform from, RectTransform to)
16 Vector2 fromPivotDerivedOffset =
new Vector2(from.rect.width * from.pivot.x + from.rect.xMin, from.rect.height * from.pivot.y + from.rect.yMin);
17 Vector2 screenP = RectTransformUtility.WorldToScreenPoint(
null, from.position);
18 screenP += fromPivotDerivedOffset;
19 RectTransformUtility.ScreenPointToLocalPointInRectangle(to, screenP,
null, out localPoint);
20 Vector2 pivotDerivedOffset =
new Vector2(to.rect.width * to.pivot.x + to.rect.xMin, to.rect.height * to.pivot.y + to.rect.yMin);
21 return to.anchoredPosition + localPoint - pivotDerivedOffset;
Credit Erdener Gonenc - @PixelEnvision.