// Show spline points
    private Vector3 ShowPoint(int index)
    {
        Vector3 point = handleTransform.TransformPoint(terrain.GetControlPoint(index));
        float   size  = HandleUtility.GetHandleSize(point);

        Handles.color = modeColors[(int)terrain.GetControlPointMode(index)];

        // Activate the bezier curve handle if we click on it
        if (Handles.Button(point, handleRotation, size * handleSize, size * pickSize, Handles.CircleCap))
        {
            selectedIndex = index;
            Repaint();
        }

        // If there's a handle currently selected...
        if (selectedIndex == index)
        {
            // Listen for inspector value dhanges
            EditorGUI.BeginChangeCheck();
            point = Handles.DoPositionHandle(point, handleRotation);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(terrain, "Move Point");
                terrain.SetControlPoint(index, handleTransform.InverseTransformPoint(point));
                terrain.BuildMesh();
                terrain.GenerateCollider();
                EditorUtility.SetDirty(terrain);
            }
        }
        return(point);
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        terrain = target as SplineTerrainGenerator;

        // If we've selected a spline control point, show its transform in the inspector
        if (selectedIndex >= 0 && selectedIndex < terrain.ControlPointCount)
        {
            DrawSelectedPointInspector();
        }

        // Button to generate new terrain
        if (GUILayout.Button("Generate New Terrain"))
        {
            Undo.RecordObject(terrain, "Generate New Terrain");
            terrain.BuildSpline();
            EditorUtility.SetDirty(terrain);
        }

        // Button to generate new terrain
        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(terrain, "Add Curve");
            terrain.AddCurve(4);
            terrain.terrainBlocks += 1;
            terrain.BuildMesh();
            EditorUtility.SetDirty(terrain);
        }

        // Button to rebuild the mesh
        if (GUILayout.Button("Build Mesh & Collider"))
        {
            Undo.RecordObject(terrain, "Build Mesh & Collider");
            terrain.BuildMesh();
            terrain.GenerateCollider();
            EditorUtility.SetDirty(terrain);
        }
    }