private void GenerateIsland() { //GameObject generatorObj = new GameObject(); //IslandGenerator gen = generatorObj.AddComponent<IslandGenerator>(); GameObject islandGenPrefab = Resources.Load <GameObject>("Prefabs/IslandGenerator"); GameObject generatorObj = (GameObject)Instantiate(islandGenPrefab); IslandGenerator gen = generatorObj.GetComponent <IslandGenerator>(); GameObject[] detailObjects = new GameObject[] { Resources.Load <GameObject>(_secondSetPath + "Pine_0"), Resources.Load <GameObject>(_secondSetPath + "Pine_1"), Resources.Load <GameObject>(_secondSetPath + "Pine_2"), Resources.Load <GameObject>(_secondSetPath + "Rock_Med"), //Resources.Load<GameObject>(_secondSetPath + "Rock_Lg"), Resources.Load <GameObject>(_secondSetPath + "Flower_Bud"), //Resources.Load<GameObject>(_secondSetPath + "Bush_Sm"), Resources.Load <GameObject>(_secondSetPath + "Grass"), Resources.Load <GameObject>(_secondSetPath + "Fern"), //Resources.Load<GameObject>(_secondSetPath + "Rock_Small") }; gen._detailObjects = detailObjects; GameObject terrainObj = gen.Generate(_size, _seed, _levels); PrefabUtility.CreatePrefab("Assets/Resources/Custom Islands Generated/" + terrainObj.name + ".prefab", terrainObj); DestroyImmediate(generatorObj); DestroyImmediate(terrainObj); }
private void MakeNewIsland(IslandGenerator gen, int islandSeed, float[][] moistNoise, float[][] tempNoise) { System.Random islandPRNG = new System.Random(islandSeed); IslandSize size = DetermineIslandSize(islandPRNG.Next()); int islandSize = (int)size; int x = islandPRNG.Next(islandSize, MaxWorldSize - islandSize); int z = islandPRNG.Next(islandSize, MaxWorldSize - islandSize); Vector3 position = new Vector3(x, 0f, z); int numOfHeightLevels = islandPRNG.Next(MinNumberOfHeightLevels) + MinNumberOfHeightLevels; // dont want island with < min height levels // should check to make sure islands can't overlap each other // copy out the relevant climate noise float[][] islandSpecificMoistureData = new float[islandSize][]; float[][] islandSpecificTempData = new float[islandSize][]; //Debug.LogFormat("specific: {0}x{1}", islandSpecificBiomeData.Length, islandSpecificBiomeData[0].Length); //Debug.LogFormat("base: {0}x{1}", biomeNoise.Length, biomeNoise[0].Length); for (int i = 0; i < islandSize; ++i) { islandSpecificMoistureData[i] = new float[islandSize]; islandSpecificTempData[i] = new float[islandSize]; for (int j = 0; j < islandSize; ++j) { //Debug.LogFormat("specific -> i: {0}, j:{1}, base -> i:{2} j:{3}",i, j, i + x, j + z); islandSpecificMoistureData[i][j] = moistNoise[i + x][j + z]; islandSpecificTempData[i][j] = tempNoise[i + x][j + z]; } } Debug.LogFormat("new island at {0} of size {1} with {2} levels ({3})", position, size.ToString(), numOfHeightLevels, islandSeed); // TODO // create an island data class that will be returned from this function // should hold things like: // tile array, native species of plants/vegetables/etc, general climate, size, soil classification, ... IslandData data = gen.Generate(size, islandSeed, position, islandSpecificMoistureData, islandSpecificTempData, numOfHeightLevels); _islands.Add(data); }