Ejemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        LakePolygonProfile lakePolygon = (LakePolygonProfile)target;

        lakePolygon.lakeMaterial = (Material)EditorGUILayout.ObjectField("Material", lakePolygon.lakeMaterial, typeof(Material), false);

        GUILayout.Label("Mesh settings:", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;

        lakePolygon.maximumTriangleSize = EditorGUILayout.FloatField("Maximum triangle size", lakePolygon.maximumTriangleSize);
        lakePolygon.traingleDensity     = 1 / (float)EditorGUILayout.IntSlider("Spline density", (int)(1 / (float)lakePolygon.traingleDensity), 1, 100);
        lakePolygon.uvScale             = EditorGUILayout.FloatField("UV scale", lakePolygon.uvScale);


        GUILayout.Label("Terrain carve:", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;
        lakePolygon.terrainCarve    = EditorGUILayout.CurveField("Terrain carve", lakePolygon.terrainCarve);
        lakePolygon.distSmooth      = EditorGUILayout.FloatField("Smooth distance", lakePolygon.distSmooth);
        lakePolygon.distSmoothStart = EditorGUILayout.FloatField("Smooth start distance", lakePolygon.distSmoothStart);
        EditorGUI.indentLevel--;

        EditorGUILayout.Space();
        EditorGUI.indentLevel++;

        lakePolygon.terrainPaintCarve = EditorGUILayout.CurveField("Terrain paint", lakePolygon.terrainPaintCarve);
        EditorGUI.indentLevel--;

#if VEGETATION_STUDIO_PRO
        lakePolygon.biomeType = System.Convert.ToInt32(EditorGUILayout.EnumPopup("Select biome", (BiomeType)lakePolygon.biomeType));
#else
        lakePolygon.biomeType = EditorGUILayout.IntField("Select biome", lakePolygon.biomeType);
#endif
    }
Ejemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        if (lakePolygon == null)
        {
            lakePolygon = (LakePolygon)target;
        }
        EditorGUILayout.Space();
        EditorGUILayout.HelpBox("Add Point  - CTRL + Left Mouse Button Click \n" +
                                "Add point between existing points - SHIFT + Left Button Click \n" +
                                "Remove point - CTRL + SHIFT + Left Button Click", MessageType.Info);

        EditorGUILayout.Space();
        lakePolygon.currentProfile = (LakePolygonProfile)EditorGUILayout.ObjectField("Lake profile", lakePolygon.currentProfile, typeof(LakePolygonProfile), false);

        if (GUILayout.Button("Create profile from settings"))
        {
            LakePolygonProfile asset = ScriptableObject.CreateInstance <LakePolygonProfile>();

            MeshRenderer ren = lakePolygon.GetComponent <MeshRenderer>();
            asset.lakeMaterial      = ren.sharedMaterial;
            asset.terrainCarve      = lakePolygon.terrainCarve;
            asset.distSmooth        = lakePolygon.distSmooth;
            asset.uvScale           = lakePolygon.uvScale;
            asset.distSmoothStart   = lakePolygon.distSmoothStart;
            asset.terrainPaintCarve = lakePolygon.terrainPaintCarve;
            asset.currentSplatMap   = lakePolygon.currentSplatMap;

            asset.maximumTriangleSize = lakePolygon.maximumTriangleSize;
            asset.traingleDensity     = lakePolygon.traingleDensity;



            string path = EditorUtility.SaveFilePanelInProject("Save new spline profile", lakePolygon.gameObject.name + ".asset", "asset", "Please enter a file name to save the spline profile to");

            if (!string.IsNullOrEmpty(path))
            {
                AssetDatabase.CreateAsset(asset, path);
                AssetDatabase.SaveAssets();
                lakePolygon.currentProfile = asset;
            }
        }

        if (lakePolygon.currentProfile != null && GUILayout.Button("Save profile from settings"))
        {
            MeshRenderer ren = lakePolygon.GetComponent <MeshRenderer>();

            lakePolygon.currentProfile.lakeMaterial = ren.sharedMaterial;

            lakePolygon.currentProfile.terrainCarve      = lakePolygon.terrainCarve;
            lakePolygon.currentProfile.distSmooth        = lakePolygon.distSmooth;
            lakePolygon.currentProfile.uvScale           = lakePolygon.uvScale;
            lakePolygon.currentProfile.distSmoothStart   = lakePolygon.distSmoothStart;
            lakePolygon.currentProfile.terrainPaintCarve = lakePolygon.terrainPaintCarve;
            lakePolygon.currentProfile.currentSplatMap   = lakePolygon.currentSplatMap;

            lakePolygon.currentProfile.maximumTriangleSize = lakePolygon.maximumTriangleSize;
            lakePolygon.currentProfile.traingleDensity     = lakePolygon.traingleDensity;


            AssetDatabase.SaveAssets();
        }


        if (lakePolygon.currentProfile != null && lakePolygon.currentProfile != lakePolygon.oldProfile)
        {
            ResetToProfile();
            EditorUtility.SetDirty(lakePolygon);
        }

        if (CheckProfileChange())
        {
            EditorGUILayout.HelpBox("Profile data changed.", MessageType.Info);
        }

        if (lakePolygon.currentProfile != null && GUILayout.Button("Reset to profile"))
        {
            ResetToProfile();
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUI.BeginChangeCheck();


        pointsFolded = EditorGUILayout.Foldout(pointsFolded, "Points:");
        EditorGUI.indentLevel++;
        if (pointsFolded)
        {
            PointsUI();
        }

        lakePolygon.lockHeight = EditorGUILayout.Toggle("Lock height", lakePolygon.lockHeight);

        EditorGUILayout.BeginHorizontal();
        lakePolygon.height = EditorGUILayout.FloatField(lakePolygon.height);
        if (GUILayout.Button("Set heights"))
        {
            for (int i = 0; i < lakePolygon.points.Count; i++)
            {
                Vector3 point = lakePolygon.points[i];
                point.y = lakePolygon.height - lakePolygon.transform.position.y;
                lakePolygon.points[i] = point;
            }
            lakePolygon.GeneratePolygon();
        }

        EditorGUILayout.EndHorizontal();

        lakePolygon.yOffset = EditorGUILayout.FloatField("Y offset mesh", lakePolygon.yOffset);
        EditorGUI.indentLevel--;
        EditorGUILayout.Space();


        GUILayout.Label("Mesh settings:", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;
        string meshResolution = "Triangles density" + "(" + lakePolygon.trianglesGenerated + " tris)";

        EditorGUILayout.LabelField(meshResolution);

        lakePolygon.maximumTriangleSize = EditorGUILayout.FloatField("Maximum triangle size", lakePolygon.maximumTriangleSize);
        lakePolygon.traingleDensity     = 1 / (float)EditorGUILayout.IntSlider("Spline density", (int)(1 / (float)lakePolygon.traingleDensity), 1, 100);
        lakePolygon.uvScale             = EditorGUILayout.FloatField("UV scale", lakePolygon.uvScale);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(lakePolygon, "Lake changed");
            lakePolygon.GeneratePolygon();
        }

        EditorGUI.indentLevel--;
        EditorGUILayout.Space();

        if (GUILayout.Button("Generate polygon"))
        {
            lakePolygon.GeneratePolygon();
        }
        EditorGUI.BeginChangeCheck();

        EditorGUILayout.Space();

        Terrain terrain = Terrain.activeTerrain;

        GUILayout.Label("Terrain carve:", EditorStyles.boldLabel);

        if (terrain != null)
        {
            EditorGUI.indentLevel++;
            lakePolygon.terrainCarve    = EditorGUILayout.CurveField("Terrain carve", lakePolygon.terrainCarve);
            lakePolygon.distSmooth      = EditorGUILayout.FloatField("Smooth distance", lakePolygon.distSmooth);
            lakePolygon.distSmoothStart = EditorGUILayout.FloatField("Smooth start distance", lakePolygon.distSmoothStart);
            EditorGUI.indentLevel--;

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(lakePolygon, "Lake curve changed");
            }

            if (GUILayout.Button("Carve Terrain"))
            {
                TerrainCarve();
            }

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.Space();
            EditorGUI.indentLevel++;

            lakePolygon.terrainPaintCarve = EditorGUILayout.CurveField("Terrain paint", lakePolygon.terrainPaintCarve);

            int splatNumber = terrain.terrainData.splatPrototypes.Length;
            if (splatNumber > 0)
            {
                string[] options = new string[splatNumber];
                for (int i = 0; i < splatNumber; i++)
                {
                    options[i] = i + " - ";
                    if (terrain.terrainData.splatPrototypes[i].texture != null)
                    {
                        options[i] += terrain.terrainData.splatPrototypes[i].texture.name;
                    }
                }

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("    Splat id:");
                lakePolygon.currentSplatMap = EditorGUILayout.Popup(lakePolygon.currentSplatMap, options);
                EditorGUILayout.EndHorizontal();

                EditorGUI.indentLevel--;

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(lakePolygon, "Lake curve changed");
                }

                if (GUILayout.Button("Paint Terrain"))
                {
                    TerrainPaint();
                }
            }
            else
            {
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox("Terrain has no splatmaps.", MessageType.Info);
            }
        }
        else
        {
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("No Terrain On Scene.", MessageType.Info);
        }
