You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I already sent you the code (via assetstore.unity.com) of small component which formats text in correct multi line and also does that in Editor to speed up the execution time. However, it also supports formatting from code. I did it with regular Text component but I believe there will be no big difference for TextMashPro
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using ArabicSupport;
using System.Linq;
[RequireComponent(typeof(Text))]
[ExecuteInEditMode]
public class ArabicLineFixer : MonoBehaviour {
[TextArea]
public string ArabicText;
public void SetArabicText(string text) {
this.ArabicText = text;
StartCoroutine(FixLineOrderCoroutine());
}
void OnValidate() {
StartCoroutine(FixLineOrderCoroutine());
}
IEnumerator FixLineOrderCoroutine() {
Text textComponent = this.GetComponent<Text>();
List<string> resultText = new List<string>();
RectTransform rt = textComponent.GetComponent<RectTransform>();
List<string> paragraphList = ArabicText.Split('\n').ToList();
foreach (string paragraph in paragraphList) {
textComponent.text = ArabicFixer.Fix(paragraph, false, false);
TextGenerationSettings tgs = textComponent.GetGenerationSettings(rt.rect.size);
if (textComponent.text.IndexOf(' ') < 0) {
resultText.Add(textComponent.text);
} else {
List<string> lineList = new List<string>();
List<string> wordList = textComponent.text.Split(' ').ToList();
string singleLine = "";
while (wordList.Count > 0) {
string singleWord = wordList[wordList.Count - 1];
wordList.RemoveAt(wordList.Count - 1);
if (textComponent.cachedTextGenerator.GetPreferredWidth(singleWord + ' ' + singleLine, tgs) > rt.rect.width) {
lineList.Add(singleLine);
singleLine = singleWord;
} else {
singleLine = (singleLine != "") ? singleWord + ' ' + singleLine : singleWord;
}
}
if (singleLine.Length > 0)
lineList.Add(singleLine);
resultText.Add(String.Join(Environment.NewLine, lineList.ToArray()));
}
if (!Application.isEditor)
yield return new WaitForEndOfFrame();
}
textComponent.text = String.Join(Environment.NewLine, resultText.ToArray());
}
}
The text was updated successfully, but these errors were encountered:
I already sent you the code (via assetstore.unity.com) of small component which formats text in correct multi line and also does that in Editor to speed up the execution time. However, it also supports formatting from code. I did it with regular Text component but I believe there will be no big difference for TextMashPro
The text was updated successfully, but these errors were encountered: