class windowA : EditorWindow{
string temp;
string a = “heihei”;
void OnGUI(){
temp = EditorGUILayout.TextField(temp);
if(GUILayout.Button(“insert”)){
//
}
}
}
How can I get a string inserted to the cursorIndex in TextFiled as I press a button?
Finally, I did.(如果你有更好的方法,希望能告诉我)
Rect textRect = EditorGUILayout.GetControlRect(false, 16f, EditorStyles.textField);
temps = GUI.TextArea(textRect, temps);
int controlID = GUIUtility.GetControlID(textRect.GetHashCode(), FocusType.Keyboard);
TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), controlID - 1);
if(Event.current.type == EventType.Layout)
{
if (add)
{
editor.Paste();
temps = editor.text;
add = false;
}
}
if (GUILayout.Button("!!"))
{
GUIUtility.systemCopyBuffer = "qwe";
add = true;
}