#if VEGETATION_STUDIO
        EditorGUILayout.Space();
        GUILayout.Label("Vegetation Studio: ", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;
        EditorGUI.BeginChangeCheck();
        lakePolygon.vegetationMaskResolution = EditorGUILayout.Slider("Mask Resolution", lakePolygon.vegetationMaskResolution, 0.1f, 1);
        lakePolygon.vegetationMaskPerimeter  = EditorGUILayout.FloatField("Vegetation Mask Perimeter", lakePolygon.vegetationMaskPerimeter);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(lakePolygon, "Lake curve changed");
            RegenerateVegetationMask();
        }
        EditorGUI.indentLevel--;
        if (lakePolygon.vegetationMaskArea == null && GUILayout.Button("Add Vegetation Mask Area"))
        {
            lakePolygon.vegetationMaskArea = lakePolygon.gameObject.AddComponent <VegetationMaskArea>();
            RegenerateVegetationMask();
        }
        if (lakePolygon.vegetationMaskArea != null && GUILayout.Button("Calculate hull outline"))
        {
            RegenerateVegetationMask();
        }
#endif

#if VEGETATION_STUDIO_PRO
        EditorGUILayout.Space();
        GUILayout.Label("Vegetation Studio Pro: ", EditorStyles.boldLabel);

        EditorGUI.BeginChangeCheck();
        lakePolygon.vegetationBlendDistance = EditorGUILayout.FloatField("Vegetation Blend Distance", lakePolygon.vegetationBlendDistance);
        lakePolygon.biomMaskResolution      = EditorGUILayout.Slider("Mask Resolution", lakePolygon.biomMaskResolution, 0.1f, 1);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(lakePolygon, "Lake curve changed");
            RegenerateBiomMask();
        }
        if (lakePolygon.biomeMaskArea != null)
        {
            lakePolygon.refreshMask = EditorGUILayout.Toggle("Auto Refresh Biome Mask", lakePolygon.refreshMask);
        }

        if (GUILayout.Button("Add Vegetation Biom Mask Area"))
        {
            lakePolygon.GeneratePolygon();

            if (lakePolygon.biomeMaskArea == null)
            {
                GameObject maskObject = new GameObject("MyMask");
                maskObject.transform.SetParent(lakePolygon.transform);
                maskObject.transform.localPosition = Vector3.zero;

                lakePolygon.biomeMaskArea = maskObject.AddComponent <BiomeMaskArea>();
            }

            if (lakePolygon.biomeMaskArea == null)
            {
                return;
            }

            RegenerateBiomMask(false);
        }
#endif
    }