FairyGUI.Image.Rebuild C# (CSharp) Method

Rebuild() protected method

protected Rebuild ( ) : void
return void
        protected virtual void Rebuild()
        {
            _requireUpdateMesh = false;
            if (_texture == null)
            {
                graphics.ClearMesh();
                return;
            }

            Rect uvRect = _texture.uvRect;
            if (_flip != FlipType.None)
                ToolSet.FlipRect(ref uvRect, _flip);

            if (_fillMethod != FillMethod.None)
            {
                graphics.Fill(_fillMethod, _fillAmount, _fillOrigin, _fillClockwise, _contentRect, uvRect);
                graphics.FillColors(_color);
                graphics.FillTriangles();
                graphics.UpdateMesh();
            }
            else if (_texture.width == _contentRect.width && _texture.height == _contentRect.height)
            {
                graphics.SetOneQuadMesh(_contentRect, uvRect, _color);
            }
            else if (_scaleByTile)
            {
                //如果纹理是repeat模式,而且单独占满一张纹理,那么可以用repeat的模式优化显示
                if (_texture.nativeTexture.wrapMode == TextureWrapMode.Repeat
                    && uvRect.x == 0 && uvRect.y == 0 && uvRect.width == 1 && uvRect.height == 1)
                {
                    uvRect.width *= _contentRect.width / _texture.width;
                    uvRect.height *= _contentRect.height / _texture.height;
                    graphics.SetOneQuadMesh(_contentRect, uvRect, _color);
                }
                else
                {
                    TileFill(_contentRect, uvRect, _texture.width, _texture.height, -1);
                    graphics.FillColors(_color);
                    graphics.FillTriangles();
                    graphics.UpdateMesh();
                }
            }
            else if (_scale9Grid != null)
            {
                Rect gridRect = (Rect)_scale9Grid;

                if (_flip != FlipType.None)
                    ToolSet.FlipInnerRect(_texture.width, _texture.height, ref gridRect, _flip);

                GenerateGrids(gridRect, uvRect);

                if (_tileGridIndice == 0)
                {
                    graphics.Alloc(16);

                    int k = 0;
                    for (int cy = 0; cy < 4; cy++)
                    {
                        for (int cx = 0; cx < 4; cx++)
                        {
                            graphics.uv[k] = new Vector2(gridTexX[cx], gridTexY[cy]);
                            graphics.vertices[k] = new Vector2(gridX[cx], -gridY[cy]);
                            k++;
                        }
                    }
                    graphics.FillTriangles(NGraphics.TRIANGLES_9_GRID);
                }
                else
                {
                    int hc, vc;
                    Rect drawRect;
                    Rect texRect;
                    int row, col;
                    int part;

                    //先计算需要的顶点数量
                    int vertCount = 0;
                    for (int pi = 0; pi < 9; pi++)
                    {
                        col = pi % 3;
                        row = pi / 3;
                        part = gridTileIndice[pi];

                        if (part != -1 && (_tileGridIndice & (1 << part)) != 0)
                        {
                            if (part == 0 || part == 1 || part == 4)
                                hc = Mathf.CeilToInt((gridX[col + 1] - gridX[col]) / gridRect.width);
                            else
                                hc = 1;
                            if (part == 2 || part == 3 || part == 4)
                                vc = Mathf.CeilToInt((gridY[row + 1] - gridY[row]) / gridRect.height);
                            else
                                vc = 1;
                            vertCount += hc * vc * 4;
                        }
                        else
                            vertCount += 4;
                    }

                    graphics.Alloc(vertCount);

                    int k = 0;

                    for (int pi = 0; pi < 9; pi++)
                    {
                        col = pi % 3;
                        row = pi / 3;
                        part = gridTileIndice[pi];
                        drawRect = Rect.MinMaxRect(gridX[col], gridY[row], gridX[col + 1], gridY[row + 1]);
                        texRect = Rect.MinMaxRect(gridTexX[col], gridTexY[row + 1], gridTexX[col + 1], gridTexY[row]);

                        if (part != -1 && (_tileGridIndice & (1 << part)) != 0)
                        {
                            k = TileFill(drawRect, texRect,
                                (part == 0 || part == 1 || part == 4) ? gridRect.width : drawRect.width,
                                (part == 2 || part == 3 || part == 4) ? gridRect.height : drawRect.height,
                                k);
                        }
                        else
                        {
                            graphics.FillVerts(k, drawRect);
                            graphics.FillUV(k, texRect);
                            k += 4;
                        }
                    }

                    graphics.FillTriangles();
                }

                graphics.FillColors(_color);
                graphics.UpdateMesh();
            }
            else
            {
                graphics.SetOneQuadMesh(_contentRect, uvRect, _color);
            }
        }