void OnGUI() { //use the terrain selected in the popup menu, gotta love unityGUI syntax Terrain selectedTerrain = m_terrains[EditorGUILayout.Popup(0, m_terrainNames)]; if (m_heightField != null) { EditorGUILayout.ColorField("Hight Field Generated", Color.green); } else { EditorGUILayout.ColorField("Height Field Generated", Color.red); } if (GUILayout.Button("Generate Height Field")) { m_heightField = generateField(selectedTerrain); } showField = EditorGUILayout.Toggle("Display Height Field", showField); if (showField && m_heightField != null) { EditorGUI.DrawPreviewTexture(new Rect(0,300,200,200), m_heightField.getBitmap(5)); } GUILayout.BeginVertical(); if (m_heightField != null) { EditorGUILayout.LabelField("Height Points: ", m_heightField.Length.ToString()); } GUILayout.EndVertical(); }
public HeightField getHeightField(int resolution, Bounds area) { int tempLayer = setupLayer(); LayerMask mask = 1 << tempLayer; int sizeX = (int)(area.size.x); int sizeZ = (int)(area.size.z); //also known as size y but unity is y-up HeightField retval = new HeightField(resolution, sizeX, sizeZ); for (float x = 0; x < retval.GetLength(0); x+= (1/(float)resolution)) { for (float y = 0; y < retval.GetLength(1); y+=(1/(float)resolution)) { float maxHeight = area.size.y; RaycastHit info; Ray ray = new Ray(new Vector3((float)x,maxHeight,(float)y), Vector3.down); Physics.Raycast(ray, out info, mask); float height = maxHeight - info.distance; retval.getHeightAtPosition(x,y).height = height; } } return retval; }
public HeightFieldRenderer(HeightField field, Terrain terrain) { m_field = field; m_terrain = terrain; }