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).
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();
}
}
}
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.