Beispiel #1
0
        private void UpdateTexturePadding()
        {
            tileSets[path] = TileSet.Load(path); // DELETE ME
            TileSet   ts          = tileSet;
            Texture2D texture     = TileMapEditor.GetTileSetTexture(ts, path);
            string    texturePath = AssetDatabase.GetAssetPath(texture);

            TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(texturePath);

            importer.isReadable = true;
            AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);

            int inWidth   = ts.tileWidth * ts.columns + ts.margin * 2 + ts.spacing * (ts.columns - 1);
            int outWidth  = ts.tileWidth * ts.columns + margin * 2 + spacing * (ts.columns - 1);
            int outHeight = ts.tileHeight * ts.rows + margin * 2 + spacing * (ts.rows - 1);

            Color[] inColors  = texture.GetPixels();
            Color[] outColors = new Color[outWidth * outHeight];

            for (int column = 0; column < ts.columns; column++)
            {
                for (int row = 0; row < ts.rows; row++)
                {
                    for (int i = 0; i < ts.tileWidth; i++)
                    {
                        for (int j = 0; j < ts.tileHeight; j++)
                        {
                            int   inX = i + (ts.tileWidth + ts.spacing) * column + ts.margin;
                            int   inY = j + (ts.tileHeight + ts.spacing) * row + ts.margin;
                            Color c   = inColors[inY * inWidth + inX];

                            int left  = (i == 0) ? ((column == 0) ? -margin : -spacing / 2) : 0;
                            int right = (i == ts.tileWidth - 1) ? ((column == ts.columns - 1) ? margin : spacing / 2) : 0;
                            int down  = (j == 0) ? ((row == 0) ? -margin : -spacing / 2) : 0;
                            int up    = (j == ts.tileHeight - 1) ? ((row == ts.rows - 1) ? margin : spacing / 2) : 0;
                            for (int x = i + left; x <= i + right; x++)
                            {
                                for (int y = j + down; y <= j + up; y++)
                                {
                                    int outX = x + (ts.tileWidth + spacing) * column + margin;
                                    int outY = y + (ts.tileHeight + spacing) * row + margin;
                                    outColors[outY * outWidth + outX] = c;
                                }
                            }
                        }
                    }
                }
            }

            Texture2D t = new Texture2D(outWidth, outHeight);

            t.SetPixels(outColors);
            byte[] bytes = t.EncodeToPNG();
            File.WriteAllBytes(texturePath, bytes);

            AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);

            tileSet.margin       = margin;
            tileSet.spacing      = spacing;
            tileSet.image.width  = outWidth;
            tileSet.image.height = outHeight;
            tileSet.Save(path);
        }
Beispiel #2
0
 private void TileSetSpriteCollectionField(TileSet tileSet)
 {
 }