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; }