Ejemplo n.º 1
0
        internal static void Main()
        {
            //// adding element + AutoGrow()
            TList<int> somelist = new TList<int>(2);
            somelist.Add(1);
            somelist.Add(2);
            somelist.Add(3);

            //// removing element by index
            somelist.RemoveAt(1);

            //// inserting element at given position
            somelist.InsertAt(0, 0);

            //// accessing element by index (I feel so sleepy that I dont't see 2)
            for (int i = 0; i < somelist.Count; i++)
            {
                Console.WriteLine(somelist[i]);
            }

            //// finding element by its value
            Console.WriteLine(somelist.Contains(3));

            ////ToString override
            Console.WriteLine(somelist.ToString());

            //// Min and max value
            int minValue = somelist.Min();
            int maxValue = somelist.Max();

            Console.WriteLine("MinValue = {0}\nMaxValue = {1}\n", minValue, maxValue);

            ////Clear list - List is empty & nothing is printed
            somelist.Clear();
            for (int i = 0; i < somelist.Count; i++)
            {
                Console.WriteLine(somelist[i]);
            }
        }
Ejemplo n.º 2
0
    /// <summary>
    /// 绘制模型
    /// </summary>
    /// <param name="toFill"></param>
    protected override void OnPopulateMesh(VertexHelper toFill)
    {
        //base.OnPopulateMesh(toFill);
        if (font == null)
        {
            return;
        }

        // We don't care if we the font Texture changes while we are doing our Update.
        // The end result of cachedTextGenerator will be valid for this instance.
        // Otherwise we can get issues like Case 619238.
        m_DisableFontTextureRebuiltCallback = true;

        Vector2 extents = rectTransform.rect.size;

        var settings = GetGenerationSettings(extents);

        //cachedTextGenerator.Populate(m_OutputText, settings);
        this.cachedTextGenerator.PopulateWithErrors(m_OutputText, settings, base.gameObject);
        Rect inputRect = rectTransform.rect;

        // get the text alignment anchor point for the text in local space
        Vector2 textAnchorPivot = GetTextAnchorPivot(alignment);
        Vector2 refPoint        = Vector2.zero;

        refPoint.x = (textAnchorPivot.x == 1 ? inputRect.xMax : inputRect.xMin);
        refPoint.y = (textAnchorPivot.y == 0 ? inputRect.yMin : inputRect.yMax);

        // Determine fraction of pixel to offset text mesh.
        Vector2 roundingOffset = PixelAdjustPoint(refPoint) - refPoint;

        // Apply the offset to the vertices
        IList <UIVertex> verts         = this.cachedTextGenerator.verts;
        float            unitsPerPixel = 1f / pixelsPerUnit;
        //Last 4 verts are always a new line...
        int vertCount = verts.Count - 4;

        //int vertCount = verts.Count;

        toFill.Clear();

        if (m_spriteAsset != null)
        {
            //清乱码

            /*for (int i = 0; i < m_AnimSpiteTag.Count; i++)
             * {
             *  if(m_AnimSpiteTag[i].Length > 0)
             *  {
             *      //UGUIText不支持<quad/>标签,表现为乱码,我这里将他的uv全设置为0,清除乱码
             *      for (int m = m_AnimSpiteTag[i][0].index * 4; m < m_AnimSpiteTag[i][0].index * 4 + 4; m++)
             *      {
             *          //if (m >= verts.Count) return;
             *          if (m >= verts.Count)
             *          {
             *              //Debug.LogError("verts:" + verts.Count + "_" + m);
             *              return;
             *          }
             *          UIVertex tempVertex = verts[m];
             *          tempVertex.uv0 = Vector2.zero;
             *          verts[m] = tempVertex;
             *      }
             *  }
             * }*/

            //移除错误顶点 截断
            for (int i = 0; i < m_AnimSpiteTag.Count;)
            {
                if (m_AnimSpiteTag[i].Count > 0)
                {
                    //UGUIText不支持<quad/>标签,表现为乱码,我这里将他的uv全设置为0,清除乱码
                    TList <SpriteTagInfor> tempSpriteTag = m_AnimSpiteTag[i];
                    for (int j = 0; j < tempSpriteTag.Count;)
                    {
                        bool isRemove = false;
                        for (int m = tempSpriteTag[j].index * 4; m < tempSpriteTag[j].index * 4 + 4; m++)
                        {
                            //if (m >= verts.Count) return;
                            if (m >= vertCount)
                            {
                                isRemove = true;
                                break;
                            }
                            //if (j == 0)
                            {
                                UIVertex tempVertex = verts[m];
                                tempVertex.uv0 = Vector2.zero;
                                verts[m]       = tempVertex;
                            }
                        }

                        //移除对应错误顶点的数据
                        if (isRemove)
                        {
                            tempSpriteTag.RemoveAt(j);
                        }
                        else
                        {
                            j++;
                        }
                    }
                    if (tempSpriteTag.Count == 0)
                    {
                        m_AnimSpiteTag.RemoveAt(i);
                        mEmojiIndexList.RemoveAt(i);
                        continue;
                    }
                }
                i++;
            }
        }

        //计算标签  计算偏移值后 再计算标签的值
        //  CalcQuadTag(verts);

        if (roundingOffset != Vector2.zero)
        {
            for (int i = 0; i < vertCount; ++i)
            {
                int tempVertsIndex = i & 3;
                m_TempVerts[tempVertsIndex]             = verts[i];
                m_TempVerts[tempVertsIndex].position   *= unitsPerPixel;
                m_TempVerts[tempVertsIndex].position.x += roundingOffset.x;
                m_TempVerts[tempVertsIndex].position.y += roundingOffset.y;
                if (tempVertsIndex == 3)
                {
                    toFill.AddUIVertexQuad(m_TempVerts);
                }
            }
        }
        else
        {
            for (int i = 0; i < vertCount; ++i)
            {
                int tempVertsIndex = i & 3;
                m_TempVerts[tempVertsIndex]           = verts[i];
                m_TempVerts[tempVertsIndex].position *= unitsPerPixel;
                if (tempVertsIndex == 3)
                {
                    toFill.AddUIVertexQuad(m_TempVerts);
                }
            }
        }


        if (m_spriteAsset != null)
        {
            //计算标签 计算偏移值后 再计算标签的值
            List <UIVertex> vertsTemp = new List <UIVertex>();
            for (int i = 0; i < vertCount; i++)
            {
                UIVertex tempVer = new UIVertex();
                toFill.PopulateUIVertex(ref tempVer, i);
                vertsTemp.Add(tempVer);
            }
            CalcQuadTag(vertsTemp);
        }


        m_DisableFontTextureRebuiltCallback = false;

        //绘制图片
        DrawSprite();

        HerfBoxEncapsulate(toFill);
        AddHerfUnderlineQuad(toFill, settings);
    }