The following is based on UI (VisualElement) after 2019
For some "advanced" "desktop applications" (with mouse and keyboard) interface development
It may be necessary to open the interface and enter or paste
(This can also be regarded as a very ancient technique)
For example: we want to open the interface as follows
I tried this method at first
I tried:
textField.Focus();
textField.SelectAll();
OR
textField.Focus();
textField.SelectRange(...);
Certainly not
Finally, the answer found in the official forum
var text = new TextField();
//text.Focus();
//text.ElementAt(0).Focus();
//GUI.FocusControl("urlText");
this.Add(text);
this.schedule.Execute(() => {
text.ElementAt(0).Focus();
text.SelectAll();
});
In addition, Gui is the method of the initial version UI (IMGUI) of Unity,
It's useless here, just record
text.name="urlText"
GUI.FocusControl("urlText");
//虽然textField也是能命名
//但.FocusControl()要生效
//貌似要配合
GUI.SetNextControlName("Text1");