Unity Editor 知识点整理(创建 自定义编辑器窗体 一)

首先在Editor 文件夹下创建脚本

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

namespace RunAndJump.LevelCreator
{
    
    
    //创建自定义编辑器窗体 需要继承EditorWindow
    public class PaletteWindow : EditorWindow
    {
    
    
        //自定义窗体一般用单例模式
        #region Singleton
            
        private static PaletteWindow instance;
        public static void ShowPalette()
        {
    
    
            instance = EditorWindow.GetWindow<PaletteWindow>();  //GetWindow(typeof(PaletteWindow))

            //设置窗体标题
            instance.titleContent = new GUIContent("Palette");
        }
        #endregion
    }
}

然后在Scripts文件夹下,创建菜单栏选项

	[MenuItem("Tools/Level Creator/Show Palette")]
       private static void ShowPalette()
       {
    
    
           PaletteWindow.ShowPalette();
       }

可以得到如下图所示效果
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43388137/article/details/122235112
今日推荐