public void loadMap() { Dictionary <Vector2, float> terraforms = GameObject.Find("TerraformController").GetComponent <DropTerraform>().terraforms; terraforms.Clear(); string text = SaveAndLoadManager.getInstance().loadText(key); string[] lines = text.Split('\n'); Regex terraformSegment = new Regex(@"\d+,\d+\/\d+"); foreach (string line in lines) { //Has Block if (terraformSegment.IsMatch(line)) { Vector2 position = Vector2.zero; position.x = int.Parse(line.Substring(0, line.IndexOf(','))); string rest = line.Substring(line.IndexOf(',') + 1); position.y = int.Parse(rest.Substring(0, rest.IndexOf('/'))); rest = rest.Substring(rest.IndexOf('/') + 1); float height = float.Parse(rest); terraforms.Add(position, height); } } TerraformRenderer.RenderAll(terraforms); }
void Start() { eventSys = EventSystem.current; terraforms = new Dictionary <Vector2, float>(); terraformPutThisClick = new List <List <KeyValuePair <Vector2, float> > >(); TerraformRenderer.RenderAll(terraforms); seed = new System.Random().Next(9000) + 1000; guidance = GameObject.Find("TerraformGuider"); }
void Update() { if (Input.GetKeyDown(KeyCode.Z)) { if (terraformPutThisClick.Count > 0) { for (int i = 0; i < terraformPutThisClick[0].Count; i++) { } terraformPutThisClick.RemoveAt(0); TerraformRenderer.RenderAll(terraforms); } return; } if (eventSys.IsPointerOverGameObject()) { return; } if (Input.GetMouseButtonDown(0)) { if (terraformPutThisClick.Count >= 10) { terraformPutThisClick.RemoveAt(9); } terraformPutThisClick.Insert(0, new List <KeyValuePair <Vector2, float> >()); } Ray cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit floorHit; float camRayLength = 300f; if (Physics.Raycast(cameraRay, out floorHit, camRayLength, LayerMask.GetMask("Floor"))) { Vector3 a = floorHit.point; guidance.transform.position = a + Vector3.up * 100; Projector projector = guidance.GetComponent <Projector>(); projector.orthographicSize = (float)diameter / 2; TerraformController tfc = TerraformController.getInstance(); if (tfc.tool == TerraformController.SMOOTH || tfc.tool == TerraformController.AUTO || tfc.tool == TerraformController.RESET) { projector.material.SetTexture("_ShadowTex", square); } else { projector.material.SetTexture("_ShadowTex", circle); } //Bugfix for dragging from UI to game. if (terraformPutThisClick == null || terraformPutThisClick.Count == 0) { return; } if (Input.GetMouseButton(0)) { for (int i = 0; i < diameter; i++) { for (int j = 0; j < diameter; j++) { Vector2 b = new Vector2(); b.x = (int)(a.x) - Mathf.Round(diameter / 2f) + i; b.y = (int)(a.z) - Mathf.Round(diameter / 2f) + j; if (blockIsInsideBounds(b)) { Vector2 a2 = new Vector2(a.x, a.z); float height = CalculateNewHeight(new Vector2((int)b.x, (int)b.y), diameter, Vector2.Distance(a2, b), strength); height = Mathf.Clamp(height, 1, ChunkMap.SizeY); KeyValuePair <Vector2, float> kvp = new KeyValuePair <Vector2, float>(new Vector2((int)b.x, (int)b.y), height); if (terraforms.ContainsKey(kvp.Key)) { terraforms[kvp.Key] = kvp.Value; } else { terraforms.Add(kvp.Key, kvp.Value); } terraformPutThisClick[0].Add(kvp); } } } TerraformRenderer.RenderAll(terraforms); } } }