DOText에서 \n가 엔터로 처리되지 않을 때
- Unity/UI & TMP
- 2020. 6. 13. 19:57
데이터베이스에서 주고 받을 때 \n 을 엔터로 받아서
바로 Text에 입력해보면 rich Text 덕분에 엔터로 바로 적용된다.
그런데 DOText를 사용하는경우 엔터로 적용되지않고 \n가 그대로 출력되는 현상이 있음.
string targetText = text.Replace("\\n", "\n");
타겟 텍스트를 위와같이 한번 처리해주면 정상출력됨.
나는 아래와 같이 확장 메서드를 만들어서 사용하고있음.
public static string DOTextMy(this TextMeshProUGUI textUGUI, string text, float perCharTime = 0.03f, System.Action endAction = null)
{
string targetText = text.Replace("\\n", "\n");
float duration = CalculateTextLength(targetText) * perCharTime;
textUGUI.DOKill();
textUGUI.text = "";
textUGUI.DOText(targetText, duration).SetUpdate(true).OnComplete(() => endAction?.Invoke());
return targetText;
}
'Unity > UI & TMP' 카테고리의 다른 글
Unity UI ScrollView snap to item (유니티 스크롤뷰 아이템 스냅) (0) | 2020.08.31 |
---|---|
TextMeshPro Sprite Asset (1) | 2020.07.06 |
DoText사용 시 RichText의 Length 문제. (0) | 2020.05.21 |
UI Extension - UI LineRenderer (0) | 2020.05.05 |
UI Extension : ScrollSnap / 스냅 스크롤 뷰 (3) | 2020.05.03 |