前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >修改Unity中Lua文件的默认打开程序

修改Unity中Lua文件的默认打开程序

作者头像
meteoric
发布2018-11-20 10:13:50
发布2018-11-20 10:13:50
2.8K00
代码可运行
举报
文章被收录于专栏:游戏杂谈游戏杂谈
运行总次数:0
代码可运行

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

昨办?

….

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

代码语言:javascript
代码运行次数:0
复制
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 + " \t " + 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。

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-08-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档