代码:
using UnityEngine;
using UnityEditor;
public class MyWidow : EditorWindow
{
[MenuItem("Window/Show MyWindow")]
static void ShowMyWindow()
{
MyWidow myWindow = EditorWindow.GetWindow<MyWidow>();//创建自定义窗口
myWindow.Show();//显示创建的自定义窗口
}
private string name = "";
void OnGUI()
{
GUILayout.Label("这是我的自定义窗口");
name = GUILayout.TextField(name);
if (GUILayout.Button("创建"))
{
GameObject go = new GameObject(name);
Undo.RegisterCreatedObjectUndo(go, "create gameObject");//允许撤回
}
}
}