基础Window
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class WindowItem : MonoBehaviour
{
[MenuItem("Window/MyWindow")]
static void MyWindow()
{
TestWindow testWindow = EditorWindow.GetWindow<TestWindow>("我的窗口");
testWindow.Show();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestWindow : EditorWindow
{
private void OnGUI()
{
if(GUILayout.Button("点击测试按钮")){
Debug.Log("按钮测试成功!");
}
}
}
EditorWindow下拉菜单拓展
以上制作的菜单,有下拉菜单,可以拓展。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestWindow : EditorWindow,IHasCustomMenu
{
private bool isOn;
public void AddItemsToMenu(GenericMenu menu)
{
//可操作性选项
menu.AddItem(new GUIContent("添加的下拉菜单列表1"), isOn, () =>
{
Debug.Log("下拉列表1测试成功");
isOn = !isOn;
if(isOn) { }
else { }
});
menu.AddDisabledItem(new GUIContent("就不让那你选"));//不可操作选项
}
}