• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

[Unity热更新]VSCode使用EmmyLua调试lua代码

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

参考链接:

https://blog.csdn.net/qq_34035956/article/details/109255357

https://www.cnblogs.com/zhizihua/p/12857245.html

https://www.showdoc.com.cn/luaide/713892723028836

 

0.环境

jdk、jre(EmmyLua插件需要)

vscode、xlua

查看jdk是否安装成功:

 

1.设置

修改launch.json,其中的ideConnectDebugger,ide指的是vscode,Debugger指的是unity,这里设置为false即表示用unity来连接vscode

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "emmylua_new",
            "request": "launch",
            "name": "EmmyLua New Debug",
            "host": "localhost",
            "port": 9966,
            "ext": [
                ".lua",
                ".lua.txt",
                ".lua.bytes"
            ],
            "ideConnectDebugger": false
        }
    ]
}

将这个dll复制粘贴到工程的Assets同级目录下

 

2.代码

TestEmmyLua.lua

local str = "start"
for i = 1, 3 do
    str = "hello:" .. i
end
str = "end"

c#

using System.IO;
using UnityEngine;
using XLua;

public class TestEmmyLua : MonoBehaviour
{
    private LuaEnv luaenv;

    void Start()
    {
        luaenv = new LuaEnv();
        string currentDirectory = Directory.GetCurrentDirectory();
        if (File.Exists(currentDirectory + "/emmy_core.dll"))
        {
            string str = @"xpcall(function() local dbg = require('emmy_core') dbg.tcpConnect('localhost', 9966) end, function() print('IDE没有开启调试') end)";
            luaenv.DoString(str);
        }
        luaenv.AddLoader(CustomLoader);
        luaenv.DoString("require('TestEmmyLua')");
    }

    private byte[] CustomLoader(ref string filePath)
    {
        //print(filePath);
        filePath = Application.dataPath + "/LuaScript/" + filePath + ".lua";
        //print(filePath);
        byte[] bytes = File.ReadAllBytes(filePath);
        return bytes;
    }
}

注意一下,CustomLoader方法的参数,需要修改为该文件的路径

 

3.运行

在vscode中设置好断点,点击左上角的运行按钮,此时下方会提示等待连接

运行unity,这时就会命中断点了


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
uLua学习笔记之一lua脚本打包与读取发布时间:2022-07-22
下一篇:
windows下编译lua源码(转载)发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap