public static void MassPlaceTrees(TerrainData terrainData, int numberOfTrees, bool randomTreeColor, bool keepExistingTrees) { int length = terrainData.treePrototypes.Length; if (length == 0) { Debug.Log("Can't place trees because no prototypes are defined"); } else { Undo.RegisterCompleteObjectUndo(terrainData, "Mass Place Trees"); TreeInstance[] sourceArray = new TreeInstance[numberOfTrees]; int num2 = 0; while (num2 < sourceArray.Length) { TreeInstance instance = new TreeInstance { position = new Vector3(UnityEngine.Random.value, 0f, UnityEngine.Random.value) }; if (terrainData.GetSteepness(instance.position.x, instance.position.z) < 30f) { instance.color = !randomTreeColor ? Color.white : GetTreeColor(); instance.lightmapColor = Color.white; instance.prototypeIndex = UnityEngine.Random.Range(0, length); instance.heightScale = GetTreeHeight(); instance.widthScale = !lockWidthToHeight ? GetTreeWidth() : instance.heightScale; instance.rotation = GetTreeRotation(); sourceArray[num2++] = instance; } } if (keepExistingTrees) { TreeInstance[] treeInstances = terrainData.treeInstances; TreeInstance[] destinationArray = new TreeInstance[treeInstances.Length + sourceArray.Length]; Array.Copy(treeInstances, 0, destinationArray, 0, treeInstances.Length); Array.Copy(sourceArray, 0, destinationArray, treeInstances.Length, sourceArray.Length); sourceArray = destinationArray; } terrainData.treeInstances = sourceArray; terrainData.RecalculateTreePositions(); } }
public static void MassPlaceTrees(TerrainData terrainData, int numberOfTrees, bool randomTreeColor, bool keepExistingTrees) { int length = terrainData.treePrototypes.Length; if (length == 0) { Debug.Log((object) "Can't place trees because no prototypes are defined"); } else { Undo.RegisterCompleteObjectUndo((UnityEngine.Object) terrainData, "Mass Place Trees"); TreeInstance[] treeInstanceArray1 = new TreeInstance[numberOfTrees]; int num = 0; while (num < treeInstanceArray1.Length) { TreeInstance treeInstance = new TreeInstance(); treeInstance.position = new Vector3(UnityEngine.Random.value, 0.0f, UnityEngine.Random.value); if ((double) terrainData.GetSteepness(treeInstance.position.x, treeInstance.position.z) < 30.0) { treeInstance.color = (Color32) (!randomTreeColor ? Color.white : TreePainter.GetTreeColor()); treeInstance.lightmapColor = (Color32) Color.white; treeInstance.prototypeIndex = UnityEngine.Random.Range(0, length); treeInstance.heightScale = TreePainter.GetTreeHeight(); treeInstance.widthScale = !TreePainter.lockWidthToHeight ? TreePainter.GetTreeWidth() : treeInstance.heightScale; treeInstance.rotation = TreePainter.GetTreeRotation(); treeInstanceArray1[num++] = treeInstance; } } if (keepExistingTrees) { TreeInstance[] treeInstances = terrainData.treeInstances; TreeInstance[] treeInstanceArray2 = new TreeInstance[treeInstances.Length + treeInstanceArray1.Length]; Array.Copy((Array) treeInstances, 0, (Array) treeInstanceArray2, 0, treeInstances.Length); Array.Copy((Array) treeInstanceArray1, 0, (Array) treeInstanceArray2, treeInstances.Length, treeInstanceArray1.Length); treeInstanceArray1 = treeInstanceArray2; } terrainData.treeInstances = treeInstanceArray1; terrainData.RecalculateTreePositions(); } }
public static void MassPlaceTrees(TerrainData terrainData, int numberOfTrees, bool randomTreeColor, bool keepExistingTrees) { int num = terrainData.treePrototypes.Length; if (num == 0) { Debug.Log("Can't place trees because no prototypes are defined"); return; } Undo.RegisterCompleteObjectUndo(terrainData, "Mass Place Trees"); TreeInstance[] array = new TreeInstance[numberOfTrees]; int i = 0; while (i < array.Length) { TreeInstance treeInstance = default(TreeInstance); treeInstance.position = new Vector3(UnityEngine.Random.value, 0f, UnityEngine.Random.value); if (terrainData.GetSteepness(treeInstance.position.x, treeInstance.position.z) < 30f) { treeInstance.color = ((!randomTreeColor) ? Color.white : TreePainter.GetTreeColor()); treeInstance.lightmapColor = Color.white; treeInstance.prototypeIndex = UnityEngine.Random.Range(0, num); treeInstance.heightScale = TreePainter.GetTreeHeight(); treeInstance.widthScale = ((!TreePainter.lockWidthToHeight) ? TreePainter.GetTreeWidth() : treeInstance.heightScale); treeInstance.rotation = TreePainter.GetTreeRotation(); array[i++] = treeInstance; } } if (keepExistingTrees) { TreeInstance[] treeInstances = terrainData.treeInstances; TreeInstance[] array2 = new TreeInstance[treeInstances.Length + array.Length]; Array.Copy(treeInstances, 0, array2, 0, treeInstances.Length); Array.Copy(array, 0, array2, treeInstances.Length, array.Length); array = array2; } terrainData.treeInstances = array; terrainData.RecalculateTreePositions(); }