89 lines
2.4 KiB
C#
89 lines
2.4 KiB
C#
using Assets.Scripts;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Map : MonoBehaviour
|
|
{
|
|
public Image city;
|
|
public Image plains;
|
|
public Image forest;
|
|
public Image stone;
|
|
public Image spawn;
|
|
public Image lake;
|
|
public Image river;
|
|
public Image[] mapTiles;
|
|
|
|
public void prepare(Dictionary<Vector3, GameObject> tiles, GameObject currentTile)
|
|
{
|
|
destroyMap();
|
|
generateMap(tiles, currentTile);
|
|
}
|
|
|
|
private void destroyMap()
|
|
{
|
|
for (int i = 0; i < mapTiles.Length; i++)
|
|
{
|
|
mapTiles[i].color = Color.white;
|
|
}
|
|
}
|
|
|
|
private void generateMap(Dictionary<Vector3, GameObject> tiles, GameObject currentTile)
|
|
{
|
|
Vector3 current = currentTile.GetComponent<Tile>().getPosition();
|
|
|
|
Vector3 position;
|
|
Color color;
|
|
|
|
int posX = (int)current.x - 2;
|
|
int posZ = (int)current.z + 2;
|
|
for (int i = 0; i < mapTiles.Length; i++)
|
|
{
|
|
if (i == 5 || i == 10 || i == 15 || i == 20)
|
|
{
|
|
posX = (int)current.x - 2;
|
|
posZ--;
|
|
}
|
|
|
|
position = new Vector3(posX, 0, posZ);
|
|
|
|
if (tiles.ContainsKey(position))
|
|
{
|
|
switch (tiles[position].name.Split('_')[0])
|
|
{
|
|
case "StoneTile":
|
|
color = stone.color;
|
|
break;
|
|
case "CityTile":
|
|
color = city.color;
|
|
break;
|
|
case "Tile":
|
|
color = plains.color;
|
|
break;
|
|
case "TreeTile":
|
|
color = forest.color;
|
|
break;
|
|
case "RiverTile1":
|
|
color = river.color;
|
|
break;
|
|
case "RiverTile2":
|
|
color = river.color;
|
|
break;
|
|
case "RiverTile3":
|
|
color = river.color;
|
|
break;
|
|
case "LakeTile":
|
|
color = lake.color;
|
|
break;
|
|
default:
|
|
color = spawn.color;
|
|
break;
|
|
}
|
|
mapTiles[i].color = color;
|
|
}
|
|
posX++;
|
|
}
|
|
}
|
|
}
|