我正在用Unity3d编写一个项目,使用C#脚本,用希伯来语和英语编写字符串。Unity3d的问题是在编写UI文本时不支持RTL语言(如希伯来语)。
问题如下:原文:מערכתהעטלףהינהמערכת,אשרמתבססתעלטכנולוגיתה-探地雷达-ראדארחודרקרקע.
统一: GPR -התיגולונכטלעתססבתמרשא,תכרעמהניהףלטעהתכרעמ.עקרקרדוחראדאר-(探地雷达)
我正试图破解文本被打印到文本框上的顺序,现在已经有一个月了,我无法正确地得到它。我组成了以下功能:
public string CorrectText (string text)
{
string result = "";
string temp = "";
string charListString = "";
List<Char> charList = new List<char> ();
char[] charArray = text.ToCharArray ();
Array.Reverse (charArray);
//go through each char in charArray
for (int x = 0; x <= charArray.Length -1; x++) {
//if the current char we're examing isn't a Space char -
if (!char.IsWhiteSpace (charArray [x])) {
//add it to charList
charList.Add (charArray [x]);
} else { //if the current char we're examing is a Space char -
charListString = new string (charList.ToArray ());
//if charListString doesn't contains English or Numeric chars -
if (!Regex.IsMatch (charListString, "^[0-9a-zA-Z.,()-]*$")) {
//go through each char in charList
for (int y = 0; y <= charList.Count - 1; y++) {
//add the current char to temp as is (not flipped)
temp += charList [y];
}
//add temp to result
if (x < charArray.Length - 1)
result += temp + " ";
if (x == charArray.Length - 1)
result += temp;
//clear charList and temp
charList.Clear ();
temp = "";
} else { //if temp contains English or Numeric chars -
//go through each char in charList - This flipps the order of letters
for (int y = charList.Count - 1; y >= 0; y--) {
//add the current char to temp
temp += charList [y];
}
//add temp to result
if (x < charArray.Length - 1)
result += temp + " ";
if (x == charArray.Length - 1)
result += temp;
//clear charList and temp
charList.Clear ();
temp = "";
}
}
}
return result;
}这几乎解决了问题,但文本是自下而上编写的,例如:
输入:מערכתהעטלףהינהמערכת,אשרמתבססתעלטכנולוגיתה-探地雷达-ראדארחודרקרקע。
输出:(探地雷达)-ראדארחודרקרקע。מערכתהעטלףהינהמערכת,אשרמתבססתעלטכנולוגיתה-探地雷达
有时,括号在句子中被混在一起,表现为:)探地(rad-ראדארחודרקרקע)。
我在网上找到了一个工具,可以将可视化希伯来语转化为逻辑希伯来语,当我复制翻转文本以实现统一时,它就像魔法一样有效!
但我在网上找不到任何有用的信息,说明如何用C#制作自己的脚本。
发布于 2015-12-09 19:55:29
我设法克服了这一切。有点像:
Canvas.ForceUpdateCanvases()更新,或者使用另一种方法。getLines来获取文本包装的信息;它保存每行开始的索引。https://stackoverflow.com/questions/32297691
复制相似问题