How can I add copy and paste support for my EditorWindow?

Hi There

I have an EditorWindow for a behaviour tree implementation. Is there an editor/utility class/set of methods for handling copy and paste/clipboard interaction?

I’d quite like to be able to copy a branch of the BT and paste it somewhere else (or cut and paste).

Thanks a lot
Bovine

Unity can do EditorGUIUtility.systemCopyBuffer. You’ll need custom implementation for custom content though. If it’s serializable, there’s stuff like EditorUtility.CopySerialized and SerializedObject.CopyFromSerializedProperty().

Very late, but I came across this post before figuring out the answer.
This code manually copies whatever the user currently has selected to the OS buffer.
You could easily modify it to act differently on these different inputs.

void OnGUI() {
/*
	Your code for drawing fields goes here
*/
var textEditor = EditorGUIUtility.GetStateObject(typeof(TextEditor), EditorGUIUtility.keyboardControl) as TextEditor;

if (textEditor != null) {
	if (focusedWindow == this) {
		// shift + x
		if (Event.current.Equals(Event.KeyboardEvent("#x")))
			textEditor.Cut();
		// shift + c
		if (Event.current.Equals(Event.KeyboardEvent("#c")))
			textEditor.Copy();
		// shift + v
		if (Event.current.Equals(Event.KeyboardEvent("#v")))
			textEditor.Paste();
	}
}
}

This post got me on track:
http://forum.unity3d.com/threads/copy-textfield-or-textarea-text-to-clipboard.24101/#post-813226
This piece of documentation described how to get the keyboard input:

Unfortunately, the command for ctrl+c, “^c” , etc. are suppressed, probably by the inputfield, but I found that using shift as a substite, so “#c”, did work, so that’s how I left it.