Exemplo n.º 1
0
    bool ParseFenXianLocation(string str, int index)
    {
        Match match = s_RegexFenxianLocation.Match(str);

        if (match != Match.Empty)
        {
            var    mapName   = match.Groups[1].Value;
            var    fenxianID = match.Groups[2].Value;
            var    posX      = match.Groups[3].Value;
            var    posY      = match.Groups[4].Value;
            string strLink   = "";
            if (posX == "0" && posY == "0")
            {
                strLink = string.Format("[{0}]", mapName);
                Scene scene = getSceneByName(mapName);
                if (scene == null)
                {
                    return(false);
                }

                posX = Mathf.RoundToInt(scene.bornpos.x * 2).ToString();
                posY = Mathf.RoundToInt(scene.bornpos.y * 2).ToString();
            }
            else
            {
                strLink = string.Format("[{0}{1}线<{2},{3}>]", mapName, fenxianID, posX, posY);
            }
            string           strData = string.Format("fenxianLocation,{0},{1},{2},{3}", mapName, fenxianID, posX, posY);
            LRichElementText element = new LRichElementText(linkTextColor, strLink, normalFontSize, true, false, strData);
            elementDic.Add(index, element);
            return(true);
        }

        return(false);
    }
Exemplo n.º 2
0
    void PraseLink(string str)
    {
        foreach (Match match in s_RegexLink.Matches(str))
        {
            var value = match.Groups[1].Value;
            if (value == "")
            {
                continue;
            }

            string sourceStr = string.Format("[{0}]", value);
            int    index     = match.Index;

            //解析换行
            if (PraseNewLine(sourceStr, index))
            {
                continue;
            }
            //解析物品链接
            else if (PraseItem(sourceStr, index))
            {
                continue;
            }
            //解析彩色字符
            else if (ParseColorText(sourceStr, index))
            {
                continue;
            }
            ////解析图片
            else if (ParseImage(sourceStr, index))
            {
                continue;
            }
            //解析表情
            else if (ParseEmote(sourceStr, index))
            {
                continue;
            }
            //解析坐标
            else if (ParseFenXianLocation(sourceStr, index))
            {
                continue;
            }
            //解析坐标
            else if (ParseLocation(sourceStr, index))
            {
                continue;
            }
            else
            {
                LRichElementText element = new LRichElementText(normalTextColor, sourceStr, normalFontSize, false, false, "");
                elementDic.Add(index, element);
            }
        }
    }
Exemplo n.º 3
0
 void PraseNormalText(string str, Regex reg)
 {
     foreach (Match match in reg.Matches(str))
     {
         var value = match.Groups[1].Value;
         if (value == "")
         {
             continue;
         }
         LRichElementText element = new LRichElementText(normalTextColor, value, normalFontSize, false, false, "");
         elementDic.Add(match.Index, element);
     }
 }
Exemplo n.º 4
0
    void ParseTail(string str)
    {
        Match match = s_RegexTail.Match(str);

        if (match != Match.Empty)
        {
            var value = match.Groups[1].Value;
            if (value == "" || value.Contains("["))
            {
                return;
            }

            LRichElementText element = new LRichElementText(normalTextColor, value, normalFontSize, false, false, "");
            elementDic.Add(match.Index, element);
        }
    }
Exemplo n.º 5
0
    bool ParseColorText(string str, int index)
    {
        Match match = s_RegexString.Match(str);

        if (match != Match.Empty)
        {
            var r    = Mathf.Clamp(int.Parse(match.Groups[1].Value), 0, 255);
            var g    = Mathf.Clamp(int.Parse(match.Groups[2].Value), 0, 255);
            var b    = Mathf.Clamp(int.Parse(match.Groups[3].Value), 0, 255);
            var text = string.Format("{0}", match.Groups[4].Value);

            Color textColor = new Color((float)r / 255, (float)g / 255, (float)b / 255);

            LRichElementText element = new LRichElementText(textColor, text, normalFontSize, false, false, "");
            elementDic.Add(index, element);
            return(true);
        }

        return(false);
    }
