✍️ 개요
📌 UI SetActive 최적화 방법
/// Bad Case (총 3회의 dirty 플래그 처리)
Image img = GetComponent<Image>();
img.gameObject.SetActive(true); //dirty 플래그 처리
img.fillAmount = 1f; //dirty 플래그 처리
img.transform.position = Vector3.zero; //dirty 플래그 처리
/// Good Case (총 1회의 dirty 플래그 처리)
Image img = GetComponent<Image>();
img.fillAmount = 1f;
img.transform.position = Vector3.zero;
img.gameObject.SetActive(true); //dirty 플래그 처리
최적화 방법 : Active가 켜지기 전에 데이터 처리를 모두 처리합니다.
UI 요소를 수정하면 LayoutRebuilder.MarkLayoutForRebuild 함수가 호출되면서 부모 계층 구조를 탐색합니다.
이때, GetComponents 연산을 사용하면서 배치 또는 레이아웃 업데이트를 체크하기 때문에 성능에 좋지 않습니다.
따라서 효율적으로 dirty 처리를 위해 UI 요소를 모두 설정한 후 SetActive(true)을 호출하는 것이 효율적입니다.
'유니티(Unity) > 최적화 기법' 카테고리의 다른 글
[Unity 최적화] 오디오(사운드) 최적화 (0) | 2024.12.16 |
---|---|
[Unity 최적화] UGUI 최적화 (0) | 2024.12.12 |
[Unity 최적화] UI 시스템 설계 (0) | 2024.12.11 |