Ejemplo n.º 1
0
    void UpdateQuads(bool updateVerts, bool updateUVs, bool updateColor)
    {
        // deduce actual bounds
        float[] xAxis, yAxis;
        byte    nonEmpty = ComputeSegments(out xAxis, out yAxis);

        // deduce full update
        bool fullUpdate = nonEmpty != m_Quads.Length;

        // refresh quad list
        if (fullUpdate == true)
        {
            RefreshQuadList(nonEmpty);
        }

        float originWidth  = m_UVCoords.Width;
        float originHeight = m_UVCoords.Height;

        m_GuiRenderer.UVSpaceToPixelSpace(ref originWidth, ref originHeight);

        float widthMult  = originWidth / m_Size.x;
        float heightMult = originHeight / m_Size.y;

        // udpate quads
        // we are going in bottom-up direction
        // so we need to go from the end of the list
        int quadIdx = 0;

        for (int yIdx = 2; yIdx >= 0; --yIdx)
        {
            float y1 = yAxis[yIdx + 1];
            float y2 = yAxis[yIdx];

            // do not create quads for empty row
            float posY1, posY2;
            ComputeRealValues(2 - yIdx, m_Size.y, y1 * heightMult, y2 * heightMult, out posY1, out posY2);
            if (posY2 - posY1 <= 0.0f)
            {
                continue;
            }

            for (int xIdx = 0; xIdx < 3; ++xIdx)
            {
                float x1 = xAxis[xIdx];
                float x2 = xAxis[xIdx + 1];

                // do not create quads for empty column
                float posX1, posX2;
                ComputeRealValues(xIdx, m_Size.x, x1 * widthMult, x2 * widthMult, out posX1, out posX2);
                if (posX2 - posX1 <= 0.0f)
                {
                    continue;
                }

                MFGuiQuad quad = m_Quads[quadIdx];
                if (quad == null)
                {
                    continue;
                }

                // update screen coords
                if (fullUpdate == true || updateVerts == true)
                {
                    Rect rect = new Rect(m_Offset.x + posX1, m_Offset.y + posY1, posX2 - posX1, posY2 - posY1);

                    if (nonEmpty > 1)
                    {
                        rect.x = rect.x - m_Size.x * 0.5f + rect.width * 0.5f;
                        rect.y = rect.y - m_Size.y * 0.5f + rect.height * 0.5f;
                    }

                    quad.UpdateVertices(m_GuiRenderer, matrix, rect, 0.0f);
                }

                // update UV coords
                if (fullUpdate == true || updateUVs == true)
                {
                    float uvX1, uvX2;
                    ComputeRealValues(xIdx, m_UVCoords.Width, x1, x2, out uvX1, out uvX2);

                    float uvY1, uvY2;
                    ComputeRealValues(2 - yIdx, m_UVCoords.Height, y1, y2, out uvY1, out uvY2);

                    Vector2 uvCoords     = new Vector2(m_UVCoords.U + uvX1, m_UVCoords.V + uvY1);
                    Vector2 uvDimensions = new Vector2(uvX2 - uvX1, uvY2 - uvY1);

                    quad.UpdateUVs(m_GuiRenderer, uvCoords, uvDimensions);
                }

                // update color
                if (fullUpdate == true || updateColor == true)
                {
                    quad.SetColor(m_GuiRenderer, m_Color);
                }

                // go for new quad
                quadIdx += 1;
            }
        }
    }