Last active
August 10, 2020 10:33
-
-
Save pinkas/573094477bff0bc8763c826e0b6eee36 to your computer and use it in GitHub Desktop.
Make sense of the RecTransform in edit mode! (without changing the inspector to debug mode)
This file contains 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
using UnityEngine; | |
[ExecuteInEditMode] | |
public class RectTransformExplained : MonoBehaviour | |
{ | |
RectTransform rt; | |
[Header("Anchored position")] | |
[SerializeField] Vector2 anchorePosition; | |
[Header("Anchor max/min")] | |
[SerializeField] Vector2 anchorMax; | |
[SerializeField] Vector2 anchorMin; | |
[Header("Offset max/min")] | |
[SerializeField] Vector2 offsetMax; | |
[SerializeField] Vector2 offsetMin; | |
[Header("Size delta")] | |
[SerializeField] Vector2 sizeDelta; | |
[Header("Rect")] | |
[SerializeField] Vector2 rect_position; | |
[SerializeField] Vector2 rect_center; | |
[SerializeField] Vector2 rect_size; | |
[SerializeField] Vector2 rect_max; | |
[SerializeField] Vector2 rect_min; | |
[Header("Relative Bounds")] | |
[SerializeField] Transform relativeTransformUsedForBounds; | |
[SerializeField] Bounds bounds; | |
void Start () | |
{ | |
rt = GetComponent<RectTransform>(); | |
} | |
void Update () | |
{ | |
anchorePosition = rt.anchoredPosition; | |
offsetMax = rt.offsetMax; | |
offsetMin = rt.offsetMin; | |
anchorMax = rt.anchorMax; | |
anchorMin = rt.anchorMin; | |
sizeDelta = rt.sizeDelta; | |
rect_position = rt.rect.position; | |
rect_center = rt.rect.center; | |
rect_max = rt.rect.max; | |
rect_min = rt.rect.max; | |
Transform relativeUsedforBounds = relativeTransformUsedForBounds != null ? relativeTransformUsedForBounds : transform.parent; | |
bounds = RectTransformUtility.CalculateRelativeRectTransformBounds(relativeUsedforBounds, transform); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment