본문 바로가기
아때(unity)

Unity Content size fitter 사용 시 sizeDelta 접근하기

by 때려쳐아니때려치지마 2021. 8. 31.
반응형

 

https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-ContentSizeFitter.html

 

Content Size Fitter | Unity UI | 1.0.0

Content Size Fitter Properties Property: Function: Horizontal Fit How the width is controlled.     Unconstrained Do not drive the width based on the layout element.     Min Size Drive the width based on the minimum width of the layout element.   

docs.unity3d.com

layout controller that controls the size of its own layout element.

컨텐츠 사이즈 필터는 해당 컴포넌트가 들어있는 오브젝트의 레이아웃 요소의 사이즈를 제어하는 컨트롤러 입니다.

 

해당 컴포넌트가 들어있는 오브젝트에서

recttransform.sizedelta를 받아오면 0으로 리턴하는 이슈가 있습니다.

 

sizeDelta대신 rect에 접근하여 width를 받아오면됩니다

근데 바로 rect에 업데이트가 안되는 모양인지 직후에 접근하면 0를 리턴합니다

그래서 canvas.ForceUpdateCanvases로 캔버스를 한번 업뎃해주고 사용하면 됩니다.

 

<요약>

Content size fitter 쓸거면 sizeDelta말고 rect로 접근해서 사이즈얻기!

그전에 캔버스업데이트 하기!

 

 

반응형

댓글