private void Awake()
{
level = new byte[levelTexture.width, levelTexture.height];
hexToIndex = new Dictionary <string, byte>();
foreach (TileTypes t in tileTypes)
{
hexToIndex.Add(t.hex, t.index);
}
for (int x = 0; x < levelTexture.width; x++)
{
for (int y = 0; y < levelTexture.height; y++)
{
Color color = levelTexture.GetPixel(x, y);
string hex = ColorUtility.ToHtmlStringRGB(color);
byte index = hexToIndex[hex];
level[x, y] = index;
}
}
for (int x = 0; x < levelTexture.width; x++)
{
for (int y = 0; y < levelTexture.height; y++)
{
byte cell = level[x, y];
GameObject obj;
if (cell == 0) //isAir
{
continue;
}
if (tileTypes[cell].isWall == true)
{
if (tileTypes[level[x, y - 1]].isWalkable || tileTypes[level[x, y - 1]].index == 5)
{
obj = Instantiate(tileTypes[cell].prefab[0], new Vector3(x, y), Quaternion.identity);
obj.transform.parent = this.transform;
}
else
{
obj = Instantiate(tileTypes[cell].prefab[1], new Vector3(x, y), Quaternion.identity);
obj.transform.parent = this.transform;
}
}
else
{
obj = Instantiate(tileTypes[cell].prefab[0], new Vector3(x, y), Quaternion.identity);
obj.transform.parent = this.transform;
}
}
}
grid.CreateGrid(level, levelTexture.width, levelTexture.height, tileTypes);
}