[Unity] 编辑器扩展学习(十一)

[EditorWindow.GetWindow]

创建自定义窗口.

使用方式:

using UnityEditor;
using UnityEngine;

public class MyWindow : EditorWindow
{
    [MenuItem("Window/CreateMyWindow")]
    static void CreateMyWindow()
    {
        MyWindow window = EditorWindow.GetWindow<MyWindow>();
        window.Show();
    }
    private string name = "";
    void OnGUI()
    {
        GUILayout.Label("My Window");
        name = GUILayout.TextField(name);
        if (GUILayout.Button("创建"))
        {
            GameObject go = new GameObject(name);
            Undo.RegisterCreatedObjectUndo(go, "RegisterCreatedObjectUndo");
        }
    }
}

效果:

1

本文链接:

https://eggmo.net/archives/218/

转载请注明文章链接地址!Thanks♪(・ω・)ノ

1 + 4 =
快来做第一个评论的人吧~