void PerlinFillMap() { if (useRandomSeed) { seed = Time.time.ToString() + transform.position.ToString(); } System.Random pseudoRandom = new System.Random(seed.GetHashCode()); PinkNoise pink = new PinkNoise(pseudoRandom.Next(0, 100)); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < depth; z++) { if (x == 0 || x == width - 1 || y == 0 || y == height - 1 || z == 0 || z == depth - 1) { map[x, y, z] = 1; } else { if (pink.GetValue(x, y, z) > 0.15) { map[x, y, z] = 1; } else { map[x, y, z] = 0; } } } } } }
private IEnumerator CreateField() { int count = 0; Vector3 size = spaceBounds.bounds.size; Vector3 min = spaceBounds.bounds.min; if (generatePlanets) { for (int i = 0; i < size.x; i += scalar) { for (int j = 0; j < size.y; j += scalar) { for (int k = 0; k < size.z; k += scalar) { Vector3 point = new Vector3(i + min.x, j + min.y, k + min.z); if (IsPointValid(point)) { float value = noise.GetValue(point.x, point.y, point.z); if (value > planetNoise.x && value <= planetNoise.y) { GameObject planetObject = Instantiate(planet, point, planet.transform.rotation) as GameObject; planetObject.SendMessage("Generate", SendMessageOptions.DontRequireReceiver); if (planetObject.GetComponent <Collider> ()) { noGenSpace.Add(planetObject.GetComponent <Collider> ()); } planetObject.transform.SetParent(transform); yield return(null); count++; } } } } } Debug.Log(count + " Planets created"); } if (generateAsteroids) { count = 0; for (int i = 0; i < size.x; i += scalar) { for (int j = 0; j < size.y; j += scalar) { for (int k = 0; k < size.z; k += scalar) { Vector3 point = new Vector3(i + min.x, j + min.y, k + min.z); if (IsPointValid(point)) { float value = noise.GetValue(point.x, point.y, point.z); if (value > asteroidNoise.x && value <= asteroidNoise.y) { GameObject asteroidObject = Instantiate(asteroid, point, asteroid.transform.rotation) as GameObject; asteroidObject.SendMessage("Generate", SendMessageOptions.DontRequireReceiver); if (asteroidObject.GetComponent <Collider> ()) { noGenSpace.Add(asteroidObject.GetComponent <Collider> ()); } asteroidObject.transform.SetParent(transform); count++; if (count % 3 == 0) { yield return(null); } } } } } } Debug.Log(count + " Asteroids created"); } if (generateOnStart) { GameObject[] warpObjects = SceneManager.GetSceneByName("Warp").GetRootGameObjects(); foreach (GameObject obj in warpObjects) { if (obj) { obj.SendMessage("EnableNextScene", SendMessageOptions.DontRequireReceiver); } } } }