private void OnGUI() { if (Input.GetKeyDown(KeyCode.Return)) { archipelagoMap = ArchipelagoTextureGenerator.GenerateTexture(regions, width, height, waterRate); } if (showMap) { GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), archipelagoMap, ScaleMode.ScaleToFit); } }
void Generate() { if (!Mathf.IsPowerOfTwo(width) || !Mathf.IsPowerOfTwo(height)) { Debug.LogError("ARCHIPELAGO SIZE IS NOT A POWER OF TWO. --- STOPPING GENERATION ---"); return; } archipelagoMap = ArchipelagoTextureGenerator.GenerateTexture(regions, width, height, waterRate); archipelago = new GameObject("Archipelago").GetComponent <Transform>(); gameObject.AddComponent <ChunkSerialization>(); ChunkSerialization.Reset(); ChunkSerialization.chunkSize = regionSize; ChunkSerialization.viewer = player; Color[] colorMap = archipelagoMap.GetPixels(); for (int z = 0; z < height; z++) { for (int x = 0; x < width; x++) { int index = (width * z) + x; Vector3 pos = new Vector3(x - Mathf.RoundToInt(width / 2), 0, z - Mathf.RoundToInt(height / 2)) * regionSize; GameObject obj; foreach (Region r in regions) { if (Mathf.Abs(r.color.r - colorMap[index].r) <= 0.009f) { obj = Instantiate(r.region, pos, Quaternion.identity, archipelago); ChunkSerialization.chunks.Add(pos / regionSize, new ChunkSerialization.TerrainChunk(pos, obj)); } } } } Destroy(this); }