Unity - Rect Transform
Unity의 UI에서 가끔은 필요에 따라 크기나 위치를 여러 가지로 변경해야 할 때가 있다.
자주 사용하지 않지만 어쩌다 사용하려고 보면 까먹어서 다시 검색하게 되는데 이를 정리해 본다.
1. Rect Transform
- 값 읽기
> offsetMin; // Left, Bottom
> offsetMax; // Right, Top
- 값 적용
> GetComponent< RectTransform >().offsetMin = new Vector2(100, 100); // (left, bottom) 적용됨
> GetComponent< RectTransform >().offsetMax = new Vector2(100, 100); // (-right, -top) 적용됨
2. Anchors
- 값 읽기
> anchorMin ; // 2D vector
> anchorMax; // 2D vector
- 값 적용
> GetComponent().anchorMin = new Vector2(0, 0); // 0 ~ 1 float
> GetComponent().anchorMax = new Vector2(1, 1);
3. Pivot
- Anchors와 같은 방식(2D Vector) : GetComponent().pivot;
4. Rotation
- 값 읽기
> rotation; // localRotation // 3D vector
- 값 적용
> GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
5. Scale
- 값 읽기
> localScale; // 3D vector
- 값 적용
> GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
6. Image(Script) Color 변경
- 값 읽기
> color; // vector4
- 값 적용
> GetComponent<Image>().color = new Color(1, 0.5f, 1, 0.5f);
요정도만 정리해도 다양하게 활용할 수 있겠다.