Пример #1
0
    private void OnGUI()
    {
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

        showMeshes = EditorGUILayout.Foldout(showMeshes, "Meshes: ");
        if (showMeshes)
        {
            meshFindType = (MeshToTerrainFindType)EditorGUILayout.EnumPopup("Mesh select type: ", meshFindType);

            if (meshFindType == MeshToTerrainFindType.gameObjects)
            {
                for( int i = 0; i < mesh.Count; i++ )
                {
                    mesh[i] = (GameObject)EditorGUILayout.ObjectField( mesh[i], typeof(GameObject), true);
                    if (mesh[i] == null)
                    {
                        mesh.RemoveAt(i);
                        i--;
                    }
                }
                GameObject newMesh = (GameObject)EditorGUILayout.ObjectField( null, typeof(GameObject), true);
                if (newMesh != null)
                {
                    bool findedMesh = false;
                    foreach(GameObject cMesh in mesh) if (newMesh == cMesh) { findedMesh = true; break; }
                    if (!findedMesh) mesh.Add(newMesh);
                    else EditorUtility.DisplayDialog("Warning", "GameObject already added", "OK");
                }
            }
            else if (meshFindType == MeshToTerrainFindType.layers)
            {
                meshLayer = EditorGUILayout.LayerField("Layer: ", meshLayer);
            }

            EditorGUILayout.Space();
        }

        showTerrains = EditorGUILayout.Foldout(showTerrains, "Terrains: ");
        if (showTerrains)
        {
            terrainType = (MeshToTerrainSelectTerrainType) EditorGUILayout.EnumPopup("Type: ", terrainType);

            if (terrainType == MeshToTerrainSelectTerrainType.existTerrains)
            {
                for( int i = 0; i < terrain.Count; i++ )
                {
                    terrain[i] = (Terrain)EditorGUILayout.ObjectField(terrain[i], typeof(Terrain), true);
                    if (terrain[i] == null)
                    {
                        terrain.RemoveAt(i);
                        i--;
                    }
                }
                Terrain newTerrain = (Terrain) EditorGUILayout.ObjectField(null, typeof(Terrain), true);

                if (newTerrain != null)
                {
                    bool findedTerrain = false;
                    foreach(Terrain cTerrain in terrain) if (newTerrain == cTerrain) { findedTerrain = true; break; }
                    if (!findedTerrain) terrain.Add(newTerrain);
                    else EditorUtility.DisplayDialog("Warning", "Terrain already added", "OK");
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Count terrains. X: ", GUILayout.ExpandWidth(false));
                newTerrainCountX = EditorGUILayout.IntField(newTerrainCountX, GUILayout.ExpandWidth(false));
                GUILayout.Label("Y: ", GUILayout.ExpandWidth(false));
                newTerrainCountY = EditorGUILayout.IntField(newTerrainCountY, GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();

                bounds = (MeshToTerrainBounds)EditorGUILayout.EnumPopup("Bounds: ", bounds);
                if (bounds == MeshToTerrainBounds.fromGameobject) boundsGameObject = (GameObject)EditorGUILayout.ObjectField("Bounds GameObject: ", boundsGameObject, typeof(GameObject), true);

                detailResolution = EditorGUILayout.IntField("Detail Resolution", detailResolution);
                resolutionPerPatch = EditorGUILayout.IntField("Resolution Per Patch", resolutionPerPatch);
                baseMapResolution = EditorGUILayout.IntField("Base Map Resolution", baseMapResolution);
                heightmapResolution = EditorGUILayout.IntField("Height Map Resolution", heightmapResolution);
            }
            EditorGUILayout.Space();
        }

        showTextures = EditorGUILayout.Foldout(showTextures, "Textures: ");
        if (showTextures)
        {
            textureType = (MeshToTerrainTextureType)EditorGUILayout.EnumPopup("Type: ", textureType);

            if (textureType == MeshToTerrainTextureType.bakeMainTextures)
            {
                textureWidth = EditorGUILayout.IntField("Width: ", textureWidth);
                textureHeight = EditorGUILayout.IntField("Height: ", textureHeight);
                textureEmptyColor = EditorGUILayout.ColorField("Empty color: ", textureEmptyColor);
            }

            EditorGUILayout.Space();
        }

        EditorGUILayout.EndScrollView();

        if (GUILayout.Button("Start", GUILayout.Height(40)))
        {
            preStart();
        }
    }
Пример #2
0
    private void OnGUI()
    {
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

        showMeshes = EditorGUILayout.Foldout(showMeshes, "Meshes: ");
        if (showMeshes)
        {
            meshFindType = (MeshToTerrainFindType)EditorGUILayout.EnumPopup("Mesh select type: ", meshFindType);

            if (meshFindType == MeshToTerrainFindType.gameObjects)
            {
                for (int i = 0; i < mesh.Count; i++)
                {
                    mesh[i] = (GameObject)EditorGUILayout.ObjectField(mesh[i], typeof(GameObject), true);
                    if (mesh[i] == null)
                    {
                        mesh.RemoveAt(i);
                        i--;
                    }
                }
                GameObject newMesh = (GameObject)EditorGUILayout.ObjectField(null, typeof(GameObject), true);
                if (newMesh != null)
                {
                    bool findedMesh = false;
                    foreach (GameObject cMesh in mesh)
                    {
                        if (newMesh == cMesh)
                        {
                            findedMesh = true; break;
                        }
                    }
                    if (!findedMesh)
                    {
                        mesh.Add(newMesh);
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("Warning", "GameObject already added", "OK");
                    }
                }
            }
            else if (meshFindType == MeshToTerrainFindType.layers)
            {
                meshLayer = EditorGUILayout.LayerField("Layer: ", meshLayer);
            }

            EditorGUILayout.Space();
        }

        showTerrains = EditorGUILayout.Foldout(showTerrains, "Terrains: ");
        if (showTerrains)
        {
            terrainType = (MeshToTerrainSelectTerrainType)EditorGUILayout.EnumPopup("Type: ", terrainType);

            if (terrainType == MeshToTerrainSelectTerrainType.existTerrains)
            {
                for (int i = 0; i < terrain.Count; i++)
                {
                    terrain[i] = (Terrain)EditorGUILayout.ObjectField(terrain[i], typeof(Terrain), true);
                    if (terrain[i] == null)
                    {
                        terrain.RemoveAt(i);
                        i--;
                    }
                }
                Terrain newTerrain = (Terrain)EditorGUILayout.ObjectField(null, typeof(Terrain), true);

                if (newTerrain != null)
                {
                    bool findedTerrain = false;
                    foreach (Terrain cTerrain in terrain)
                    {
                        if (newTerrain == cTerrain)
                        {
                            findedTerrain = true; break;
                        }
                    }
                    if (!findedTerrain)
                    {
                        terrain.Add(newTerrain);
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("Warning", "Terrain already added", "OK");
                    }
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Count terrains. X: ", GUILayout.ExpandWidth(false));
                newTerrainCountX = EditorGUILayout.IntField(newTerrainCountX, GUILayout.ExpandWidth(false));
                GUILayout.Label("Y: ", GUILayout.ExpandWidth(false));
                newTerrainCountY = EditorGUILayout.IntField(newTerrainCountY, GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();

                bounds = (MeshToTerrainBounds)EditorGUILayout.EnumPopup("Bounds: ", bounds);
                if (bounds == MeshToTerrainBounds.fromGameobject)
                {
                    boundsGameObject = (GameObject)EditorGUILayout.ObjectField("Bounds GameObject: ", boundsGameObject, typeof(GameObject), true);
                }

                detailResolution    = EditorGUILayout.IntField("Detail Resolution", detailResolution);
                resolutionPerPatch  = EditorGUILayout.IntField("Resolution Per Patch", resolutionPerPatch);
                baseMapResolution   = EditorGUILayout.IntField("Base Map Resolution", baseMapResolution);
                heightmapResolution = EditorGUILayout.IntField("Height Map Resolution", heightmapResolution);
            }
            EditorGUILayout.Space();
        }

        showTextures = EditorGUILayout.Foldout(showTextures, "Textures: ");
        if (showTextures)
        {
            textureType = (MeshToTerrainTextureType)EditorGUILayout.EnumPopup("Type: ", textureType);

            if (textureType == MeshToTerrainTextureType.bakeMainTextures)
            {
                textureWidth      = EditorGUILayout.IntField("Width: ", textureWidth);
                textureHeight     = EditorGUILayout.IntField("Height: ", textureHeight);
                textureEmptyColor = EditorGUILayout.ColorField("Empty color: ", textureEmptyColor);
            }

            EditorGUILayout.Space();
        }

        EditorGUILayout.EndScrollView();

        if (GUILayout.Button("Start", GUILayout.Height(40)))
        {
            preStart();
        }
    }