private void UpdatePreviewBrush() { TerrainScript targetScript = ((TerrainScript)target); if ((targetScript.treePrototypes.Count > 0) && (previewMesh != null)) { previewMesh.UpdatePreviewMesh(targetScript.terrainData.treeInstances, targetScript.treePrototypes[0].prefab.renderer.bounds.size.y); } Vector3 normal = Vector3.zero; Vector3 hitPos = Vector3.zero; Vector2 vector; Vector3 vector2 = Vector3.zero; float m_Size = 16 * brushSize; Projector previewProjector = currentTextureBrush.GetPreviewProjector(); float num = 1f; float num2 = mixMap.width / mixMap.height; Vector2 size = targetScript.getSizeOfMesh(); // terrain.getSizeOfMesh(); int terrainSizeX = (int)size.x; int terrainSizeZ = (int)size.y; Transform PPtransform = previewProjector.transform; bool flag = true; Vector2 newMousePostion = Event.current.mousePosition; newMousePostion.y = Screen.height - (Event.current.mousePosition.y + 35); Ray ray = Camera.current.ScreenPointToRay(newMousePostion); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000f)) { vector2 = hit.point; hitPos = hit.point; normal = hit.normal; float num4 = ((m_Size % 2) != 0) ? 0.5f : 0f; int alphamapWidth = 64; int alphamapHeight = 64; vector.x = (Mathf.Floor(hit.textureCoord.x * alphamapWidth) + num4) / ((float)alphamapWidth); vector.y = (Mathf.Floor(hit.textureCoord.y * alphamapHeight) + num4) / ((float)alphamapHeight); vector2.x = vector.x * -terrainSizeX + (terrainSizeX / 2); vector2.z = vector.y * -terrainSizeZ + (terrainSizeZ / 2); vector2 += Selection.activeGameObject.transform.position; num = ((m_Size * 0.5f) / ((float)alphamapWidth)) * terrainSizeX; num2 = ((float)alphamapWidth) / ((float)alphamapHeight); } else { flag = false; } previewProjector.enabled = flag; if (flag) { PPtransform.position = hitPos + (normal * 100); PPtransform.rotation = Quaternion.LookRotation(normal); } previewProjector.orthographicSize = num / num2; previewProjector.aspectRatio = num2; }
public static void PlaceTrees(TerrainScript terrain, Vector3 position, Vector3 normal, int selectedTree) { if (terrain.treePrototypes.Count != 0) { if (true) { int num = 0; MyTreeInstance instance = new MyTreeInstance(); instance.position = position; instance.rotation = GetTreeRotation(normal); instance.color = GetTreeColor(); instance.lightmapColor = Color.white; instance.prototypeIndex = selectedTree; instance.widthScale = GetTreeWidth(); instance.heightScale = GetTreeHeight(); if (((Event.current.type != EventType.MouseDrag) && (brushSize <= 1f)) || TerrainFunctions.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, spacing)) { terrain.AddTreeInstance(instance); num++; } Vector3 prototypeExtent = Vector3.one; prototypeExtent.y = 0f; float num2 = brushSize / ((prototypeExtent.magnitude * spacing) * 0.5f); int num3 =(int) ((num2 * num2) * 0.5f); num3 = Mathf.Clamp(num3, 0, 100); for (int i = 1; (i < num3) && (num < num3); i++) { Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle; insideUnitCircle.x *= (brushSize*100) / terrain.getSizeOfMesh().x; insideUnitCircle.y *= (brushSize*100) / terrain.getSizeOfMesh().y; Vector3 off = new Vector3(insideUnitCircle.x, 0, insideUnitCircle.y); Vector3 pos = Vector3.Cross(normal, off); Vector3 position2 = position + pos; Vector3 nom = position2 - (position2 + normal*10); Ray ray = new Ray(position2, nom); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { //if (terrain.isInsideOfBounds(position2)) { if (true) { if (TerrainFunctions.CheckTreeDistance(terrain.terrainData, hit.point, instance.prototypeIndex, spacing)) { instance = new MyTreeInstance(); instance.position = hit.point; instance.rotation = GetTreeRotation(hit.normal); instance.color = GetTreeColor(); instance.lightmapColor = Color.white; instance.prototypeIndex = selectedTree; instance.widthScale = GetTreeWidth(); instance.heightScale = GetTreeHeight(); terrain.AddTreeInstance(instance); num++; } } } } } } }
public static void PlaceTrees(TerrainScript terrain, Vector3 position, Vector3 normal, int selectedTree) { if (terrain.treePrototypes.Count != 0) { if (true) { int num = 0; MyTreeInstance instance = new MyTreeInstance(); instance.position = position; instance.rotation = GetTreeRotation(normal); instance.color = GetTreeColor(); instance.lightmapColor = Color.white; instance.prototypeIndex = selectedTree; instance.widthScale = GetTreeWidth(); instance.heightScale = GetTreeHeight(); if (((Event.current.type != EventType.MouseDrag) && (brushSize <= 1f)) || TerrainFunctions.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, spacing)) { terrain.AddTreeInstance(instance); num++; } Vector3 prototypeExtent = Vector3.one; prototypeExtent.y = 0f; float num2 = brushSize / ((prototypeExtent.magnitude * spacing) * 0.5f); int num3 = (int)((num2 * num2) * 0.5f); num3 = Mathf.Clamp(num3, 0, 100); for (int i = 1; (i < num3) && (num < num3); i++) { Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle; insideUnitCircle.x *= (brushSize * 100) / terrain.getSizeOfMesh().x; insideUnitCircle.y *= (brushSize * 100) / terrain.getSizeOfMesh().y; Vector3 off = new Vector3(insideUnitCircle.x, 0, insideUnitCircle.y); Vector3 pos = Vector3.Cross(normal, off); Vector3 position2 = position + pos; Vector3 nom = position2 - (position2 + normal * 10); Ray ray = new Ray(position2, nom); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { //if (terrain.isInsideOfBounds(position2)) { if (true) { if (TerrainFunctions.CheckTreeDistance(terrain.terrainData, hit.point, instance.prototypeIndex, spacing)) { instance = new MyTreeInstance(); instance.position = hit.point; instance.rotation = GetTreeRotation(hit.normal); instance.color = GetTreeColor(); instance.lightmapColor = Color.white; instance.prototypeIndex = selectedTree; instance.widthScale = GetTreeWidth(); instance.heightScale = GetTreeHeight(); terrain.AddTreeInstance(instance); num++; } } } } } } }