NGUI 解決UILable 默認在頂滿第一行時,在起始位置如鍵入空格無效,其緣由就是會加入換行符,使字符串,總體換行了ide
解決辦法加入bool變量控制函數
1在 UILable代碼中添加spa
[HideInInspector][SerializeField] public bool wrapText = true;
2 在該函數中 void ProcessText (bool legacyMode, bool full)code
對方法blog
// Wrap the text rem
bool fits = NGUIText.WrapText(mText, out mProcessedText, true, wrapText);添加參數字符串
3 在NGUIText源碼中相應函數添加參數源碼
static public bool WrapText (string text, out string finalText) { return WrapText(text, out finalText, false); }
static public bool WrapText (string text, out string finalText, bool keepCharCount, bool needWrap = true)
// Doesn't fit? if (Mathf.RoundToInt(remainingWidth) < 0) { // Can't start a new line 在此處添加判斷 !needWrap 來阻止建立新行,就解決問題了 if ( !needWrap || lineIsEmpty || lineCount == maxLineCount) { // This is the first word on the line -- add it up to the character that fits sb.Append(text.Substring(start, Mathf.Max(0, offset - start))); bool space = IsSpace(ch); if (!space && !eastern) fits = false; if (lineCount++ == maxLineCount) { start = offset; break; } if (keepCharCount) ReplaceSpaceWithNewline(ref sb); else EndLine(ref sb); // Start a brand-new line lineIsEmpty = true; if (space) { start = offset + 1; remainingWidth = regionWidth; } else { start = offset; remainingWidth = regionWidth - glyphWidth; } prev = 0; } else { // Revert the position to the beginning of the word and reset the line lineIsEmpty = true; remainingWidth = regionWidth; offset = start - 1; prev = 0; if (lineCount++ == maxLineCount) break; if (keepCharCount) ReplaceSpaceWithNewline(ref sb); else EndLine(ref sb); continue; }