• UnityProject面板中右键创建新的Lua脚本以及修改文件默认打开方式的编辑器


      新大厅中要介入热更新,那自然少不了Lua。这两天在学习腾讯的xLua还有之前一直有在积累的shader知识。由于Unity原生没有直接创建lua脚本的功能,而且VS对Lua和Shader支持的都不是特别好,而且比较臃肿,所以我制作了创建lua脚本和改变其默认打开方式的编辑器。

    1.右键创建Lua脚本

     1     [MenuItem("Assets/Create/Lua Script #&c", priority = 81)]
     2     static void CreateLuaScriptMethod()
     3     {
     4         Object[] obj = Selection.objects;
     5         
     6         string assetPath = AssetDatabase.GetAssetPath(obj[0]);
     7         string path = "";
     8         if (!Path.HasExtension(assetPath))
     9         {
    10             path = Path.GetFullPath(assetPath);
    11         }
    12         else
    13         {
    14             string dirPath = Path.GetDirectoryName(assetPath);
    15             path = Path.GetFullPath(dirPath);
    16         }
    17         path += "/NewLuaScript.lua.txt";
    18         int index = 1;
    19         while (File.Exists(path))
    20         {
    21             string dir = Path.GetDirectoryName(path);
    22             path = dir + "/NewLuaScript"+index+".lua.txt";
    23             index++;
    24         }
    25         Debug.Log(path);
    26         StreamWriter sw = new StreamWriter(path, false);
    27         sw.Close();
    28         AssetDatabase.Refresh();
    29     }

      priority 是设置该条目的优先级,为了让它在创建C#脚本下方

      在文件上右键时在它的目录下生成新的lua.txt文件(txt是为了能被Unity识别为TextAsset,xLua的脚本就是这种格式)。当命名重复会自动在后面增加index。

    2.将Shader文件的打开方式更换为系统默认的打开方式

    [OnOpenAsset]
        public static bool OpenShaderAsset(int instanceID, int line)
        {
            if (EditorUtility.InstanceIDToObject(instanceID) is Shader)
            {
                string assetPath = AssetDatabase.GetAssetPath(instanceID);
                System.Diagnostics.Process.Start(Application.dataPath + "/../" + assetPath);
                return true;
            }
            return false;
        }

      系统默认打开方式人人应该都会了,想让.txt文件也用默认方式打开再创建一个函数,把Shader改成TextAsset即可。这样我的lua脚本和Shader脚本都会有VSCode打开

  • 相关阅读:
    Linux内核驱动--硬件访问I/O【原创】
    Linux内核驱动--mmap设备方法【原创】
    Linux系统调用的运行过程【转】
    蓝牙Bluetooth技术手册规范下载【转】
    FarBox--另类有趣的网站服务【转】
    蓝牙HID协议笔记【转】
    linux 串口0x03,0x13的问题【转】
    CC254x/CC2540/CC2541库函数速查(转)
    BLE获取iphone mac地址的方法--【原创】
    用secureCRT操作ubuntu终端
  • 原文地址:https://www.cnblogs.com/StraussDu/p/7453798.html
Copyright © 2020-2023  润新知