• 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;
                    }
  • 相关阅读:
    比较重量(网易笔试题)
    抽象工厂模式
    简单工厂模式
    R语言dai xie
    Hadoop综合大作业
    hive基本操作与应用
    用mapreduce 处理气象数据集
    熟悉常用的HBase操作,编写MapReduce作业
    爬虫大作业
    第三章 熟悉常用的HDFS操作
  • 原文地址:https://www.cnblogs.com/lihonglin2016/p/6640924.html
Copyright © 2020-2023  润新知