public MapCubeCoord[] getCloseNeighbors() { MapCubeCoord[] nb = new MapCubeCoord[6]; nb [0] = new MapCubeCoord(x + 1, y, z); nb [1] = new MapCubeCoord(x, y - 1, z); nb [2] = new MapCubeCoord(x, y, z + 1); nb [3] = new MapCubeCoord(x - 1, y, z); nb [4] = new MapCubeCoord(x, y + 1, z); nb [5] = new MapCubeCoord(x, y, z - 1); return(nb); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } if (obj.GetType() != typeof(MapCubeCoord)) { return(false); } MapCubeCoord other = (MapCubeCoord)obj; return(x == other.x && y == other.y && z == other.z); }
// Use this for initialization void Start() { MapCubeCoord[][] rings = new MapCubeCoord[7][]; rings[0] = new MapCubeCoord[1]; rings[0][0] = new MapCubeCoord(0, 0, 0); for (int r = 1; r < rings.Length; r++) { rings[r] = new MapCubeCoord[6 * r]; for (int d = 0; d < 6; d++) { rings[r][d * r] = rings[r - 1][d * (r - 1)].getNeighbors()[d]; for (int o = 1; o < r; o++) { rings[r][d * r + o] = rings[r][d * r + o - 1].getNeighbors()[(d + 2) % 6]; } } } for (int r = 0; r < rings.Length; r++) { for (int i = 0; i < rings[r].Length; i++) { if (rings[r][i] != null) { GameObject gobj = new GameObject("Map tile at" + rings[r][i], new System.Type[] { typeof(MapTile) }); gobj.transform.SetParent(transform, false); gobj.layer = gameObject.layer; MapTile tile = gobj.GetComponent <MapTile>(); tile.Coord = rings[r][i]; tiles.Add(rings[r][i], tile); } } } GameDataManager gdm = GameObject.FindObjectOfType <GameDataManager>(); TileTerrain[] terrains = gdm.CatalogDB.GetCatalog <TileTerrain>().ToArray(); foreach (MapTile tile in tiles.Values) { tile.Terrain = terrains[Random.Range(0, terrains.Length)]; } }
public bool isNeigbor(MapCubeCoord other) { return((Mathf.Abs(x - other.x) + Mathf.Abs(y - other.y) + Mathf.Abs(z - other.z)) == 2); }