Tanoda
switchToRectTransform.cs
Go to the documentation of this file.
1
4
6{
7 public static class RectTransformExtension
8 {
13 public static Vector2 switchToRectTransform(this RectTransform from, RectTransform to)
14 {
15 Vector2 localPoint;
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;
22 }
23 }
24}
Credit Erdener Gonenc - @PixelEnvision.