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;
                    }
  • 相关阅读:
    HTTP压力测试工具apache的ab的使用方法
    [转]Memcached 协议中英文对照
    [转]Windows下删除.svn文件夹的最简易方法
    [转]50 个便利的 Web 设计工具
    Navicat数据存放位置和备份数据库路径设置
    Silverlight第三方控件
    MVC3.0中使用JQuery.DataTable插件。
    什么是句柄?为什么会有句柄?HANDLE
    WPF内存释放
    ArcGis for wpf 符号渲染
  • 原文地址:https://www.cnblogs.com/lihonglin2016/p/6640924.html
Copyright © 2011-2022 走看看