/// <summary>
    /// Returns a mesh with the asset's saved data. If data isn't set, it returns PPC_IcosahedronGeneratorNoUV.Generate(10).
    /// </summary>
    /// <param name="_recalculateNecessaryData">Recalculates mesh bounds, normals and tangents.</param>
    public Mesh LoadMesh(bool _recalculateNecessaryData)
    {
        Mesh mesh;

        if (meshVertices == null || meshVertices.Length < 10)
        {
            Debug.Log(GetType().ToString() + ": Generating new mesh data...");
            mesh = PPC_IcosahedronGeneratorNoUV.Generate(10);
            SaveMeshData(mesh);
        }
        else
        {
            mesh = new Mesh
            {
                name      = name + " Mesh",
                vertices  = meshVertices,
                triangles = meshTriangles,
                colors    = meshColors
            };
        }

        if (_recalculateNecessaryData)
        {
            mesh.RecalculateBounds();
            mesh.RecalculateNormals();
            mesh.RecalculateTangents();
        }

        return(mesh);
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Auto Save Data");
        EditorGUILayout.PropertyField(autoSaveData, GUIContent.none, GUILayout.MaxWidth(14));
        EditorGUI.BeginDisabledGroup(NotPlayingOrNoMesh || builder.PolyPlanet.data == null);
        if (GUILayout.Button(new GUIContent("Save Mesh Data", "Available in play-mode."), EditorStyles.miniButton))
        {
            builder.SaveCurrentMeshDataToScriptableObject();
        }
        EditorGUI.EndDisabledGroup();
        EditorGUILayout.EndHorizontal();

        terrainFoldout = EditorGUILayout.Foldout(terrainFoldout, "Terrain", true);
        if (terrainFoldout)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(maxHeight);
            EditorGUILayout.PropertyField(limitDepth1);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");
            if (GUILayout.Button(new GUIContent("Get Mesh Max Height", "Sets 'maxHeight' to the current mesh's maximum vertex distance.")))
            {
                builder.GetMaxCurrentMaxHeight();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(NotPlayingOrNoMesh);
            EditorGUILayout.PrefixLabel(" ");
            if (GUILayout.Button(new GUIContent("Set Height To Max Height", "Sets all vertex distances to 'maxHeight'. Available in play-mode.")))
            {
                builder.SetHeightToMaxHeight();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();

            //perlin
            noiseFoldout = EditorGUILayout.Foldout(noiseFoldout, "Perlin Noise", true);
            if (noiseFoldout)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(scale);
                EditorGUILayout.PropertyField(seed);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(" ");
                EditorGUI.BeginDisabledGroup(NotPlayingOrNoMesh);
                if (GUILayout.Button(new GUIContent("Generate Terrain", "Available in play-mode."), EditorStyles.miniButton))
                {
                    (target as PPC_PlanetMeshBuilder).ApplyNoiseToMesh();
                }
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
            }

            // sample texture
            sampleFoldout = EditorGUILayout.Foldout(sampleFoldout, "Sample Texture", true);
            if (sampleFoldout)
            {
                EditorGUI.indentLevel++;
                EditorGUI.BeginDisabledGroup(NotPlayingOrNoMesh);
                builder.sampleTexture = EditorGUILayout.ObjectField(builder.sampleTexture, typeof(Texture2D), false) as Texture2D;
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.HelpBox("Make sure the texture is readable.", MessageType.Info);
                EditorGUI.indentLevel--;
            }
            EditorGUI.indentLevel--;
            EditorGUILayout.Space();
        }

        coloringFoldout = EditorGUILayout.Foldout(coloringFoldout, "Coloring", true);
        if (coloringFoldout)
        {
            EditorGUI.indentLevel++;
            EditorGUI.BeginChangeCheck();
            Color selectedColor = EditorGUILayout.ColorField(builder.SelectedColor);
            EditorGUILayout.PropertyField(colorNoise);
            EditorGUILayout.PropertyField(monotone);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Selected Color Change");
                builder.SelectedColor = selectedColor;
            }
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");
            EditorGUI.BeginDisabledGroup(NotPlayingOrNoMesh);
            if (GUILayout.Button(new GUIContent("Color Terrain", "Available in play-mode."), EditorStyles.miniButton))
            {
                builder.ColorPlanetWithCurrentColor();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
            EditorGUI.indentLevel--;
            EditorGUILayout.Space();
        }

        sphereGenerationFoldout = EditorGUILayout.Foldout(sphereGenerationFoldout, "Sphere Generation", true);
        if (sphereGenerationFoldout)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(detail);
            EditorGUILayout.HelpBox("Mesh triangles on generation: " + (detail.intValue * detail.intValue * 20).ToString(), MessageType.Info);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");
            EditorGUI.BeginDisabledGroup(NotPlayingOrNoMesh);
            if (GUILayout.Button(new GUIContent("Generate Sphere", "Generates an Icosahedron-based sphere. Available in play-mode."), EditorStyles.miniButton))
            {
                PPC_IcosahedronGeneratorNoUV.ApplyMesh(builder.GetComponent <PPC_Planet>().GetComponent <MeshFilter>(), PPC_IcosahedronGeneratorNoUV.Generate(detail.intValue));
                if (autoSaveData.boolValue)
                {
                    builder.SaveCurrentMeshDataToScriptableObject();
                }
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
            EditorGUI.indentLevel--;
            EditorGUILayout.Space();
        }

        settingsFoldout = EditorGUILayout.Foldout(settingsFoldout, "Settings", true);
        if (settingsFoldout)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(brushPower);
            EditorGUILayout.PropertyField(brushModeKey);
            EditorGUI.indentLevel--;
            EditorGUILayout.Space();
        }

        UIFoldout = EditorGUILayout.Foldout(UIFoldout, "UI / Editor", true);
        if (UIFoldout)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(brushModeTextUI);
            EditorGUILayout.PropertyField(levelBrushTextUI);
            EditorGUILayout.PropertyField(colorPicker);
            EditorGUILayout.PropertyField(gizmoScale);
            EditorGUI.indentLevel--;
        }

        brushInfoFoldout = EditorGUILayout.Foldout(brushInfoFoldout, "Controls & Brush Info", true);
        if (brushInfoFoldout)
        {
            EditorGUILayout.HelpBox(
                "KEYBOARD/MOUSE CONTROLS:\n" +
                "Left Mouse - Primary brush function\n" +
                "Right Mouse - Secondary brush function\n" +
                "Left Control - Toggle singleton brush\n" +
                "Alpha 1, 2, 3, 4 - Brush mode switching",
                MessageType.Info);
            EditorGUILayout.HelpBox(
                "MODIFY BRUSH\n" +
                "Primary - Increase vertex height (expand)\n" +
                "Secondary - Decrease vertex height (erode)",
                MessageType.Info);
            EditorGUILayout.HelpBox(
                "SMOOTH BRUSH\n" +
                "Primary - Slowly smooth center vertex\n" +
                "Secondary - Fully smooth center vertex",
                MessageType.Info);
            EditorGUILayout.HelpBox(
                "LEVEL BRUSH\n" +
                "Primary - Level terrain (plateau)\n" +
                "Secondary - Set level height to center vertex height",
                MessageType.Info);
            EditorGUILayout.HelpBox(
                "COLOR BRUSH\n" +
                "Primary - Color vertex\n" +
                "Secondary - Get color of center vertex",
                MessageType.Info);
        }

        serializedObject.ApplyModifiedProperties();
    }