Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Generate()
- {
- Vector3 tmpPos;
- GameObject tree;
- /*
- System.Random r = new System.Random();
- for (int i = 0; i < 100; i++)
- {
- print((float)RandomExtensions.NextGaussian(r, this.waterMu, this.waterSigma));
- }
- * */
- System.DateTime d = System.DateTime.Now;
- if (this.waterTrees > 0 || this.dryTrees > 0 )
- {
- this.waterTreesQueue = new List<GameObject>(this.waterTrees);
- this.dryTreesQueue = new List<GameObject>(this.dryTrees);
- SpawnWater();
- SpawnDry();
- print("creation: " + (System.DateTime.Now - d));
- int rows = Mathf.RoundToInt(Mathf.Sqrt(this.waterTrees + this.dryTrees));
- int columns = rows;
- int indexX = Mathf.RoundToInt((this.gridWidth / rows));
- int indexY = Mathf.RoundToInt((this.gridHeight / columns));
- int startX = Mathf.RoundToInt((indexX / 2) - (this.gridWidth/2));
- int startY = Mathf.RoundToInt((indexY / 2) - (this.gridHeight/2));
- int randomLimitsX = Mathf.RoundToInt(indexX / 3);
- int randomLimitsY = Mathf.RoundToInt(indexY / 3);
- System.DateTime gt = System.DateTime.Now;
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < columns; j++)
- {
- tmpPos = new Vector3(this.gridCenter.x + (Random.Range(-1 * randomLimitsX, randomLimitsX) + (startX + indexX * i)), 0f, this.gridCenter.y + Random.Range(-1 * randomLimitsY, randomLimitsY) + (startY + indexY * j));
- float randVal = Random.value;
- if (this.dryTreesQueue.Count == 0 || randVal < .5f)
- {
- if (this.waterTreesQueue.Count > 0)
- {
- tree = (GameObject)this.waterTreesQueue[0];
- this.waterTreesQueue.RemoveAt(0);
- tree.transform.position = tmpPos;
- }
- }
- else if (this.waterTreesQueue.Count == 0 || randVal > .5f)
- {
- if (this.dryTreesQueue.Count > 0)
- {
- tree = (GameObject)this.dryTreesQueue[0];
- this.dryTreesQueue.RemoveAt(0);
- tree.transform.position = tmpPos;
- }
- }
- }
- }
- print("reposition: " + (System.DateTime.Now - gt));
- // clean up
- foreach (GameObject item in this.waterTreesQueue)
- {
- Destroy(item);
- }
- foreach (GameObject item in this.dryTreesQueue)
- {
- Destroy(item);
- }
- }
- else
- {
- this.errorText.text = "# of trees == 0";
- }
- print("Elapsed: " + (System.DateTime.Now - d));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement