Пример #1
0
    /*
     * @param side:
     * 0 - top
     * 1 - bottom
     * 2 - right
     * 3 - left
     * 4 - front
     * 5 - back
     */
    private void AddUvs(List <Vector2> uvs, int id, byte side)
    {
        // One texture unit (1/16=0.0625)
        const float unit = 0.0625f;

        // Choose block or liquid
        // Get texture coordinates for this side
        Block   b = Config.ID[id] as Block;
        Vector2 uv;

        if (b != null)
        {
            uv = b.GetUV(side);
        }
        else
        {
            Liquid l = Config.ID[id] as Liquid;
            uv = l.GetUV(side);
        }


        // Texture coordinates in the 16x16 grid
        float x = uv.x;
        float y = uv.y;

        // Convert to texture units
        x *= unit;
        y *= unit;

        // Illegal coords warning
        if (x > 15 || x < 0 || y > 15 || y < 0)
        {
            Debug.LogWarning("Block's texture coordinates are out of range [0, 15]");
        }

        // Add UVs
        uvs.Add(new Vector2(x, y));                 // left bottom
        uvs.Add(new Vector2(x, y + unit));          // left top
        uvs.Add(new Vector2(x + unit, y + unit));   // right top
        uvs.Add(new Vector2(x + unit, y));          // right bottom
    }