Unity/Unity 리서치

중첩된 LayoutView가 제대로 작동하지 않을 때

lipnus 2023. 7. 8. 19:15
반응형

 

LabelGroup과 

하위의 BranchLabel, TagLabel에 모두 HorizontailLayoutView가 있음

 

하위의 LayoutView가 업데이트 내역이 상위 LayoutView에 제때에 적용이 안되서 문제인듯?

 

 

 

Solution (야매)

상위 Layout Group의 Control Child Size 체크하니까 된다

 

 

Solution (덜 야매)

👹원인

출처: https://github.com/nhn/gpm.unity/issues/165

 

 

😀해결

ContentSizeFilter는 자손 컨텐츠의 크기에 따라 자동으로 LayoutView의 크기를 맞춰주는 역할을 하는 컴포넌트.

ContentSizeFilter를 임의로 Refresh시킴.

 

중첩된 경우, 하위 콘텐츠 크기에 따라 자동으로 Refresh가 안됨

 

    [SerializeField] private ContentSizeFitter sizeFitter;
    
    
   
    private void RefreshContentSize()
    {
        System.Collections.IEnumerator Routine()
        {
            sizeFitter.verticalFit = ContentSizeFitter.FitMode.Unconstrained;
            yield return null;
            sizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
        }
        StartCoroutine(Routine());
    }

 

 

 

https://discussions.unity.com/t/ui-how-to-force-content-size-fitter-update-after-instantiating-a-prefab/192475

 

[UI] How to force Content Size Fitter Update after instantiating a prefab?

Hi everyone, I have a quite complexe interface with scroll rect and everything. All is ok BUT, when i instantiate a prefab in a parent which contains a content size fitter component, the size is not update until i enable/disable the game object in the edit

discussions.unity.com

여기보면 LayoutView의 Spacing값을 약간 변화시켜서 바꾸는 방법도 있다.

반응형