void Awake() { //First we will create our map using the parameters we have set createdMap = BlockUtilities.CreateBlockMap(mapName, tileSize, chunkWidth, chunkHeight, growthAxis); //Now we will create a big old block of cubes, according to the dimensions we've set above for (int x = 0; x < levelWidth; x++) { for (int y = 0; y < levelWidth; y++) { for (int z = 0; z < levelDepth; z++) { //We instantiate the block outside of the BlockUtilites library //I've made it this way to allow you to pool GameObjects or anything you like //So you have control over where your blocks come from Block b = GameObject.Instantiate(blockPrefab) as Block; //Now we add the block to the map at the desired coordinates //We won't randomise or refresh at this point, as we're creating a large map //We will do that as one call later BlockUtilities.AddBlockToMap(createdMap, b, false, 0, false, x, y, z, false, true); } } } //Now that our map has been created, we will refresh it //Refreshing your map sets your blocks to orient correctly //And gives you an opportunity to randomise your variants en'masse BlockUtilities.RefreshMap(createdMap, randomiseInitialMap); }
//Generate our map public void GenerateMap(int width, int height, int depth, string mapName, Vector3 tileScale, int chunkWidth, int chunkHeight, BlockMap.GrowthAxis growthAxis, float deleteUpdateRate, float createUpdateRate, int actionsPerPass) { this.deleteRate = deleteUpdateRate; this.createRate = createUpdateRate; this.actionsPerPass = actionsPerPass; if (this.blockMap == null) { InitializeStreamingMap(width, height, depth); this.blockMap = BlockUtilities.CreateBlockMap(mapName, tileScale, chunkWidth, chunkHeight, growthAxis); } }
//We'll construct the map here void ConstructLevel() { bool[,] map = GetLevelMap(levelWidth, levelHeight); //We'll go ahead and create our map now createdMap = BlockUtilities.CreateBlockMap(mapName, tileSize, chunkWidth, chunkHeight, growthAxis); //We're just going to iterate through the level we got back from the //function (trusting that it's correctly sized) for (int x = 0; x < levelWidth; x++) { for (int y = 0; y < levelHeight; y++) { if (map[x, y]) { Block b = GameObject.Instantiate(blockPrefab) as Block; //We'll add our instantiated block here //And we will not refresh just yet - //it's better to refresh and clean at the end BlockUtilities.AddBlockToMap(createdMap, b, false, 0, false, x, y, 0, false, false); } else { if (useEmptyBlocks) { BlockUtilities.AddBlockToMap(createdMap, null, false, 0, false, x, y, 0, false, true); } } } } //And now we refresh our map BlockUtilities.RefreshMap(createdMap, randomiseInitialMap); //Done! //Enjoy! }