I have a function that takes an image, and breaks it down into individual tiles. This is the image.
[175092-autotiletest.png*|175092]
The code is designed to break it down in a specific way… left to right, top to bottom. Here’s the code.
public Texture2D[] GetAutoTiles(string path)
{
Texture2D OriginalImage;
Texture2D CurrentImage;
List<Texture2D> tilesList = new List<Texture2D>();
Texture2D[] tilesArray;
if (path != "" || path != null)
{
OriginalImage = new Texture2D(2,2);
byte[] fileData;
fileData = File.ReadAllBytes(path);
OriginalImage.LoadImage(fileData);
int tilesOnX = Mathf.FloorToInt(OriginalImage.width / cellSize);
int tilesOnY = Mathf.FloorToInt(OriginalImage.height / cellSize);
int x = 0;
int y= OriginalImage.height - cellSize;
for (int iX = 0; iX < tilesOnX; iX++)
{
x = iX * cellSize;
Debug.Log(x +", "+ y);
Color[] selection = OriginalImage.GetPixels(x, y, cellSize, cellSize);
CurrentImage = new Texture2D(cellSize, cellSize);
CurrentImage.SetPixels(selection);
CurrentImage.Apply();
tilesList.Add(CurrentImage);
if (iX == tilesOnX - 1)
{
iX = -1;
y -= cellSize;
if (y < 0)
{
break;
}
}
}
int i = 1;
tilesArray = new Texture2D[tilesList.Count+1];
tilesArray[0] = OriginalImage;
foreach(Texture2D t in tilesList)
{
tilesArray *= t;*
}
return tilesArray;
}
return null;
}
----------
The problem is, it’s only returning the last tile of the image (With parts 15, 16, 19 and 20). I’ve used this code for breaking normal tiles and it works fine. Can’t figure out why its no longer working. The X and Y coordinates seem to be fine but this is what is returned:
[175093-capture.png|175093]*
*
*