private void CalculateCountOfSystemElements() { int tilesCount = 0; foreach (var t in ColoredList) { tilesCount += t.Item2.Count; } int oneTileElementsCount = tilesCount / 3; int BigElementCount = oneTileElementsCount / BigElementsModifier; int AvrageElementCount = oneTileElementsCount / AvrageElementsModifier; int SmallElementCount = oneTileElementsCount / SmallElementModifier; GeneratorItems[0] = new SystemElementGeneratorItem() { CountPerMapModule = BigElementCount, Size = 7 }; GeneratorItems[1] = new SystemElementGeneratorItem() { CountPerMapModule = AvrageElementCount, Size = 3 }; GeneratorItems[2] = new SystemElementGeneratorItem() { CountPerMapModule = SmallElementCount, Size = 1 }; }
private void GenerateSystemElement(SystemElementGeneratorItem generatorItem, HashSet <HexagonTille> source, ref Color elementColor) { foreach (var tile in elementTiles) { tile.IsComponent = true; tile.SetMainColor(componentHexColor, ref elementColor); source.Remove(tile); foreach (var neighbour in tile.NeighbourList) { source.Remove(neighbour); } } Vector3 position = elementTiles[0].transform.position; if (elementTiles.Count == 3) { float minX, maxX, posY; minX = maxX = position.x; posY = position.y; for (int i = 1; i < elementTiles.Count; i++) { position = elementTiles[i].transform.position; float x = position.x; float y = position.y; if (x < minX) { minX = x; } else if (x > maxX) { maxX = x; } posY += y; } position = new Vector3((minX + maxX) / 2, posY / 3, 0); } var generatedElementInfo = new GeneratedElementInfo() { MapTerritory = currentMapTerritory, Position = position, Tiles = new HashSet <HexagonTille>(elementTiles) }; OnSystemElementGenerated.Invoke(generatedElementInfo); }
private void GenerateSystemElements(SystemElementGeneratorItem generatorItem, HashSet <HexagonTille> tileList, Color elementColor) { for (int i = 0; i < generatorItem.CountPerMapModule; i++) { elementTiles.Clear(); FindTilesForSystemElement(tileList, generatorItem.Size); if (elementTiles.Count == 0) { return; } GenerateSystemElement(generatorItem, tileList, ref elementColor); } }