Esempio n. 1
0
 private void Load()
 {
     baseMapResolution = LoadPref("BaseMapRes", 1024);
     boundsGameObject  = LoadPrefGameObject("BoundsGameObject", null);
     boundsType        = (MeshToTerrainBounds)LoadPref("BoundsType", (int)MeshToTerrainBounds.autoDetect);
     if (boundsType == MeshToTerrainBounds.selectBounds)
     {
         bounds = LoadPref("Bounds", new Bounds(Vector3.zero, Vector3.one));
     }
     detailResolution    = LoadPref("DetailMapRes", 1024);
     direction           = (MeshToTerrainDirection)LoadPref("Direction", (int)MeshToTerrainDirection.normal);
     generateTextures    = LoadPref("GenerateTextures", false);
     heightmapResolution = LoadPref("HeightMapRes", 129);
     meshes                = LoadPref("Meshes", new List <GameObject>());
     holes                 = (MeshToTerrainHoles)LoadPref("Holes", (int)MeshToTerrainHoles.minimumValue);
     meshFindType          = (MeshToTerrainFindType)LoadPref("MeshFindType", (int)MeshToTerrainFindType.gameObjects);
     meshLayer             = LoadPref("MeshLayer", 31);
     newTerrainCountX      = LoadPref("CountX", 1);
     newTerrainCountY      = LoadPref("CountY", 1);
     resolutionPerPatch    = LoadPref("ResPerPath", 16);
     showMeshes            = LoadPref("ShowMeshes", true);
     showTerrains          = LoadPref("ShowTerrains", true);
     showTextures          = LoadPref("ShowTextures", true);
     smoothingFactor       = LoadPref("SmoothingFactor", 1);
     terrains              = LoadPref("Terrains", new List <Terrain>());
     terrainType           = (MeshToTerrainSelectTerrainType)LoadPref("TerrainType", (int)MeshToTerrainSelectTerrainType.newTerrains);
     textureEmptyColor     = LoadPref("TextureEmptyColor", Color.white);
     textureHeight         = LoadPref("TextureHeight", 1024);
     textureResolution     = LoadPref("TextureResolution", 1024);
     textureWidth          = LoadPref("TextureWidth", 1024);
     useHeightmapSmoothing = LoadPref("UseHeightmapSmoothing", true);
     yRange                = (MeshToTerrainYRange)LoadPref("YRange", 0);
     yRangeValue           = LoadPref("YRangeValue", yRangeValue);
     adjustMeshSize        = LoadPref("AdjustMeshSize", true);
     textureCaptureMode    = (MeshToTerrainTextureCaptureMode)LoadPref("TextureCaptureMode", (int)MeshToTerrainTextureCaptureMode.camera);
 }
Esempio n. 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();
        }
    }
Esempio n. 3
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();
        }
    }
Esempio n. 4
0
    private void OnTerrainsGUINew()
    {
        if (availableResolutionsStr == null || availableHeightsStr == null)
        {
            availableHeightsStr     = availableHeights.Select(h => h.ToString()).ToArray();
            availableResolutionsStr = availableResolutions.Select(r => r.ToString()).ToArray();
        }

        GUILayout.BeginHorizontal();
        GUILayout.Label("Count terrains. X: ", GUILayout.ExpandWidth(false));
        newTerrainCountX = Mathf.Max(EditorGUILayout.IntField(newTerrainCountX, GUILayout.ExpandWidth(false)), 1);
        GUILayout.Label("Y: ", GUILayout.ExpandWidth(false));
        newTerrainCountY = Mathf.Max(EditorGUILayout.IntField(newTerrainCountY, GUILayout.ExpandWidth(false)), 1);
        GUILayout.EndHorizontal();

        adjustMeshSize = EditorGUILayout.Toggle("Adjust size of meshes", adjustMeshSize);
        EditorGUILayout.HelpBox("Adjust the size of meshes will break your prefabs (if present), but will help to work around the raycast problem on too small and too big meshes.\nAfter generation meshes and terrains will have the original size.", MessageType.Info);

        EditorGUI.BeginChangeCheck();
        boundsType = (MeshToTerrainBounds)EditorGUILayout.EnumPopup("Bounds", boundsType);

        if (EditorGUI.EndChangeCheck())
        {
            if (boundsType == MeshToTerrainBounds.selectBounds)
            {
            }
            else if (boundsHelper != null)
            {
                Object.DestroyImmediate(boundsHelper.gameObject);
            }
        }

        if (boundsType == MeshToTerrainBounds.fromGameobject)
        {
            boundsGameObject = (GameObject)EditorGUILayout.ObjectField("Bounds GameObject: ", boundsGameObject, typeof(GameObject), true);
        }
        else if (boundsType == MeshToTerrainBounds.selectBounds)
        {
            if (boundsHelper == null)
            {
                showBoundSelector = false;
            }

            showBoundSelector = GUILayout.Toggle(showBoundSelector, "Show Selector", GUI.skin.button);
            if (showBoundSelector && boundsHelper == null)
            {
                CreateBoundsHelper();
            }
            else if (!showBoundSelector && boundsHelper != null)
            {
                Object.DestroyImmediate(boundsHelper.gameObject);
                boundsHelper = null;
            }

            EditorGUI.BeginChangeCheck();
            bounds = EditorGUILayout.BoundsField("Bounds", bounds);

            if (EditorGUI.EndChangeCheck() && boundsHelper != null)
            {
                boundsHelper.bounds = bounds;
            }

            if (GUILayout.Button("Detect Bounds"))
            {
                DetectBounds();
            }
        }

        const string detailTooltip             = "The resolution of the map that controls grass and detail meshes. For performance reasons (to save on draw calls) the lower you set this number the better.";
        const string resolutionPerPatchTooltip = "Specifies the size in pixels of each individually rendered detail patch. A larger number reduces draw calls, but might increase triangle count since detail patches are culled on a per batch basis. A recommended value is 16. If you use a very large detail object distance and your grass is very sparse, it makes sense to increase the value.";
        const string basemapTooltip            = "Resolution of the composite texture used on the terrain when viewed from a distance greater than the Basemap Distance.";
        const string heightmapTooltip          = "Pixel resolution of the terrains heightmap.";
        const string alphamapTooltip           = "Resolution of the splatmap that controls the blending of the different terrain textures.";
        const string helpHref = "http://docs.unity3d.com/Manual/terrain-OtherSettings.html";

        DrawField("Heightmap Resolution", ref heightmapResolution, heightmapTooltip, helpHref, availableHeightsStr, availableHeights);
        DrawField("Detail Resolution", ref detailResolution, detailTooltip, helpHref);
        DrawField("Control Texture Resolution", ref alphamapResolution, alphamapTooltip, helpHref, availableResolutionsStr, availableResolutions);
        DrawField("Base Texture Resolution", ref baseMapResolution, basemapTooltip, helpHref, availableResolutionsStr, availableResolutions);
        DrawField("Resolution Per Patch", ref resolutionPerPatch, resolutionPerPatchTooltip, helpHref);

        if (resolutionPerPatch < 1)
        {
            resolutionPerPatch = 1;
        }
        detailResolution = detailResolution / resolutionPerPatch * resolutionPerPatch;
    }