예제 #1
0
    //---------------------------------------------------------
    // Makes a copy of material and U,V settings
    public void CopyMaterialSettings(GUIBase_Widget otherWidget)
    {
        if (otherWidget == null)
        {
            return;
        }
        if (otherWidget.m_Material == null || otherWidget.m_Material.mainTexture == null)
        {
            Debug.LogWarning("GUIBase_Widget.CopyMaterialSettings() :: Invalid source widget '" + otherWidget.GetFullName('.') + "'!!!",
                             otherWidget.gameObject);
            return;
        }

        // setup widget
        m_Material  = otherWidget.m_Material;
        m_InTexPos  = otherWidget.m_InTexPos;
        m_InTexSize = otherWidget.m_InTexSize;
        m_Grid9     = otherWidget.m_Grid9;

        // we don't need to call ChangeMaterial() if there is not any gui renderer assigned yet
        // we can wait until Initialize() call will do so
        if (m_GuiRenderer != null)
        {
            // reassign renderer and material
            ChangeMaterial(m_Material);
        }
    }
예제 #2
0
    //---------------------------------------------------------
    MFGuiSprite AddSprite(Rect rect,
                          float rotAngle,
                          float depth,
                          int leftPixelX,
                          int bottomPixelY,
                          int pixelWidth,
                          int pixelHeight,
                          MFGuiGrid9 grid9 = null)
    {
        SetModify();

        return(m_GuiRenderer.AddElement(rect, rotAngle, depth, leftPixelX, bottomPixelY, pixelWidth, pixelHeight, grid9));
    }
예제 #3
0
    public MFGuiSprite AddElement(Rect rect,
                                  float angle,
                                  float depth,
                                  int leftPixelX,
                                  int bottomPixelY,
                                  int pixelWidth,
                                  int pixelHeight,
                                  MFGuiGrid9 grid9 = null)
    {
        LogFuncCall("AddElement", name);

        rect = rect.MakePixelPerfect();

        Vector2 uvCoords = PixelCoordToUVCoord(leftPixelX, bottomPixelY);
        Vector2 uvSizes  = PixelSpaceToUVSpace(pixelWidth, pixelHeight);

        return(AddElement(rect, angle, depth, new MFGuiUVCoords(uvCoords, uvSizes), grid9));
    }
예제 #4
0
 public MFGuiGrid9Cached(MFGuiGrid9 other)
 {
     c = (byte)other.ComputeSegments(out x, out y);
 }
예제 #5
0
    //---------------------------------------------------------
    //public int AddSprite(Rect inSprite, Vector2 inScale, float inRotAngle, Rect inSpriteTextCoord)
    public int AddSprite(Vector2 centerSpritePos,
                         float width,
                         float height,
                         float scaleWidth,
                         float scaleHeight,
                         float rotAngle,
                         int texU,
                         int texV,
                         int texW,
                         int texH,
                         MFGuiGrid9 grid9 = null)
    {
        int resIdx = -1;

        float rx = centerSpritePos.x - 0.5f * width * scaleWidth;
        float ry = centerSpritePos.y - 0.5f * height * scaleHeight;

        MFGuiSprite sprite = AddSprite(
            new Rect(rx, ry, width * scaleWidth, height * scaleHeight),
            rotAngle,
            ComputedWidgetLayer * -(1.0f / GUIBase_Layout.MAX_LAYERS),
            texU,
            texV,
            texW,
            texH,
            grid9);

        //	Debug.Log(name + " depth = " + (-((float)m_Layout.m_LayoutLayer + (float)m_GuiWidgetLayer * 0.1f)));

        if (sprite != null)
        {
            if (m_Sprites == null)
            {
                ReserveSprites(1);
                resIdx = m_UnusedSpriteIndex++;
            }
            else if (ReservedSpritesSize > 0 && m_UnusedSpriteIndex < ReservedSpritesSize)
            {
                resIdx = m_UnusedSpriteIndex++;
            }
            else
            {
                // reallocate (add 1 sprite)
                ReallocateSprites(m_Sprites.Length + 1);
                resIdx = m_UnusedSpriteIndex++;
            }

            m_Sprites[resIdx].m_Sprite    = sprite;
            m_Sprites[resIdx].m_IsVisible = false;
            m_Sprites[resIdx].m_Pos       = centerSpritePos;
            m_Sprites[resIdx].m_Width     = width;
            m_Sprites[resIdx].m_Height    = height;
            m_Sprites[resIdx].m_Grid9     = grid9;

            // Show sprite ?
            ShowSprite(resIdx, Visible);
        }

        //Debug.Log("AddSprite = "+ resIdx +" for "+ gameObject.name);

        return(resIdx);
    }
예제 #6
0
 //---------------------------------------------------------
 void UpdateSprite(MFGuiSprite sprite, Rect rect, float rotAngle, Vector2 scale, float depth, MFGuiGrid9 grid9)
 {
     m_GuiRenderer.UpdateSprite(sprite, rect, rotAngle, scale, depth, grid9);
 }
예제 #7
0
    public void UpdateSprite(MFGuiSprite sprite, Rect rect, float angle, Vector2 scale, float depth, MFGuiGrid9 grid9)
    {
        LogFuncCall("UpdateSpritePosSize", name);

        // update matrix
        UpdateMatrix(ref sprite.matrix, rect, angle, scale, depth);

        rect = rect.MakePixelPerfect();

        // setup surface
        sprite.size = new Vector2(rect.width, rect.height);

        // we can't allow to change grid9 once it has been assigned
        // but we can assign one if there is not any yet
        if (sprite.grid9 == null && grid9 != null)
        {
            sprite.grid9 = new MFGuiGrid9Cached(grid9);
        }

        // we can transform sprite now
        Transform(sprite);
    }
예제 #8
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);
    }
예제 #9
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);
    }