Version: 2022.2
public void Focus ();

描述

将键盘焦点移动到另一个 EditorWindow。

Focus 公共方法控制激活哪个窗口 以使用键盘。在下面的示例中, 处于活动状态的 EditorWindow 键盘被更改为 另一种 EditorWindow 键盘。 另请参阅:focusedWindow 通过按其他窗口上的按钮来聚焦一个窗口。

// EditorWindow.Focus
//
// A window that change state to the second window when
// the button is pressed.

using UnityEngine; using UnityEditor;

public class FocusExample1 : EditorWindow { public static FocusExample1 Instance = null;

[MenuItem("Example/Focus Example1")] static void Init() { GetWindow<FocusExample1>("Focus1"); }

public FocusExample1() { Instance = this; }

void OnGUI() { if (GUILayout.Button("Focus Window2")) { FocusExample2.Instance.Focus(); } } }
// Second window

using UnityEngine; using UnityEditor;

public class FocusExample2 : EditorWindow { public static FocusExample2 Instance = null;

[MenuItem("Example/Focus Example2")] static void Init() { GetWindow<FocusExample2>("Focus2"); }

public FocusExample2() { Instance = this; }

void OnGUI() { if (GUILayout.Button("Focus Window1")) { FocusExample1.Instance.Focus(); } } }