public void AddMeshRenderer(GameObject go, TerrainSourceID terrainSourceID) { MeshRenderer[] meshRenderers = go.GetComponentsInChildren <MeshRenderer>(); for (int i = 0; i <= meshRenderers.Length - 1; i++) { if (Filterlods) { if (meshRenderers[i].name.ToUpper().Contains("LOD1")) { continue; } if (meshRenderers[i].name.ToUpper().Contains("LOD2")) { continue; } if (meshRenderers[i].name.ToUpper().Contains("LOD3")) { continue; } } var newMeshTerrainTerrainSource = new MeshTerrainMeshSource() { MeshRenderer = meshRenderers[i], TerrainSourceID = terrainSourceID, MaterialPropertyBlock = new MaterialPropertyBlock() }; MeshTerrainMeshSourceList.Add(newMeshTerrainTerrainSource); } NeedGeneration = true; }
void DrawDebuginfo() { if (ShowDebugInfo) { for (int i = 0; i <= MeshTerrainMeshSourceList.Count - 1; i++) { if (MeshTerrainMeshSourceList[i].MaterialPropertyBlock == null) { MeshTerrainMeshSource meshTerrainMeshSource = MeshTerrainMeshSourceList[i]; meshTerrainMeshSource.MaterialPropertyBlock = new MaterialPropertyBlock(); MeshTerrainMeshSourceList[i] = meshTerrainMeshSource; } DrawMeshRenderer(MeshTerrainMeshSourceList[i].MeshRenderer, MeshTerrainMeshSourceList[i].MaterialPropertyBlock, MeshTerrainMeshSourceList[i].TerrainSourceID); } } }
void DrawSourceInspector() { GUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Add terrain sources", LabelStyle); bool addMesh = false; GUILayout.BeginHorizontal(); DropZoneTools.DrawMeshTerrainDropZone(DropZoneType.MeshRenderer, _meshTerrain, ref addMesh); //DropZoneTools.DrawMeshTerrainDropZone(DropZoneType.Terrain, _meshTerrain, ref addMesh); GUILayout.EndHorizontal(); EditorGUILayout.HelpBox( "Drop a mesh renderers or Unity terrains to add them to the terrain source data.", MessageType.Info); _meshTerrain.Filterlods = EditorGUILayout.Toggle("Skip LODs", _meshTerrain.Filterlods); EditorGUILayout.HelpBox("When checked import will skip all meshes with the name containing LOD1,LOD2 or LOD3.", MessageType.Info); GUILayout.EndVertical(); if (addMesh) { EditorUtility.SetDirty(target); return; } GUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Included sources", LabelStyle); EditorGUILayout.Space(); int removeIndex = -1; if (_meshTerrain.MeshTerrainMeshSourceList.Count > 0) { EditorGUILayout.LabelField("Meshes", LabelStyle); for (int i = 0; i <= _meshTerrain.MeshTerrainMeshSourceList.Count - 1; i++) { GUILayout.BeginHorizontal(); MeshTerrainMeshSource meshTerrainMeshSource = _meshTerrain.MeshTerrainMeshSourceList[i]; EditorGUI.BeginChangeCheck(); EditorGUILayout.LabelField("Mesh: ", LabelStyle, GUILayout.Width(50)); meshTerrainMeshSource.MeshRenderer = EditorGUILayout.ObjectField("", meshTerrainMeshSource.MeshRenderer, typeof(MeshRenderer), true, GUILayout.Width(150)) as MeshRenderer; meshTerrainMeshSource.TerrainSourceID = (TerrainSourceID)EditorGUILayout.EnumPopup("", meshTerrainMeshSource.TerrainSourceID, GUILayout.Width(150)); if (GUILayout.Button("Remove")) { removeIndex = i; } if (EditorGUI.EndChangeCheck()) { _meshTerrain.MeshTerrainMeshSourceList[i] = meshTerrainMeshSource; _meshTerrain.NeedGeneration = true; EditorUtility.SetDirty(target); } GUILayout.EndHorizontal(); } } if (removeIndex > -1) { _meshTerrain.MeshTerrainMeshSourceList.RemoveAt(removeIndex); _meshTerrain.NeedGeneration = true; EditorUtility.SetDirty(target); //HandleUtility.Repaint(); } if (_meshTerrain.MeshTerrainTerrainSourceList.Count > 0) { EditorGUILayout.LabelField("Terrains", LabelStyle); } GUILayout.EndVertical(); if (_meshTerrain.MeshTerrainData) { GUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Generate terrain data", LabelStyle); if (_meshTerrain.NeedGeneration) { EditorGUILayout.HelpBox( "The terrain sources have changed. Mesh terrain data needs to be regenerated.", MessageType.Warning); } if (GUILayout.Button("Generate terrain data")) { _meshTerrain.GenerateMeshTerrain(); _meshTerrain.NeedGeneration = false; VegetationStudioManager.ClearCache(); } EditorGUILayout.HelpBox( "The generated data will be stored in the assigned MeshTerrainData object.", MessageType.Info); GUILayout.EndVertical(); } else { EditorGUILayout.HelpBox( "You need to create and assign a mesh terrain data in order to generate the BVH tree.", MessageType.Warning); } }