public void Generate() { if (this._isWorldGenerated) { this.ClearWorld(); } int materialCount = this.materialPrefabs.Count; List <GameObject> selectedMaterials = new List <GameObject>(); for (int i = 0; i < materialCount; ++i) { if (this.selectableSpawn[i]) { selectedMaterials.Add(this.materialPrefabs[i]); } } int selectedCount = selectedMaterials.Count; GameObject go; Cell cell; System.Random rand; WangDoubleHash hashObject = new WangDoubleHash(currentSeed); float height; this.sizeX = this.nextWorldSizeX; this.sizeY = this.nextWorldSizeY; for (int y = 0; y < sizeY; ++y) { _cells.Add(new List <Cell>()); for (int x = 0; x < sizeX; ++x) { // get seed for current cell int cellSeed = (int)hashObject.GetHash(x, y); rand = new System.Random(cellSeed); // spawn world cell go = Instantiate(cellPrefab); cell = go.GetComponent <Cell>(); go.transform.parent = transform; height = (rand.Next(0, (int)(yOffsetJitter * 100)) + 50) / 100f; go.transform.localPosition = new Vector3(x - sizeX / 2 + 1, height, -(y - sizeY / 2 + 1)); // setup cell cell.Setup(x, y, cellSize); cell.SetMaterial(selectedMaterials[rand.Next(0, selectedCount)]); // TODO: would be nice to have a percentage-based material type setup? (some stuff is placed rarely) cell.SetValues(rand); cell.SetTemperature(globalTemperature); _cells[y].Add(cell); } } this._isWorldGenerated = true; }
public uint Hash(uint generator, int value) { return(WangDoubleHash.GetHash(value, generator)); }
public void Generate() { if(this._isWorldGenerated) { this.ClearWorld(); } int materialCount = this.materialPrefabs.Count; List<GameObject> selectedMaterials = new List<GameObject>(); for(int i = 0;i < materialCount;++i) { if(this.selectableSpawn[i]) { selectedMaterials.Add(this.materialPrefabs[i]); } } int selectedCount = selectedMaterials.Count; GameObject go; Cell cell; System.Random rand; WangDoubleHash hashObject = new WangDoubleHash(currentSeed); float height; this.sizeX = this.nextWorldSizeX; this.sizeY = this.nextWorldSizeY; for (int y = 0; y < sizeY; ++y) { _cells.Add(new List<Cell>()); for (int x = 0; x < sizeX; ++x) { // get seed for current cell int cellSeed = (int)hashObject.GetHash(x, y); rand = new System.Random(cellSeed); // spawn world cell go = Instantiate(cellPrefab); cell = go.GetComponent<Cell>(); go.transform.parent = transform; height = (rand.Next(0, (int)(yOffsetJitter * 100)) + 50) / 100f; go.transform.localPosition = new Vector3(x - sizeX / 2 + 1, height, -(y - sizeY / 2 + 1)); // setup cell cell.Setup(x, y, cellSize); cell.SetMaterial(selectedMaterials[rand.Next(0, selectedCount)]); // TODO: would be nice to have a percentage-based material type setup? (some stuff is placed rarely) cell.SetValues(rand); cell.SetTemperature(globalTemperature); _cells[y].Add(cell); } } this._isWorldGenerated = true; }