본문 바로가기

Programming/유니티

유니티(Unity) TextmeshproGui 사용시 Recttransfrom 의 크기가 변경되지 않을 때 (content size filter)

sizedelta

자식으로 텍스트를 사용할 때 글자의 크기에 따라서 부모 Recttransform의 sizedelta 크기를 변경해야 할 때가 있습니다. 그러나 원하는 타이밍에 부모의 크기가 자식의 크기에 따라 변하지 않는 경우가 생깁니다. 이럴 때 사용하는 방법을 알아보겠습니다. ( When using text as a child, you may need to change the sizedelta of the parent Recttransform depending on the size of the character. However, there are cases where the size of the parent does not change depending on the size of the child at the desired timing. Let’s find out how to use it in this case. )

목차
1. content size filter
2. textmeshprogui
3. LayoutRebuilder
4. 예외 사항(Exceptions)

----

----

content size filter

textmeshprogui에 content size filter 컴포넌트를 추가해주고 부모 Recttransfrom에도 content size filter를 추가해 줍니다. content size filter의 역할은 이미지나 텍스트의 크기를 자동으로 조절해 주는 컴포넌트입니다. 그러나 자동을 믿고 테스트를 해보지 않으면 낭패를 보는 경우가 생깁니다. ( Add a content size filter component to textmeshprogui and add a content size filter to the parent Recttransfrom. The role of the content size filter is a component that automatically adjusts the size of images or text. However, if you believe in automation and do not test it, you may end up in failure. )

textmeshprogui

특히 텍스트를 표시할 때 갱신이 안되는 경우가 많이 생기는데 이럴 때는 텍스트를 변경해 준 후에 ForceMeshUpdate()를 한번 호출해 주면 텍스트의 크기를 수동으로 갱신시켜 줄 수 있습니다. ( In particular, there are many cases where the size cannot be updated when displaying text. In this case, you can manually update the size of the text by calling ForceMeshUpdate() once after changing the text. )

----

----

LayoutRebuilder

자식 오브젝트인 텍스트의 크기를 변경해도 부모 오브젝트의 크기가 부자연스럽게 변경되는 현상이 발생할 수 있습니다. 약간 덜걱거리며 순간이동하는 현상을 확인 할 수 있습니다. 이럴 때는 부모의 recttransform 역시도 다시 그려주면 됩니다. LayoutRebuilder.ForceRebuildLayoutImmediate(parent.rectransfrom) 을 호출해 주면 부모 오브젝트의 크기도 자연스럽게 변경됩니다. ( Even if you change the size of text, which is a child object, the size of the parent object may change unnaturally. You can see a slight rattling and instantaneous movement. In this case, you can also redraw the parent's recttransform. If you call LayoutRebuilder.ForceRebuildLayoutImmediate(parent.rectransfrom), the size of the parent object will naturally change. )

예외 사항(Exceptions)

자식으로 텍스트를 가지고있는 recttransform A, B 두 개 있고 B가 A의 자식으로 종속되어 있을 경우가 있습니다. B는 A의 크기에 따라 B의 위치가 변경되도록 의도된 것입니다. 이런 경우는 A, B에 속한 텍스트를 ForceMeshUpdate()해주고 A, B를 ForceRebuildLayoutImmediate 해주었을 때 A에 자식으로 달려있는 B의 위치가 어색하게 변경되는 경우가 발생할 수 있습니다. 이럴 경우는 update 함수 안에 LayoutRebuilder.ForceRebuildLayoutImmediate(A) LayoutRebuilder.ForceRebuildLayoutImmediate(B)를 호출해 주면 어색한 이동이 사라지게 됩니다. 퍼포먼스상 그다지 좋지 않은 로직일 수 있지만 별다른 해결책이 보이지 않는다면 나쁘지 않은 방법이라고 생각합니다. ( There are two recttransforms, A and B, that have text as children, and B may be dependent as a child of A. B is intended to change its position depending on the size of A. In this case, when you ForceMeshUpdate() the text belonging to A and B and ForceRebuildLayoutImmediate A and B, the position of B, which is a child of A, may change awkwardly. In this case, if you call LayoutRebuilder.ForceRebuildLayoutImmediate(A) and LayoutRebuilder.ForceRebuildLayoutImmediate(B) in the update function, the awkward movement will disappear. It may not be a very good logic in terms of performance, but I think it is not a bad method if there is no other solution. )

 

Godot(고닷), Scene change, reload etc with Unity

목차 1. 씬 전환 (scene change) 2. 씬 다시 호출 (reload scene) 3. 앱 종료 (app quit) ---- ---- Scene change get_tree().change_scene("res://scene.tscn") [ in Unity ] SceneManager.LoadScene("sceneName"); reload scene get_tree().reload_current_sce

moblieandlife.tistory.com

 

Godot(고닷), error Parent node is busy setting up children (addchild)

call_deferred addchild 는 _ready() 함수가 호출된 후에 호출되어야 한다고 한다. 그러나 _ready() 함수안에서 addchild를 사용하고 싶다면, call_deferred()를 이용하여 addchild를 사용할 수 있다. (It is said that addch

moblieandlife.tistory.com

 

유니티(Unity) 스크롤 아이템의 높이를 텍스트 높이에 따라 변경

들어가기 전 한줄에 여러 요소를 넣을 때 비율을 설정 하는 방법을 미리 확인해도 좋다. 유니티(Unity) 한줄에 여러 오브젝트를 넣고 일정한 비율로 나열하기 UI 작업을 하다보면 제목, 내용, 날짜

moblieandlife.tistory.com

 

유니티(Unity) 한줄에 여러 오브젝트를 넣고 일정한 비율로 나열하기

UI 작업을 하다보면 제목, 내용, 날짜 이런식의 내용을 한줄에 넣어야하는 일이 생긴다. 이때 유용하게 사용 할 수 있는 컴포넌트가 있다. Layout Element 가 그것이다. 제목, 내용, 날짜를 가로로 정

moblieandlife.tistory.com