Created
October 23, 2023 11:06
-
-
Save WhiteOlivierus/f029ab0857b1a537ddcc2d1bb579c0e3 to your computer and use it in GitHub Desktop.
RectTransformExtensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RectTransformData | |
| { | |
| public Vector3 LocalPosition { get; set; } | |
| public Vector3 LocalScale { get; set; } | |
| public Vector2 SizeDelta { get; set; } | |
| public Vector2 AnchorMin { get; set; } | |
| public Vector2 AnchorMax { get; set; } | |
| public Vector2 AnchoredPosition { get; set; } | |
| public Vector2 Pivot { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class RectTransformExtensions | |
| { | |
| public static RectTransformData CopyRectTransformData(this RectTransform rectTransform) | |
| { | |
| return new RectTransformData | |
| { | |
| LocalPosition = rectTransform.localPosition, | |
| LocalScale = rectTransform.localScale, | |
| SizeDelta = rectTransform.sizeDelta, | |
| AnchorMin = rectTransform.anchorMin, | |
| AnchorMax = rectTransform.anchorMax, | |
| AnchoredPosition = rectTransform.anchoredPosition, | |
| Pivot = rectTransform.pivot | |
| }; | |
| } | |
| public static void ApplyRectTransformData(this RectTransform rectTransform, RectTransformData rectTransformData) | |
| { | |
| if (rectTransformData == null) | |
| { | |
| return; | |
| } | |
| rectTransform.localPosition = rectTransformData.LocalPosition; | |
| rectTransform.localScale = rectTransformData.LocalScale; | |
| rectTransform.sizeDelta = rectTransformData.SizeDelta; | |
| rectTransform.anchorMin = rectTransformData.AnchorMin; | |
| rectTransform.anchorMax = rectTransformData.AnchorMax; | |
| rectTransform.anchoredPosition = rectTransformData.AnchoredPosition; | |
| rectTransform.pivot = rectTransformData.Pivot; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment