Exemplo n.º 1
0
    public void SetTextureCoords(int spriteIdx, float UVLeft, float UVTop, float UVWidth, float UVHeight)
    {
        if (m_Sprites == null)
        {
            return;
        }
        if (m_Sprites.Length <= spriteIdx)
        {
            return;
        }

        MFGuiSprite sprite = m_Sprites[spriteIdx].m_Sprite;

        if (sprite == null)
        {
            return;
        }

        MFGuiUVCoords uvCoords = sprite.uvCoords;

        uvCoords.U      = UVLeft;
        uvCoords.V      = 1.0f - (UVTop + UVHeight);
        uvCoords.Width  = UVWidth;
        uvCoords.Height = UVHeight;
        sprite.uvCoords = uvCoords;

        SetModify();
    }
Exemplo n.º 2
0
    // Adds a sprite to the manager at the location and rotation of the client
    // GameObject and with its transform.  Returns a reference to the new sprite
    // Width and height are in world space units
    // lowerLeftUV - the UV coordinate for the upper-left corner
    // UVDimensions - the distance from lowerLeftUV to place the other UV coords
    public MFGuiSprite AddSprite(Matrix4x4 matrix, Rect rect, MFGuiUVCoords uvCoords, MFGuiGrid9 grid9)
    {
        LogFuncCall("AddSprite", name);

        if (availableSprites.Count < 1)
        {
            EnlargeSpriteArrays(allocBlockSize);
        }

        int index = availableSprites.Dequeue();

        if (sprites[index] == null)
        {
            sprites[index] = new MFGuiSprite(this, index);
        }

        rect = rect.MakePixelPerfect();

        // Assign the new sprite:
        MFGuiSprite sprite = sprites[index];

        sprite.matrix   = matrix;
        sprite.size     = new Vector2(rect.width, rect.height);
        sprite.uvCoords = uvCoords;
        sprite.grid9    = grid9 != null ? new MFGuiGrid9Cached(grid9) : default(MFGuiGrid9Cached);
        sprite.visible  = true;

        // Done
        return(sprite);
    }
Exemplo n.º 3
0
    public MFGuiSprite AddElement(Rect rect, float angle, float depth, MFGuiUVCoords uvCoords, MFGuiGrid9 grid9)
    {
        LogFuncCall("AddElement", name);

        UpdateUISize();

        // create matrix
        Matrix4x4 matrix = Matrix4x4.identity;

        UpdateMatrix(ref matrix, rect, angle, Vector2.one, depth);

        rect = rect.MakePixelPerfect();

        // create sprite
        MFGuiSprite sprite = AddSprite(matrix, rect, uvCoords, grid9);

        return(sprite);
    }
Exemplo n.º 4
0
    //-----------------------------------------------------
    void SetNumber(int number, int max, bool force)
    {
        if (m_Value == number && false == force)
        {
            return;
        }

        int absNumber = Mathf.Abs(number);

        if (absNumber > max)
        {
            absNumber = max;
        }

        m_Value = number;

        int div1 = 1;
        int div2 = 10;

        int visibleDigits = 0;

        for (int digitIdx = 0; digitIdx < numberDigits; ++digitIdx)
        {
            int rest = (absNumber % div2) / div1;

            if ((absNumber > (div1 - 1)) || (digitIdx == 0) || m_KeepZeros)
            {
                // Show digit
                m_Widget.ShowSprite(digitIdx, true);

                // set correct UV
                MFGuiSprite   s        = m_Widget.GetSprite(digitIdx);
                MFGuiUVCoords uvCoords = s.uvCoords;
                uvCoords.U = m_UvLeft + m_UvWidth * rest;
                uvCoords.V = 1.0f - (m_UvTop + m_UvHeight);
                s.uvCoords = uvCoords;

                visibleDigits++;
            }
            else
            {
                // Hide digit
                m_Widget.ShowSprite(digitIdx, false);
            }

            div1  = div2;
            div2 *= 10;
        }

        if (visibleDigits == 0)
        {
            return;
        }
        if (visibleDigits == m_LastVisibleDigits && force == false)
        {
            return;
        }
        m_LastVisibleDigits = visibleDigits;

        Transform trans = transform;
        Vector3   scale = trans.lossyScale;

        float   width     = m_Widget.GetWidth() / numberDigits;
        float   height    = m_Widget.GetHeight();
        float   halfWidth = m_Widget.GetWidth() * scale.x * 0.5f;
        Vector3 deltaPos  = new Vector3(halfWidth, 0.0f);
        Vector3 rightPos  = m_Widget.GetOrigPos() + deltaPos;

        Vector3 delta;

        switch (m_Alignment)
        {
        case TextAlignment.Left:
            delta       = deltaPos / (numberDigits * 0.5f);
            rightPos.x -= (numberDigits - visibleDigits) * delta.x;
            break;

        case TextAlignment.Center:
            delta = deltaPos / (visibleDigits * 0.5f);
            break;

        default:
            delta = deltaPos / (numberDigits * 0.5f);
            break;
        }

        for (int idx = 0; idx < visibleDigits; ++idx)
        {
            m_Widget.UpdateSpritePosAndSize(idx, rightPos.x - (idx + 0.5f) * delta.x, rightPos.y - (idx + 0.5f) * delta.y, width, height);
        }
    }