zoukankan      html  css  js  c++  java
  • NGUI 解决UILable 在空行起始位置加‘ ’

    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;
                    }
  • 相关阅读:
    Mybatis在oracle批量更新
    WebService小记
    java基本排序
    ant使用
    python 集合
    amazon-aws 使用 SNS 发送短信
    Html5+ 开发APP 后台运行代码
    CentOS7 -防火墙
    java 模拟表单方式提交上传文件
    修改pom项目版本 jenkins 关联 shell命令
  • 原文地址:https://www.cnblogs.com/lihonglin2016/p/6640924.html
Copyright © 2011-2022 走看看