Exemplo n.º 1
0
        // Creates Texture Atlas from all textures in /Blocks/ FOLDER
        public void CreateAtlas()
        {
            string[]  images      = Directory.GetFiles("Assets/Resources/Textures/Blocks/", "*.png");
            int       pixelWidth  = 32;
            int       pixelHeight = 32;
            int       atlasWidth  = Mathf.CeilToInt((Mathf.Sqrt(images.Length) + 1) * pixelWidth);
            int       atlasHeight = Mathf.CeilToInt((Mathf.Sqrt(images.Length) + 1) * pixelHeight);
            Texture2D atlas       = new Texture2D(atlasWidth, atlasHeight);
            int       count       = 0;

            for (int x = 0; x < atlasWidth / pixelWidth; x++)
            {
                for (int y = 0; y < atlasHeight / pixelHeight; y++)
                {
                    if (count > images.Length - 1)
                    {
                        goto end;
                    }
                    Texture2D temp = new Texture2D(0, 0, TextureFormat.ARGB32, false);
                    temp.LoadImage(File.ReadAllBytes(images[count]));
                    atlas.SetPixels(x * pixelWidth, y * pixelHeight, pixelWidth, pixelHeight, temp.GetPixels());
                    float startx         = x * pixelWidth;
                    float starty         = y * pixelHeight;
                    float perpixelratiox = 1.0f / atlas.width;
                    float perpixelratioy = 1.0f / atlas.height;
                    startx *= perpixelratiox;
                    starty *= perpixelratioy;
                    float endx = startx + (perpixelratiox * pixelWidth);
                    float endy = starty + (perpixelratioy * pixelHeight);
                    UVMap map  = new UVMap(images[count], new Vector2[]
                    {
                        new Vector2(startx, starty),
                        new Vector2(startx, endy),
                        new Vector2(endx, starty),
                        new Vector2(endx, endy)
                    });
                    map.Register();
                    count++;
                }
            }
end:
            ;
            Atlas = atlas;
            File.WriteAllBytes("Assets/Resources/Textures/Atlas/atlas.png", atlas.EncodeToPNG());
        }
Exemplo n.º 2
0
 // Block constructor for Blocks with unique top, sides, bottom textures (Grass)
 public Block(string _blockName, bool _isTransparent, bool _isSemiTransparent, BlockFaceStyle _style, string _textureName0, string _textureName1, string _textureName2, string _textureName3, string _textureName4, string _textureName5)
 {
     this.BlockName         = _blockName;
     this.IsTransparent     = _isTransparent;
     this.IsSemiTransparent = _isSemiTransparent;
     this.style             = _style;
     if (this.style == BlockFaceStyle.AirStyle)
     {
         this.textureName0 = null;
         this.textureName1 = null;
         this.textureName2 = null;
         this.textureName3 = null;
         this.textureName4 = null;
         this.textureName5 = null;
         this.uvMap0       = null;
         this.uvMap1       = null;
         this.uvMap2       = null;
         this.uvMap3       = null;
         this.uvMap4       = null;
         this.uvMap5       = null;
     }
     else if (this.style == BlockFaceStyle.UniversalStyle)
     {
         this.textureName0 = _textureName0;
         this.textureName1 = null;
         this.textureName2 = null;
         this.textureName3 = null;
         this.textureName4 = null;
         this.textureName5 = null;
         this.uvMap0       = UVMap.GetUVMap(this.textureName0).UVMaps;
         this.uvMap1       = null;
         this.uvMap2       = null;
         this.uvMap3       = null;
         this.uvMap4       = null;
         this.uvMap5       = null;
     }
     else if (this.style == BlockFaceStyle.LogStyle)
     {
         this.textureName0 = _textureName0;
         this.textureName1 = _textureName1;
         this.textureName2 = null;
         this.textureName3 = null;
         this.textureName4 = null;
         this.textureName5 = null;
         this.uvMap0       = UVMap.GetUVMap(this.textureName0).UVMaps;
         this.uvMap1       = UVMap.GetUVMap(this.textureName1).UVMaps;
         this.uvMap2       = null;
         this.uvMap3       = null;
         this.uvMap4       = null;
         this.uvMap5       = null;
     }
     else if (this.style == BlockFaceStyle.GrassStyle)
     {
         this.textureName0 = _textureName0;
         this.textureName1 = _textureName1;
         this.textureName2 = _textureName2;
         this.textureName3 = null;
         this.textureName4 = null;
         this.textureName5 = null;
         this.uvMap0       = UVMap.GetUVMap(this.textureName0).UVMaps;
         this.uvMap1       = UVMap.GetUVMap(this.textureName1).UVMaps;
         this.uvMap2       = UVMap.GetUVMap(this.textureName2).UVMaps;
         this.uvMap3       = null;
         this.uvMap4       = null;
         this.uvMap5       = null;
     }
     this.REGISTER();
 }