public void LoadNeighbors1() // load neighbors in radius 1 { bool offsetX = (position.y % 2) == 1; // to proper fit in hexagonal shape, odd rows have an offset in X Vector2Int neighbor_pos = position; neighbor_pos.x = position.x + 1 > WS_World.sizeX - 1 ? 0 : position.x + 1; neighbors_1.Add(world.GetTile(neighbor_pos)); // add right neighbor neighbor_pos.x = position.x - 1 < 0 ? (WS_World.sizeX - 1) : position.x - 1; // add left neighbor neighbors_1.Add(world.GetTile(neighbor_pos)); if (offsetX) // apply the offset if required { neighbor_pos.x = position.x; } neighbor_pos.y = position.y + 1 > WS_World.sizeY - 1 ? 0 : position.y + 1; // add upper left neihgbor neighbors_1.Add(world.GetTile(neighbor_pos)); neighbor_pos.y = position.y - 1 < 0 ? WS_World.sizeY - 1 : position.y - 1; // add lower left neihgbor neighbors_1.Add(world.GetTile(neighbor_pos)); neighbor_pos.x = neighbor_pos.x + 1 > WS_World.sizeX - 1 ? 0 : neighbor_pos.x + 1; neighbor_pos.y = position.y + 1 > WS_World.sizeY - 1 ? 0 : position.y + 1; // add upper right neihgbor neighbors_1.Add(world.GetTile(neighbor_pos)); neighbor_pos.y = position.y - 1 < 0 ? WS_World.sizeY - 1 : position.y - 1; // add lower left neihgbor neighbors_1.Add(world.GetTile(neighbor_pos)); }
// Update is called once per frame void Update() { if (!tilePanel.activeSelf) { if (Input.GetMouseButton(0) && world.output != null) { float mouseRatioX = Input.mousePosition.x / Screen.width; float mouseRatioY = Input.mousePosition.y / Screen.height; Vector2 tilePos = new Vector2((mouseRatioX * world.output.width) / (world.hexTex.width * 0.84f), (mouseRatioY * world.output.height) / (world.hexTex.height * 0.75f)); selectedTile = world.GetTile(new Vector2Int(Mathf.FloorToInt(tilePos.x), Mathf.FloorToInt(tilePos.y))); if (selectedTile != null) { if (!selectedTile.seaBody) { tilePanel.SetActive(true); switch (selectedTile.biome) { case Biome.POLAR: biomeImage.sprite = iconPolar; break; case Biome.TUNDRA: biomeImage.sprite = iconTundra; break; case Biome.BOREAL_FOREST: biomeImage.sprite = iconBorealForest; break; case Biome.ALPINE: biomeImage.sprite = iconAlpine; break; case Biome.ALPINE_SHRUBLAND: biomeImage.sprite = iconAlpineShrubland; break; case Biome.ALPINE_FOREST: biomeImage.sprite = iconAlpineForest; break; case Biome.TEMPERATE_SHRUBLAND: biomeImage.sprite = iconTemperateShrubland; break; case Biome.TEMPERATE_GRASSLAND: biomeImage.sprite = iconTemperateGrassland; break; case Biome.TEMPERATE_FOREST: biomeImage.sprite = iconTemperateForest; break; case Biome.WETLANDS: biomeImage.sprite = iconWetlands; break; case Biome.SAVANNAH: biomeImage.sprite = iconSavannah; break; case Biome.TEMPERATE_DESERT: biomeImage.sprite = iconTemperateDesert; break; case Biome.TROPICAL_GRASSLAND: biomeImage.sprite = iconTropicalGrassland; break; case Biome.TROPICAL_JUNGLE: biomeImage.sprite = iconTropicalJungle; break; case Biome.ARID_DESERT: biomeImage.sprite = iconAridDesert; break; case Biome.WATER: biomeImage.sprite = iconWater; break; } return; } } tilePanel.SetActive(false); } } else { townName.text = selectedTile.name; } }