/** * This is the main function called when on geoTimeScale. * Add here the list of things that should happen while on this mode. */ private void geoTimeTerrainMod() { for (int i = 0; i < mountainSpots.Count; i++) { MountainSeed sp = mountainSpots[i]; sp.applyToTerrain(); } if (updateTexturesOnGeo) { applyTexture(); } if (updateBasinsOnGeo) { for (int l = waterSpots.Count, i = 0; i < l; i++) { waterSpots[i].updateHeight(); } } if (riverErosionOnGeo) { RiverErode(); } }
public void Generate() { Debug.Log("Generate!"); targetTilemap.ClearAllTiles(); targetTilemap.SetTile(new Vector3Int(size.x - 1, size.y - 1, 0), field); targetTilemap.BoxFill(Vector3Int.zero, field, 0, 0, size.x - 1, size.y - 1); List <MountainSeed> mountain_seeds = new List <MountainSeed>(); List <SeaSeed> sea_seeds = new List <SeaSeed>(); List <ForestSeed> forest_seeds = new List <ForestSeed>(); // 山の種を作る。 for (int i = 0; i < mountainSeedCount; ++i) { int x = Random.Range(2, size.x); int y = Random.Range(2, size.y); var new_seed = new MountainSeed(); new_seed.position.x = x; new_seed.position.y = y; new_seed.influence = Random.Range(2, 8); mountain_seeds.Add(new_seed); } // 森の種を作る for (int i = 0; i < seaSeedCount; ++i) { int x = Random.Range(2, size.x); int y = Random.Range(2, size.y); var new_seed = new ForestSeed(); new_seed.position.x = x; new_seed.position.y = y; new_seed.influence = Random.Range(2, 4); forest_seeds.Add(new_seed); } // 湖の種を作る for (int i = 0; i < seaSeedCount; ++i) { int x = Random.Range(2, size.x); int y = Random.Range(2, size.y); var new_seed = new SeaSeed(); new_seed.position.x = x; new_seed.position.y = y; new_seed.influence = Random.Range(2, 8); sea_seeds.Add(new_seed); } // 山を成長させる。 for (int i = 0; i < mountain_seeds.Count; ++i) { var seed = mountain_seeds[i]; Elevation(seed.position.x, seed.position.y, seed.influence); } // 森を成長させる。 for (int i = 0; i < forest_seeds.Count; ++i) { var seed = forest_seeds[i]; Sprout(seed.position.x, seed.position.y, seed.influence); } // 川を成長させます for (int i = 0; i < sea_seeds.Count; ++i) { var seed = sea_seeds[i]; Erosion(seed.position.x, seed.position.y, seed.influence); } // プレイヤーの初期位置を設定します(マップの真ん中) player.SetTilemap(targetTilemap); player.SetPlayerPosition(new Vector2Int(size.x / 2, size.y / 2)); for (int x = 0; x < town.Length; ++x) { targetTilemap.SetTile(new Vector3Int(size.x / 2 + x, size.y / 2, 0), town[x]); targetTilemap.SetTransformMatrix(new Vector3Int(size.x / 2 + x, size.y / 2, 0), Matrix4x4.identity); } }
// ██╗ ██╗██████╗ ██████╗ █████╗ ████████╗███████╗ // ██║ ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝ // ██║ ██║██████╔╝██║ ██║███████║ ██║ █████╗ // ██║ ██║██╔═══╝ ██║ ██║██╔══██║ ██║ ██╔══╝ // ╚██████╔╝██║ ██████╔╝██║ ██║ ██║ ███████╗ // ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ // Update is called once per frame void Update() { // Pre-update state-based vars frame++; // KEYBOARD INTERACTION if (Input.GetKeyDown(KeyCode.G)) { riverGizmos = !riverGizmos; } // Toggle geological time scale on right mouse click if (Input.GetKeyDown(KeyCode.T)) { toggleGeoTime(); if (geoTimeScale) { storeCurrentPosition(); enableCursor(false); } else { resetPrevPosition(); enableCursor(true); } toggleMainCamera(); } // Change to Terraform mode if (Input.GetKeyDown(KeyCode.P)) { cursorMode = TERRAFORM; } // Change to Mountain mode if (Input.GetKeyDown(KeyCode.M)) { cursorMode = MOUNTAIN; } // Change to Water mode if (Input.GetKeyDown(KeyCode.F)) { cursorMode = WATER; } // Force Erode if (Input.GetKey(KeyCode.E)) { switch (ErosionType) { case (ET.steepness): SteepnessErode(); break; case (ET.wind): WindErode(); break; case (ET.gradientDescent): GradientErode(); break; } } // Recompute textures on ErodeUP if (Input.GetKeyUp(KeyCode.E)) { applyTexture(); } // MOUSE INTERACTIONS // Perform human actions if applicable (disabled for geotime mode) if (humanActions && !geoTimeScale) { // Calculate terrain cursor position RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); bool wasHit = Physics.Raycast(ray, out hit); Vector3 targetPos = new Vector3(hit.point.x, hit.point.y + 5f, hit.point.z); cursorProjector.transform.position = targetPos; // MOUSE BUTTON DOWN if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) { switch (cursorMode) { // set mountain seeds case MOUNTAIN: MountainSeed ms = new MountainSeed(this, hit.point, pullRadius); if (wasHit) { mountainSpots.Add(ms); } if (debugLogs) { Debug.Log(ms.ToString()); } break; case WATER: WaterSeed ws = new WaterSeed(this, hit.point, pullRadius); if (wasHit) { waterSpots.Add(ws); } if (debugLogs) { Debug.Log(ws.ToString()); } break; } } // MOUSE BUTTON HELD DOWN // If any mouse button is pressed, perform actions based on cursorMode if (Input.GetMouseButton(0) || Input.GetMouseButton(1)) { switch (cursorMode) { // push/pull terrain case TERRAFORM: if (wasHit) { humanPullTerrain(hit.point, Input.GetMouseButton(0)); } break; } } // Apply textures on human terraforming mouse up if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1)) { switch (cursorMode) { // push/pull terrain case TERRAFORM: if (wasHit) { //applyTexture(); } break; } } // If scrollwheel, update pullRadius and cursorProjector float wheel = Input.GetAxis("Mouse ScrollWheel"); if (wheel != 0) { pullRadius *= wheel > 0 ? wheelIncrement : (1 / wheelIncrement); cursorProjector.orthographicSize = pullRadius; } } // If on geoTimeScale, what to do if (geoTimeScale) { year += 1000; // Update GUI elements labelContent.text = "Year " + year.ToString() + "..."; // Call the main function with terrain modifications for this mode geoTimeTerrainMod(); } if (Input.GetKeyDown(KeyCode.R)) { resetTerrain(); } }
// ██╗ ██╗██████╗ ██████╗ █████╗ ████████╗███████╗ // ██║ ██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝ // ██║ ██║██████╔╝██║ ██║███████║ ██║ █████╗ // ██║ ██║██╔═══╝ ██║ ██║██╔══██║ ██║ ██╔══╝ // ╚██████╔╝██║ ██████╔╝██║ ██║ ██║ ███████╗ // ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ // Update is called once per frame void Update() { // Pre-update state-based vars frame++; // KEYBOARD INTERACTION if (Input.GetKeyDown (KeyCode.G)) { riverGizmos = !riverGizmos; } // Toggle geological time scale on right mouse click if (Input.GetKeyDown(KeyCode.T)) { toggleGeoTime(); if (geoTimeScale) { storeCurrentPosition(); enableCursor(false); } else { resetPrevPosition(); enableCursor(true); } toggleMainCamera(); } // Change to Terraform mode if (Input.GetKeyDown (KeyCode.P)) { cursorMode = TERRAFORM; } // Change to Mountain mode if (Input.GetKeyDown (KeyCode.M)) { cursorMode = MOUNTAIN; } // Change to Water mode if (Input.GetKeyDown (KeyCode.F)) { cursorMode = WATER; } // Force Erode if (Input.GetKey(KeyCode.E)){ switch(ErosionType) { case(ET.steepness): SteepnessErode(); break; case(ET.wind): WindErode(); break; case(ET.gradientDescent): GradientErode(); break; } } // Recompute textures on ErodeUP if (Input.GetKeyUp(KeyCode.E)) { applyTexture (); } // MOUSE INTERACTIONS // Perform human actions if applicable (disabled for geotime mode) if (humanActions && !geoTimeScale) { // Calculate terrain cursor position RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); bool wasHit = Physics.Raycast(ray, out hit); Vector3 targetPos = new Vector3(hit.point.x, hit.point.y + 5f, hit.point.z); cursorProjector.transform.position = targetPos; // MOUSE BUTTON DOWN if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) { switch(cursorMode) { // set mountain seeds case MOUNTAIN: MountainSeed ms = new MountainSeed(this, hit.point, pullRadius); if (wasHit) mountainSpots.Add(ms); if (debugLogs) Debug.Log(ms.ToString()); break; case WATER: WaterSeed ws = new WaterSeed(this, hit.point, pullRadius); if (wasHit) waterSpots.Add(ws); if (debugLogs) Debug.Log(ws.ToString()); break; } } // MOUSE BUTTON HELD DOWN // If any mouse button is pressed, perform actions based on cursorMode if (Input.GetMouseButton(0) || Input.GetMouseButton (1)) { switch(cursorMode) { // push/pull terrain case TERRAFORM: if(wasHit) { humanPullTerrain(hit.point, Input.GetMouseButton(0)); } break; } } // Apply textures on human terraforming mouse up if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp (1)) { switch(cursorMode) { // push/pull terrain case TERRAFORM: if(wasHit) { //applyTexture(); } break; } } // If scrollwheel, update pullRadius and cursorProjector float wheel = Input.GetAxis("Mouse ScrollWheel"); if (wheel != 0) { pullRadius *= wheel > 0 ? wheelIncrement : ( 1/ wheelIncrement); cursorProjector.orthographicSize = pullRadius; } } // If on geoTimeScale, what to do if (geoTimeScale) { year += 1000; // Update GUI elements labelContent.text = "Year " + year.ToString() + "..."; // Call the main function with terrain modifications for this mode geoTimeTerrainMod(); } if (Input.GetKeyDown (KeyCode.R)) { resetTerrain(); } }