이 페이지에서는 시각적 트리에서 요소를 관리하는 베스트 프랙티스에 대해 설명합니다.
요소를 생성하고 계층 구조에 로드하는 작업은 속도가 느립니다.이를 방지하려면 계층 구조에 요소를 미리 생성하고 display:none
을 사용하여 요소를 숨기고 필요할 때만 표시할 수 있습니다.그러나 동시에 많은 요소를 만들면 메모리를 더 많이 사용할 수 있습니다.
요소 풀링은 매번 new()
로 요소를 생성한 후 놓아두는 대신 나중에 다시 생성할 수 있는 요소를 보관하는 것입니다.
풀에 보관하는 모든 요소를 완전히 통제하고 풀에 반환하기 전에 올바르게 재설정했는지 확인하는 것이 중요합니다.그렇지 않으면 풀링 시스템이 불안정해지고 문제가 발생할 수 있습니다.예를 들어 이벤트 콜백을 등록하거나 내부 직렬화되지 않은 상태를 동시에 설정하면서 요소를 풀링하면 요소를 정리하는 것이 불가능합니다.
시각적 요소의 수를 적게 유지하려면 가능하면 ListView를 사용하십시오.ListView는 요소를 풀링하고 사용자가 스크롤할 때 요소를 재활용합니다.
또는 ListView와 유사한 자체 풀 및 재활용 메커니즘을 구현하고 다음을 사용하여 표시되는 영역을 관리할 수 있습니다.
GeometryChangedEvent
를 사용하십시오.VisualElement.layout
프로퍼티를 사용하십시오.Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.