// 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
    // leftPixelX and bottomPixelY- the bottom-left position of the desired portion of the texture, in pixels
    // pixelWidth and pixelHeight - the dimensions of the desired portion of the texture, in pixels
    public GUISprite AddSprite(GameObject client, int width, int height, float depth, Vector2 LLUV)
    {
        int     spriteIndex;
        Vector2 lowerLeftUV  = PixelCoordToUVCoord((int)LLUV.x, (int)LLUV.y);
        Vector2 UVDimensions = PixelSpaceToUVSpace(width, height);

        // Get an available sprite:
        if (availableBlocks.Count < 1)
        {
            // If we're out of available sprites, allocate some more.
            EnlargeArrays(allocBlockSize);
        }

        // Use a sprite from the list of available blocks:
        spriteIndex = ((GUISprite)availableBlocks[0]).index;
        availableBlocks.RemoveAt(0);    // Now that we're using this one, remove it from the available list

        // Assign the new sprite:
        GUISprite newSprite = sprites[spriteIndex];

        newSprite.client       = client;
        newSprite.depth        = depth;
        newSprite.lowerLeftUV  = LLUV;
        newSprite.uvDimensions = UVDimensions;

        switch (plane)
        {
        case SPRITE_PLANE.XY:
            newSprite.SetSizeXY(width, height);
            break;

        case SPRITE_PLANE.XZ:
            newSprite.SetSizeXZ(width, height);
            break;

        case SPRITE_PLANE.YZ:
            newSprite.SetSizeYZ(width, height);
            break;

        default:
            newSprite.SetSizeXY(width, height);
            break;
        }

        // Save this to an active list now that it is in-use:
        //activeBlocks.Add(newSprite);
        AddToActiveList(newSprite);

        // Setup the UVs:
        UVs[newSprite.uv1] = lowerLeftUV + Vector2.up * UVDimensions.y;                 // Upper-left
        UVs[newSprite.uv2] = lowerLeftUV;                                               // Lower-left
        UVs[newSprite.uv3] = lowerLeftUV + Vector2.right * UVDimensions.x;              // Lower-right
        UVs[newSprite.uv4] = lowerLeftUV + UVDimensions;                                // Upper-right

        // Set our flags:
        vertsChanged = true;
        uvsChanged   = true;

        return(newSprite);
    }
    public void RemoveSprite(GUISprite sprite)
    {
        sprite.SetSizeXY(0, 0);
        sprite.v1 = Vector3.zero;
        sprite.v2 = Vector3.zero;
        sprite.v3 = Vector3.zero;
        sprite.v4 = Vector3.zero;

        vertices[sprite.mv1] = sprite.v1;
        vertices[sprite.mv2] = sprite.v2;
        vertices[sprite.mv3] = sprite.v3;
        vertices[sprite.mv4] = sprite.v4;

        sprite.client = null;

        availableBlocks.Add(sprite);

        // Remove the sprite from the active list
        //activeBlocks.Remove(sprite);
        RemoveFromActiveList(sprite);

        vertsChanged = true;
    }
Esempio n. 3
0
    public void RemoveSprite(GUISprite sprite)
    {
        sprite.SetSizeXY(0,0);
        sprite.v1 = Vector3.zero;
        sprite.v2 = Vector3.zero;
        sprite.v3 = Vector3.zero;
        sprite.v4 = Vector3.zero;

        vertices[sprite.mv1] = sprite.v1;
        vertices[sprite.mv2] = sprite.v2;
        vertices[sprite.mv3] = sprite.v3;
        vertices[sprite.mv4] = sprite.v4;

        sprite.client = null;

        availableBlocks.Add(sprite);

        // Remove the sprite from the active list
        //activeBlocks.Remove(sprite);
        RemoveFromActiveList(sprite);

        vertsChanged = true;
    }