void Start() { //To get the same random numbers each time we run the script Random.InitState(100); OceanGenerator = new OceanGenerator(randomFillPercent, gridSize); OceanGenerator.RandomizeMap(); //For testing that init is working GenerateAndDisplayTexture(OceanGenerator.GetMap()); //Start the simulation StartCoroutine(SimulateCavePattern()); }
// Launches the generation of the specified water body (or all of them if index = -1). public void RecalculateWaterBodies(int index = -1) { // Reset all roads, since roads will have to be recalculated after any water body change. foreach (RoadGenerator thread in roadThreads.Values) thread.Abort (); roadThreads.Clear (); if (roadsCoroutine != null) { StopCoroutine (roadsCoroutine); roadsCoroutine = null; } for (int i = ((index < 0) ? 0 : index); i < ((index < 0) ? waterBodiesDefinitionData.Count : (index + 1)); i++) { if (waterBodiesThreads.ContainsKey (i)) // If thread for this water body is running, substitute it. waterBodiesThreads[i].Abort (); Vector3 origin = waterBodiesDefinitionData [i]; WaterBodyGenerator thread; if (origin.y >= 0f) thread = new OceanGenerator (new Vector2 (origin.x, origin.z), origin.y); else thread = new RiverGenerator (new Vector2 (origin.x, origin.z)); thread.Start (); waterBodiesThreads[i] = thread; } // If the coroutine is already launch, no change is needed, since it will check for all currently running threads. if (waterBodiesCoroutine == null) waterBodiesCoroutine = StartCoroutine (WaitForWaterBodyThreads()); }