2.右键菜单项和生成脚本窗口

2.基本工具流程实现


2.1 知识点

新建项目,添加右键菜单项和打开生成脚本窗口

自定义右键菜单

[MenuItem("GameObject/UI/自动生成面板脚本文件")]
private static void CreateToolPanel()
{
    
}

打开自定义面板

public class UIPanelTool : EditorWindow
{
    [MenuItem("GameObject/UI/自动生成面板脚本文件")]
    private static void CreateToolPanel()
    {
        UIPanelTool win = EditorWindow.GetWindow<UIPanelTool>("自动生成面板脚本工具");
        win.Show();
    }
}

自定义面板打开文件保存面板

public class UIPanelTool : EditorWindow
{
    //...

    private void OnGUI()
    {
        if(GUILayout.Button("选择保存路径"))
        {
            string path = EditorUtility.SaveFilePanel("脚本保存路径", Application.dataPath, "", ".cs");
            if( path != "" )
            {
                
            }
        }
    }
}

2.2 知识点代码

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

public class UIPanelTool : EditorWindow
{
    [MenuItem("GameObject/UI/自动生成面板脚本文件")]
    private static void CreateToolPanel()
    {
        UIPanelTool win = EditorWindow.GetWindow<UIPanelTool>("自动生成面板脚本工具");
        win.Show();
    }

    private void OnGUI()
    {
        if(GUILayout.Button("选择保存路径"))
        {
            string path = EditorUtility.SaveFilePanel("脚本保存路径", Application.dataPath, "", ".cs");
            if( path != "" )
            {

            }
        }
    }
}


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 785293209@qq.com

×

喜欢就点赞,疼爱就打赏