示例#1
0
        private static void UF_HandleToken(List <TextToken> tokens, List <ULineData> listULineDatas, float sizeScale)
        {
            listULineDatas.Clear();
            int overlying = 0;

            for (int k = 0; k < tokens.Count; k++)
            {
                if (tokens [k].type == TextTokenType.HEAD_U)
                {
                    overlying++;
                    for (int i = k + 1; i < tokens.Count; i++)
                    {
                        if (tokens [i].type == TextTokenType.HEAD_U)
                        {
                            overlying++;
                        }
                        else if (tokens [i].type == TextTokenType.END_U)
                        {
                            overlying--;
                            if (overlying == 0)
                            {
                                ULineData uline = new ULineData();
                                uline.idx    = tokens [k].index;
                                uline.length = tokens [i].index - tokens [k].index;
                                //样式
                                int idxSize = tokens[k].buffer.IndexOf("u=");
                                if (idxSize > -1)
                                {
                                    uline.size = RichText.UF_ReadFloat(tokens [k].buffer, idxSize + 2, 1) * sizeScale;
                                }
                                else
                                {
                                    uline.size = 1 * sizeScale;
                                }

                                int idxOff = tokens[k].buffer.IndexOf("o=");
                                if (idxOff > -1)
                                {
                                    uline.offset = RichText.UF_ReadFloat(tokens [k].buffer, idxOff + 2, 0);
                                }

                                int idxType = tokens[k].buffer.IndexOf("t=");
                                if (idxType > -1)
                                {
                                    uline.type = RichText.UF_ReadInt(tokens [k].buffer, idxType + 2, 1);
                                }
                                else
                                {
                                    uline.type = 0;
                                }

                                int idxCOff = tokens[k].buffer.IndexOf("#");
                                if (idxCOff > -1)
                                {
                                    uline.color    = RichText.UF_ReadColor(tokens [k].buffer, idxCOff + 1);
                                    uline.useColor = true;
                                }
                                listULineDatas.Add(uline);
                                //嵌套类型只有最外层有效
                                k = i;
                                break;
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        private static void UF_HandleMesh(List <UIVertex> uivertexs, List <ULineData> listULineDatas, int startIndex)
        {
            if (uivertexs.Count == 0 || listULineDatas.Count == 0)
            {
                return;
            }

            Vector2 uvPoint = Vector2.zero;

            uvPoint.x = (CharacterInfoBlock.uvBottomLeft.x + CharacterInfoBlock.uvTopRight.x) * 0.5f;

            uvPoint.y = (CharacterInfoBlock.uvBottomLeft.y + CharacterInfoBlock.uvTopRight.y) * 0.5f;

            int charCount = uivertexs.Count / 6;

            for (int k = 0; k < listULineDatas.Count; k++)
            {
                ULineData ulinfo = listULineDatas [k];

                int len = ulinfo.length;

                if (ulinfo.idx + ulinfo.length > charCount)
                {
                    len = charCount - ulinfo.idx;
                }

                Vector2 startUp    = uivertexs [ulinfo.idx * 6].position;
                Vector2 lastBottom = uivertexs [ulinfo.idx * 6 + 3].position;
                Color32 vcolor     = uivertexs [ulinfo.idx * 6].color;

                if (ulinfo.useColor)
                {
                    byte sa = vcolor.a;
                    vcolor   = ulinfo.color;
                    vcolor.a = (byte)((sa * vcolor.a) / 255);
                }

                for (int j = startIndex; j < len; j++)
                {
                    int     idx  = (ulinfo.idx + j) * 6;
                    Vector2 pmin = uivertexs [idx].position;
                    Vector2 pmax = uivertexs [idx + 3].position;

                    if (Mathf.Abs(lastBottom.y - pmax.y) < ZOOM_UNDER_LINE)
                    {
                        lastBottom = pmax;
                    }
                    else
                    {
                        //分段
                        UF_AddUnderLineToVertex(
                            startUp,
                            lastBottom,
                            uivertexs,
                            vcolor,
                            uvPoint,
                            ulinfo.offset,
                            UF_GetLROffset(ulinfo.type, Mathf.Abs(startUp.y - lastBottom.y)),
                            ulinfo.size);
                        startUp    = pmin;
                        lastBottom = pmax;
                    }
                }

                UF_AddUnderLineToVertex(
                    startUp,
                    lastBottom,
                    uivertexs,
                    vcolor,
                    uvPoint,
                    ulinfo.offset,
                    UF_GetLROffset(ulinfo.type, Mathf.Abs(startUp.y - lastBottom.y)),
                    ulinfo.size);
            }
        }