void CreatGround() { if (!groundFolder) { groundFolder = new GameObject(); groundFolder.transform.position = Vector3.zero; groundFolder.name = "GroundFolder"; checker.Clear(); } else { foreach (GameObject obj in checker) { DestroyImmediate(obj); } checker.Clear(); } int cell = cellByLenghtChecker + 1; int index = 0; for (int y = 0; y < checkerOnTheHeight; y++) { for (int x = 0; x < checkerOnTheLenght; x++) { checker.Add(new GameObject()); checker[index].transform.parent = groundFolder.transform; checker[index].name = "" + nameMap + " " + index; GroundBaseGenerator groundScript = checker[index].AddComponent <GroundBaseGenerator>(); groundScript.NumberCellByLenght = cell; groundScript.Density = cellDensity; if (!skinLoadGroundVue) { groundScript.HeightChecker = new HeightGround(); height.Add(groundScript.HeightChecker); groundScript.HeightChecker.InitialisationRowArray(cell - 1); } else { groundScript.HeightChecker = height[index]; } groundScript.GenerateGroundBase(); groundScript.IndexInTheCheckboard = index; checker[index].transform.position = new Vector3(x * cellByLenghtChecker, 0, y * cellByLenghtChecker); checker[index].GetComponent <MeshRenderer>().material = CheckerMaterial; index++; } } CalculateHeightBorder(); ApplyVertexColor(); groundCreat = true; }
void ApplyVertexColor() { foreach (GameObject obj in checker) { GroundBaseGenerator ground = obj.GetComponent <GroundBaseGenerator>(); ground.RedColorByHeight = vertexColorRedValue; ground.GreenColorByHeight = vertexColorGreenValue; ground.BlueColorByHeight = vertexColorBlueValue; ground.GenerateGroundBase(); } }
/// <summary> /// Rebuild and modify all checker /// </summary> void RebuildAndModifyChecker() { #region Cell foreach (GameObject obj in checker) { GroundBaseGenerator script = obj.GetComponent <GroundBaseGenerator>(); script.NumberCellByLenght = cellByLenghtChecker + 1; script.Density = cellDensity; script.HeightChecker.NewRowArray(cellByLenghtChecker); script.GenerateGroundBase(); } #endregion #region Checker int newNumberCheckerIncreaseOnTheLenght = checkerOnTheLenght - initCheckerOnTheLenght;//2-4 if (newNumberCheckerIncreaseOnTheLenght > 0) { int indexCheckerOnTheLenghtPos = initCheckerOnTheLenght;//2 for (int y = 0; y < initCheckerOnTheHeight; y++) { if (y != 0) { indexCheckerOnTheLenghtPos += initCheckerOnTheLenght + newNumberCheckerIncreaseOnTheLenght; } for (int x = 0; x < newNumberCheckerIncreaseOnTheLenght; x++) { checker.Insert(indexCheckerOnTheLenghtPos + x, new GameObject()); GameObject newChecker = checker[indexCheckerOnTheLenghtPos + x]; newChecker.transform.parent = groundFolder.transform; newChecker.name = "Extended Checker" + (indexCheckerOnTheLenghtPos + x); GroundBaseGenerator script = newChecker.AddComponent <GroundBaseGenerator>(); script.NumberCellByLenght = cellByLenghtChecker + 1; script.Density = cellDensity; script.HeightChecker = new HeightGround(); script.HeightChecker.InitialisationRowArray(cellByLenghtChecker); //script.GenerateGroundBase(); newChecker.GetComponent <MeshRenderer>().material = CheckerMaterial; } } } else if (newNumberCheckerIncreaseOnTheLenght < 0) { int absNewNumberCheckerIncreaseOnTheLenght = Mathf.Abs(newNumberCheckerIncreaseOnTheLenght); int initialSizeArrayChecker = checker.Count; for (int y = 0; y < initCheckerOnTheHeight; y++) { if (y != 0) { initialSizeArrayChecker -= checkerOnTheLenght; } for (int x = 0; x < absNewNumberCheckerIncreaseOnTheLenght; x++) { initialSizeArrayChecker -= 1; DestroyImmediate(checker[initialSizeArrayChecker]); checker.RemoveAt(initialSizeArrayChecker); } } } int newNumberCheckerIncreaseOnTheHeight = checkerOnTheHeight - initCheckerOnTheHeight;//2-4 if (newNumberCheckerIncreaseOnTheHeight > 0) { for (int y = 0; y < newNumberCheckerIncreaseOnTheHeight; y++) { for (int x = 0; x < checkerOnTheLenght; x++) { checker.Add(new GameObject()); GameObject newChecker = checker[checker.Count - 1]; newChecker.transform.parent = groundFolder.transform; newChecker.name = "Extended Checker" + checker.Count; GroundBaseGenerator script = newChecker.AddComponent <GroundBaseGenerator>(); script.NumberCellByLenght = cellByLenghtChecker + 1; script.Density = cellDensity; script.HeightChecker = new HeightGround(); script.HeightChecker.InitialisationRowArray(cellByLenghtChecker); //script.GenerateGroundBase(); newChecker.GetComponent <MeshRenderer>().material = CheckerMaterial; } } } else if (newNumberCheckerIncreaseOnTheHeight < 0) { int absNewNumberCheckerIncreaseOnTheHeight = Mathf.Abs(newNumberCheckerIncreaseOnTheHeight); for (int y = 0; y < absNewNumberCheckerIncreaseOnTheHeight; y++) { for (int x = 0; x < checkerOnTheLenght; x++) { DestroyImmediate(checker[checker.Count - 1]); checker.RemoveAt(checker.Count - 1); } } } CalculateHeightBorder(); RebuildAllGround(); #endregion #region Placement int index = 0; for (int y = 0; y < checkerOnTheHeight; y++) { for (int x = 0; x < checkerOnTheLenght; x++) { checker[index].transform.position = new Vector3(x * (cellByLenghtChecker), 0, y * (cellByLenghtChecker)); index++; } } #endregion }