DoText사용 시 RichText의 Length 문제.

 

DOText는 아래와 같이 인자를 받는다.

Txt_talk.DOText(string endTargetText, float duration);

 

때문에 사용할 Text의 Length를 사용해서 duration을 결정하곤 하는데, 

문제는 <color="red"> 등과 같이 RichText를 사용할 시에는 보이지않는데 Length에 포함된다는 것.

 

유니티포럼
https://forum.unity.com/threads/rich-text-length.402876/

 

public int TextLength(string richText)
    {
        int len = 0;
        bool inTag = false;
 
        foreach (var ch in richText)
        {
            if (ch == '<')
            {
                inTag = true;
                continue;
            }
            else if (ch == '>')
            {
                inTag = false;
            }
            else if (!inTag)
            {
                len++;
            }
        }
 
        return len;
    }

 

위의 코드로 Length를 구하면 RichText부분을 제외한 길이를 얻을 수 있다.

'Unity > UI & TMP' 카테고리의 다른 글

TextMeshPro Sprite Asset  (1) 2020.07.06
DOText에서 \n가 엔터로 처리되지 않을 때  (0) 2020.06.13
UI Extension - UI LineRenderer  (0) 2020.05.05
UI Extension : ScrollSnap / 스냅 스크롤 뷰  (3) 2020.05.03
UI Unmask  (0) 2020.04.07

댓글

Designed by JB FACTORY