基础Window

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. public class WindowItem : MonoBehaviour
  6. {
  7. [MenuItem("Window/MyWindow")]
  8. static void MyWindow()
  9. {
  10. TestWindow testWindow = EditorWindow.GetWindow<TestWindow>("我的窗口");
  11. testWindow.Show();
  12. }
  13. }
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. public class TestWindow : EditorWindow
  6. {
  7. private void OnGUI()
  8. {
  9. if(GUILayout.Button("点击测试按钮")){
  10. Debug.Log("按钮测试成功!");
  11. }
  12. }
  13. }

image.png

EditorWindow下拉菜单拓展

以上制作的菜单,image.png有下拉菜单,可以拓展。

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. public class TestWindow : EditorWindow,IHasCustomMenu
  6. {
  7. private bool isOn;
  8. public void AddItemsToMenu(GenericMenu menu)
  9. {
  10. //可操作性选项
  11. menu.AddItem(new GUIContent("添加的下拉菜单列表1"), isOn, () =>
  12. {
  13. Debug.Log("下拉列表1测试成功");
  14. isOn = !isOn;
  15. if(isOn) { }
  16. else { }
  17. });
  18. menu.AddDisabledItem(new GUIContent("就不让那你选"));//不可操作选项
  19. }
  20. }

image.png