public void UpdateList(TileProject newTile) { for (int i = 1; i < group.Count; i++) { group[i].group.Add(newTile); } }
void SpawnGroup(int x, int y, OreToSpawn ore) { TileProject tile = new TileProject(); tile.groupSize = ore.groupSize; tile.ore = ore.ore; tile.amount = ore.settings.oreAmount; tempTiles[x, y] = tile; int groupSize = Random.Range(ore.settings.minGroupSize, ore.settings.maxGroupSize + 1); int check = 0, minGroupSize = 0, rand; List <int> dirs = RandomizeDir(); // dodaj while który w przypadku dużych grup będzie umieszczał złoża z innych pól a nie tylko z pierwszego for (int i = 0; i < dirs.Count; i++) { rand = ore.groupSize; //Random.Range(minGroupSize, ore.groupSize + 1); //if (rand == minGroupSize) minGroupSize = minGroupSize == 0 ? minGroupSize : minGroupSize - 1; //else minGroupSize = minGroupSize < ore.groupSize ? minGroupSize + 1 : minGroupSize; if (dirs[i] == 0) { if (tempTiles[x + 1, y] == null) { tempTiles[x + 1, y] = tile; tempTiles[x + 1, y].groupSize = rand; tempTiles[x, y].UpdateList(tempTiles[x + 1, y]); tempTiles[x + 1, y].group = tempTiles[x, y].group; groupSize--; // dodaj w każdym ifie zliczanie wygenerowanych złóż żeby na końcu podliczyć ich ilość // i na bierząco kontrolować czy nie spawnuje sie ich za dużo } } else if (dirs[i] == 1) { if (tempTiles[x, y + 1] == null) { tempTiles[x, y + 1] = tile; tempTiles[x, y + 1].groupSize = rand; tempTiles[x, y].UpdateList(tempTiles[x, y + 1]); tempTiles[x, y + 1].group = tempTiles[x, y].group; groupSize--; } } else if (dirs[i] == 2) { if (tempTiles[x - 1, y] == null) { tempTiles[x - 1, y] = tile; tempTiles[x - 1, y].groupSize = rand; tempTiles[x, y].UpdateList(tempTiles[x - 1, y]); tempTiles[x - 1, y].group = tempTiles[x, y].group; groupSize--; } } else if (dirs[i] == 3) { if (tempTiles[x, y - 1] == null) { tempTiles[x, y - 1] = tile; tempTiles[x, y - 1].groupSize = rand; tempTiles[x, y].UpdateList(tempTiles[x, y - 1]); tempTiles[x, y - 1].group = tempTiles[x, y].group; groupSize--; } } if (groupSize == 0) { return; } check++; if (check > 10) { return; } } }