本文整理汇总了C#中UIFont.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# UIFont.GetLength方法的具体用法?C# UIFont.GetLength怎么用?C# UIFont.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIFont
的用法示例。
在下文中一共展示了UIFont.GetLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WrapString
public static string WrapString(string text, UIFont uiFont, float wrapLength, int size){
sb.Length = 0; //Clear does not exist in .net2.0, so we set length to 0
float currentLength = 0;
int lastStart = 0;
int lastSpace = -1;
bool isHTML = false;
//We iterate over all characters in the string
for (int i = 0; i< text.Length; i++){
char currentChar = text[i];
bool forceBreak = false;
bool terminate = false;
//This allows the formatting to accept newline characters in the input text
if(currentChar == HTMLStart){
isHTML = true;
}
if(currentChar == HTMLEnd){
isHTML = false;
}
if(isHTML){
// currentLength remains the same
}
else{
if(currentChar == NewLine){
lastSpace = i;
forceBreak = true;
}
else{
//If we arent already flagged for a new line, keep track of the most recent space character
if(currentChar == Space){
lastSpace = i;
}
currentLength += size*uiFont.GetLength(currentChar);
}
}
//if we've reached the end, we need to write remaining text without a break
if (i==text.Length-1){
lastSpace = i;
terminate = true;
}
//If we have exceeded the length, or forced a line break
if( (currentLength > wrapLength) || forceBreak || terminate){
//We only add the 1 if the last character isn't a space or newline
int count;
if(currentChar == Space || currentChar == NewLine){
count = lastSpace - lastStart;
}
else{
count = lastSpace - lastStart+1;
}
if(count < 1){
// Debug.LogError("wrap failed" + count);
//currentLength = 0;
}
else{ //break a line - can we justify it here?
sb.Append(text, lastStart, count);
if(!terminate){
sb.Append(NewLine);
}
//reset position to next character after lastSpace
i = lastSpace +1;
lastStart = i;
currentLength = 0;
}
}
}
return sb.ToString();
}