zoukankan      html  css  js  c++  java
  • 修改Unity中Lua文件的默认打开程序

    项目中引用了XLua,而Lua文件又是以txt文件结尾的,当修改系统的扩展脚本编辑器为vs后双击lua文件(xx.txt)默认也使用vs打开了,无提示的黑白文本编辑悲伤

    image

    昨办?

    ….

    后来看到网上有写Unity的插件,想着应该也能判断后缀名然后调用指定的编辑器,果然可以。直接贴代码了(C#文件,只要建一个名为Editor的目录 —— 与路径无关,扔进去就行,Unity会自动编译的)

    using UnityEngine;
    using UnityEditor;
    using System;
    
    public class LuaTxtEditor
    {
    
        //http://www.xuanyusong.com/archives/3702 
    
        [UnityEditor.Callbacks.OnOpenAssetAttribute(1)]
        public static bool step1(int instanceID, int line)
        {
            //string name = EditorUtility.InstanceIDToObject(instanceID).name;
            //Debug.Log("Open Asset step: 1 (" + name + ")");
    
            return false;
        }
    
        [UnityEditor.Callbacks.OnOpenAssetAttribute(2)]
        public static bool step2(int instanceID, int line)
        {
            string strFilePath = AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(instanceID));
            string strFileName = Application.dataPath + "/" + strFilePath.Replace("Assets/", "");
    
            if (strFileName.EndsWith(".txt"))
            {
                string strZBStudioPath = Environment.GetEnvironmentVariable("ZEROBRANESTUDIO_PATH");
    
                if (strZBStudioPath != null && strZBStudioPath.Length > 0)
                {
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                    startInfo.FileName = strZBStudioPath + (strZBStudioPath.EndsWith("/") ? "" : "/") +  "zbstudio.exe";
                    startInfo.Arguments = strFileName;
                    process.StartInfo = startInfo;
                    process.Start();
    
                    //Debug.Log(startInfo.FileName + " 	 " + startInfo.Arguments);
    
                    return true;
                }
                else
                {
                    Debug.Log("Not Found Enviroment Variable 'ZEROBRANESTUDIO_PATH'.");
    
                    return false;
                }            
            }
    
            //string name = EditorUtility.InstanceIDToObject(instanceID).name;
            //Debug.Log("Open Asset step: 1 (" + name + ")");
    
            return false;
        }
    
    }

    上面使用ZeroBraneStudio来打开lua文件,你也可以修改为自己常用的编辑器,上面使用了环境变量获取程序的安装路径。

    另外介绍几个小技巧:

    1、shift + space(空格键),打以让鼠标所停留的视窗最大化

    2、Unity在运行模式(Play)下所做的修改是不保存的,为了防止这种误操作,可以修改运行模式下的颜色;

    菜单Edit –> Preferences –> Colors –> playmode tint。

    image

    更多的技巧,可以参考知乎:Unity游戏开发有哪些让你拍案叫绝的技巧?

  • 相关阅读:
    【转】ios输入框被键盘挡住的解决办法
    【转】操作系统Unix、Windows、Mac OS、Linux的故事
    mac 下删除非空文件夹
    解决Win7 64bit + VS2013 使用opencv时出现提“应用程序无法正常启动(0xc000007b)”错误
    图的邻接表表示
    图的邻接矩阵表示
    并查集
    05-树9 Huffman Codes及基本操作
    05-树7 堆中的路径
    堆的操作集
  • 原文地址:https://www.cnblogs.com/meteoric_cry/p/7374077.html
Copyright © 2011-2022 走看看