Unity编辑器扩展——EditorWindow

创建窗口

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor; 


public class CreateTrees : EditorWindow
{

    [MenuItem("Window/My Window1")]
    static void Init()
    {
       
        CreateTrees window = (CreateTrees)GetWindow(typeof(CreateTrees));
        window.titleContent = new GUIContent("CreateTrees");//修改窗口标题
        window.Show(); //显示窗口
    }




}


public class CreateTrees : EditorWindow
{
    public string str;
    public string str1;

    public bool ison;
    public float slider;

    private Object obj;

    [MenuItem("Window/My Window1")]
    static void Init()
    {

        CreateTrees window = (CreateTrees)GetWindow(typeof(CreateTrees));
        window.titleContent = new GUIContent("CreateTrees");//修改窗口标题
        window.Show(); //显示窗口
    }


    void OnGUI()
    {

        str = EditorGUILayout.TextField("Lable",str);             //创建输入框

        if (GUILayout.Button("Button"))                           //创建按钮
        {
            Debug.Log("Button事件");
        }

        ison = EditorGUILayout.BeginToggleGroup("toggle",ison);
        str1 = EditorGUILayout.TextField("Lable1", str1);         //创建输入框
        //在这中间的字段可被toggle控制显示与隐藏
        EditorGUILayout.EndToggleGroup();

        slider= EditorGUILayout.Slider(slider, 0,1);
        obj = EditorGUILayout.ObjectField(obj, typeof(GameObject), true); //创建GameObject输入框

    }




}

 创建TextField文本输入框

创建button

创建toggle

创建GameObject输入框

 

在创建的窗口上显示字段

Unity编辑器扩展——EditorWindow_第1张图片

 

你可能感兴趣的:(c#,Unity,unity编辑器扩展,编辑器,unity,游戏引擎)