NGUI 解决UILable 在空行起始位置加‘\n’

NGUI 解决UILable 默认在顶满第一行时,在起始位置如键入空格无效,其原因就是会加入换行符,使字符串,整体换行了

 

解决办法加入bool变量控制

1在 UILable代码中添加

[HideInInspector][SerializeField] public bool wrapText = true;

 2 在该函数中 void ProcessText (bool legacyMode, bool full)

对方法

 // Wrap the text     

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;
                }

 

转载于:https://www.cnblogs.com/lihonglin2016/p/6640924.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值