public static bool HasOpenInstances ();

参数

t窗口类型。必须派生自 EditorWindow

返回

bool 如果与指定类型匹配的 EditorWindow 已打开,则返回 true。否则返回 false。

描述

检查编辑器窗口是否已打开。

using UnityEngine;
using UnityEditor;

public class MyWindow : EditorWindow { string myString = "Hello World";

// Add menu named "My Window" to the Window menu [MenuItem("Window/My Window")] static void Init() { // Get existing open window or if none, make a new one: MyWindow window = (MyWindow)EditorWindow.GetWindow(typeof(MyWindow)); window.Show(); }

[MenuItem("Window/Close My Window")] static void Close() { // Checks if any window of type MyWindow is open if (EditorWindow.HasOpenInstances<MyWindow>()) { var window = EditorWindow.GetWindow(typeof(MyWindow)); window.Close(); } }

void OnGUI() { GUILayout.Label("Base Settings", EditorStyles.boldLabel); myString = EditorGUILayout.TextField("Text Field", myString); } }