Modifying mesh vertices in an editor script

I'm wondering if it's possible to change the position of mesh vertices in the editor. Here's my current code:

function OnSceneGUI()
{
    var mesh : Mesh = target.GetComponent(MeshFilter).mesh;
        var verts = mesh.vertices;

    for (var v in verts)
        v = v + Handles.PositionHandle( target.transform.position + v,
                                        Quaternion.identity            );

    mesh.vertices = verts;
}

Unity complains: "Instantiating mesh due to calling MeshFilter.mesh during edit mode. This will leak meshes. Please use MeshFilter.sharedMesh instead." But using sharedMesh wouldn't make a lot of sense, either.

Actually you do have to do what Unity says and use sharedMesh. Otherwise, as it says, you'd leak meshes since they would only exist in the scene and not the project. Here is an editor script that makes custom planes, which uses sharedMesh. If it needs to be unique you can make a new mesh.

Here is my code for accessing/creating meshes at runtime or edit mode.

using UnityEngine;

[ExecuteInEditMode]

[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]

public abstract class DynamicMesh : MonoBehaviour
{

    #region Protected Abstract Properties

	protected abstract Vector3[] vertices { get; }


	protected abstract Vector2[] uv { get; }


	protected abstract int[] triangles { get; }

	#endregion

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	#region Protected Properties

	protected MeshFilter meshFilter
	{
		get
		{
			if(this._meshFilter == null)
			{
				this._meshFilter = gameObject.GetComponent();
			}
			return this._meshFilter;
		}
	}


	protected Mesh mesh
	{
		get
		{
			if(_mesh != null)
			{
				return _mesh;
			}
			else
			{

				if(meshFilter.sharedMesh == null)
				{
					Mesh newMesh = new Mesh();
					_mesh = meshFilter.sharedMesh = newMesh;
				}
				else
				{
					_mesh = meshFilter.sharedMesh;
				}
				return _mesh;
			}
		}
	}

	#endregion

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	#region Protected Methods

	protected virtual void OnEnable()
	{
		ReCalculateMesh(true);
	}

	#endregion
	
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	#region Private Methods

	private void ReCalculateMesh(bool allAttributes)
	{
		if(allAttributes)
		{
			if(mesh == null)
			{
				Debug.LogError("Could not access or create a mesh", this);
				return;
			}
			mesh.Clear();
		}
		mesh.vertices = vertices;

		if(allAttributes)
		{
			mesh.uv = uv;
			mesh.triangles = triangles;
		}
		mesh.RecalculateNormals();
		mesh.RecalculateBounds();
	}


	#endregion
	
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	#region Private Members

	private MeshFilter _meshFilter = null;
	private Mesh _mesh = null;

	#endregion
}