Exemplo n.º 6
0
    bool PraseItem(string str, int index)
    {
        Match match = s_RegexItem.Match(str);

        if (match != Match.Empty)
        {
            var    name      = match.Groups[1].Value;
            var    data      = match.Groups[2].Value;
            int    quality   = System.Convert.ToInt32(match.Groups[3].Value);
            string strItem   = string.Format("[{0}]", name);
            string strData   = data;
            Color  itemColor = Color.white;
            if (quality < itemTextColor.Length)
            {
                itemColor = itemTextColor[quality];
            }
            LRichElementText element = new LRichElementText(itemColor, strItem, normalFontSize, false, false, strData);
            elementDic.Add(index, element);

            return(true);
        }

        return(false);
    }
Exemplo n.º 7
0
    //public LRichText(InputType inputType):this()
    //{
    //    this.inputType = inputType;
    //}

    //===================================================================
    //解析内部结构并生成相关GameObject的方法
    //===================================================================
    //将_richElements中的单个元素拆解为每个字符一个元素,这个时候是一字排开的状态
    //_elemRenderArr中存放的所有元素的list
    void reloadData()
    {
        this.removeAllElements();

        RectTransform rtran = this.GetComponent <RectTransform>();

        //align
        if (alignType == RichAlignType.DESIGN_CENTER)
        {
            rtran.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f);
        }
        else if (alignType == RichAlignType.LEFT_TOP)
        {
            rtran.GetComponent <RectTransform>().pivot = new Vector2(0f, 1f);
        }

        foreach (LRichElement elem in _richElements)
        {
            if (elem.type == RichType.TEXT)
            {
                LRichElementText elemText = elem as LRichElementText;
                char[]           _charArr = elemText.txt.ToCharArray();
                TextGenerator    gen      = new TextGenerator();

                foreach (char strChar in _charArr)
                {
                    LRenderElement rendElem = new LRenderElement();
                    rendElem.type        = RichType.TEXT;
                    rendElem.strChar     = strChar.ToString();
                    rendElem.isOutLine   = elemText.isOutLine;
                    rendElem.isUnderLine = elemText.isUnderLine;
                    rendElem.font        = this.font;
                    rendElem.fontSize    = elemText.fontSize;
                    rendElem.data        = elemText.data;
                    rendElem.color       = elemText.color;

                    TextGenerationSettings setting = new TextGenerationSettings();
                    setting.font               = this.font;
                    setting.fontSize           = elemText.fontSize;
                    setting.lineSpacing        = 1;
                    setting.scaleFactor        = 1;
                    setting.verticalOverflow   = VerticalWrapMode.Overflow;
                    setting.horizontalOverflow = HorizontalWrapMode.Overflow;

                    rendElem.width  = (int)gen.GetPreferredWidth(rendElem.strChar, setting);
                    rendElem.height = (int)gen.GetPreferredHeight(rendElem.strChar, setting);
                    _elemRenderArr.Add(rendElem);
                }
            }
            else if (elem.type == RichType.IMAGE)
            {
                LRichElementImage elemImg  = elem as LRichElementImage;
                LRenderElement    rendElem = new LRenderElement();
                rendElem.type = RichType.IMAGE;
                rendElem.path = elemImg.path;
                rendElem.data = elemImg.data;
                //从配置直接传进来,不用再读取图片大小了
                //Sprite sp = Resources.LoadAssetAtPath(AppConst.RawResPath + rendElem.path, typeof(Sprite)) as Sprite;
                rendElem.width  = elemImg.width;
                rendElem.height = elemImg.height;
                _elemRenderArr.Add(rendElem);
            }
            else if (elem.type == RichType.ANIM)
            {
                LRichElementAnim elemAnim = elem as LRichElementAnim;
                LRenderElement   rendElem = new LRenderElement();
                rendElem.type       = RichType.ANIM;
                rendElem.path       = elemAnim.path;
                rendElem.data       = elemAnim.data;
                rendElem.frameCount = elemAnim.frameCount;
                rendElem.fs         = elemAnim.fs;
                //Sprite sp = Resources.LoadAssetAtPath(AppConst.RawResPath + rendElem.path + "/1", typeof(Sprite)) as Sprite;
                rendElem.width  = elemAnim.width;
                rendElem.height = elemAnim.height;
                _elemRenderArr.Add(rendElem);
            }
            else if (elem.type == RichType.NEWLINE)
            {
                LRenderElement rendElem = new LRenderElement();
                rendElem.isNewLine = true;
                _elemRenderArr.Add(rendElem);
            }
        }

        _richElements.Clear();

        formarRenderers();
    }