private static void ThreadFunction_Demo(object parentClass) { PersistentData dataClass = ((PersistentData)parentClass); TerrainBuilderReturnPacket terrainPacket_thread = TerrainBuilder.generateTerrain_DemoVer(Constants.roomWidthHeight, Constants.numOfVertsPerEdge); bool[,] boolArray_noNoise = terrainPacket_thread.getBoolArray_noNoise(); Color32[] minimapColorArray = MinimapBaseColorMaker.convertBoolArrayToMinimapColorArray(boolArray_noNoise, boolArray_noNoise.GetLength(0), boolArray_noNoise.GetLength(1)); dataClass.setLoadingData(terrainPacket_thread, minimapColorArray); }
// ------------------------------------------------------------------------------------------------------ // ----------- Terrain generation and initialization stuff: -------------------------------------------------------- // ------------------------------------------------------------------------------------------------------ private void generateTerrain() { // TerrainBuilderReturnPacket terrainPacket = TerrainBuilder.generateTerrain(Constants.roomWidthHeight, Constants.numOfVertsPerEdge); TerrainBuilderReturnPacket terrainPacket = persistentData.getTerrainPacket(); Mesh[,] terrainMeshes = terrainPacket.getTerrainMeshes(); // Mesh[,] terrainMeshes = TerrainBuilder.sliceHeightArrayIntoMultipleMeshes(terrainPacket.getHeightArray(), Constants.roomWidthHeight, Constants.numOfVertsPerEdge); boolArray = terrainPacket.getBoolArray(); persistentData.setAreaTotal(terrainPacket.getNumOfRooms()); persistentData.setKeysTotal(terrainPacket.getNumOfKeys()); persistentData.setDoorsTotal(terrainPacket.getNumOfLockedDoors()); numOfRooms_horizontal = (byte)terrainMeshes.GetLength(0); numOfRooms_vertical = (byte)terrainMeshes.GetLength(1); waterManager.setWaterSize(numOfRooms_horizontal, numOfRooms_vertical, Constants.roomWidthHeight); // color the pixels in the terrainMaterial? // Color32[] terrainColors = TerrainColorGenerator.GenerateTerrainColors(); Color32[] terrainColors = persistentData.getTerrainColors(); Texture2D terrainTexture = new Texture2D(4, 1); terrainTexture.wrapMode = TextureWrapMode.Clamp; terrainTexture.filterMode = FilterMode.Point; terrainMaterial.mainTexture = terrainTexture; //terrainTexture.SetPixel(0, 0, terrainColors[3]); terrainTexture.SetPixel(0, 0, terrainColors[0]); terrainTexture.SetPixel(1, 0, terrainColors[1]); terrainTexture.SetPixel(2, 0, terrainColors[2]); terrainTexture.SetPixel(3, 0, terrainColors[3]); terrainTexture.Apply(); //waterManager.setWaterTint(terrainColors[3]); waterManager.setWaterTint(terrainColors[0]); Debug.Log("Water color is: " + (terrainColors[0])); persistentData.setTerrainColors(terrainColors); // Instantiate the 3D terrain meshes: GameObject newTerrainParent = new GameObject("terrainParent"); MeshFilter terrainMeshFilter; MeshRenderer terrainMeshRenderer; for (int indexX = 0; indexX < numOfRooms_horizontal; indexX++) { for (int indexY = 0; indexY < numOfRooms_vertical; indexY++) { GameObject newTerrain = new GameObject("terrainPiece"); terrainMeshFilter = newTerrain.AddComponent <MeshFilter>(); terrainMeshFilter.mesh = terrainMeshes[indexX, indexY]; terrainMeshRenderer = newTerrain.AddComponent <MeshRenderer>(); terrainMeshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; terrainMeshRenderer.material = terrainMaterial; newTerrain.transform.position = new Vector3(((indexX * Constants.roomWidthHeight) - 2f * Constants.roomWidthHeight), -0.5f, ((-indexY * Constants.roomWidthHeight) + 2f * Constants.roomWidthHeight)); newTerrain.transform.parent = newTerrainParent.transform; } } // Move the player's boat to the starting location: playerBoatTransform_target.position = new Vector3((((float)terrainPacket.getPlayerStartingLocation()[0]) + 0.5f) * Constants.roomWidthHeight, 0f, (((float)terrainPacket.getPlayerStartingLocation()[1]) + 0.5f) * -Constants.roomWidthHeight); playerBoatTransform_delayed.position = playerBoatTransform_target.position; // And bookmark the first 'port town' where the player spawns: // bookmarkNewPortTownLocation(playerBoatTransform_target.position.x, playerBoatTransform_target.position.z); // Instantiate the interactables: doorHitboxManager = new DoorHitboxManager(terrainPacket.getDoorLocations(), terrainPacket.getDoorSides(), terrainPacket.getDoorColors()); // first instantiate the final treasure: interactablesManager.addObjectToArray(instantiateItem_initial(terrainPacket.getFinalTreasureLocation()[0], terrainPacket.getFinalTreasureLocation()[1], Constants.interactableID_treasureFinal), Constants.interactableID_treasureFinal, 0); // Then instantiate all the keys: byte[,] itemLocations = terrainPacket.getKeyLocations(); bool[] hasKey = terrainPacket.getHasKey(); byte[] itemIDs = { Constants.interactableID_key1, Constants.interactableID_key2, Constants.interactableID_key3, Constants.interactableID_key4, Constants.interactableID_key5, Constants.interactableID_key6 }; for (short index = 0; index < 6; index++) { if (hasKey[index]) { interactablesManager.addObjectToArray(instantiateItem_initial(itemLocations[index, 0], itemLocations[index, 1], itemIDs[index]), itemIDs[index], index); } } // then instantiate all the door prefabs: itemLocations = terrainPacket.getDoorLocations(); itemIDs = terrainPacket.getDoorColors(); byte[] doorSide = terrainPacket.getDoorSides(); for (short index = 0; index < itemIDs.Length; index++) { interactablesManager.addObjectToArray(instantiateDoor_initial(itemLocations[index, 0], itemLocations[index, 1], itemIDs[index], doorSide[index]), itemIDs[index], index); } // Now instantiate the minimap: minimapManager.initializeMinimapData(terrainPacket.getSimplePacket(), terrainPacket.getBoolArray_noNoise(), persistentData); // Now instantiate all the port towns: PortTownReturnPacket portTownPacket = terrainPacket.getPortTownPacket(); placeAllPortTowns(portTownPacket); minimapManager.setPortTownData(portTownPacket); // Instantiate the enemy manager: enemyManager.placeStartingEnemies(playerBoatTransform_target.position, boolArray, doorHitboxManager, (byte)(numOfRooms_horizontal - 3), (byte)(numOfRooms_vertical - 3), portTownPacket, persistentData.getDensityOfEnemies_value()); // Cannonball related stuff: touchManager.setArrowAndWheelColors(terrainColors[0]); cannonballManager.initializeCannonballData(boolArray, doorHitboxManager, persistentData.getDensityOfEnemies_value(), persistentData.getShipColors()[5]); }