使用VSCode+XLua开发Unity

如何进行调试(luaide):

1.保证addLoader中的路径是绝对路径,把调试文件放到main文件同级目录。
2.在main文件中加入代码
3.使用其中的高阶用法可以在断点时查看c#属性的值
https://www.jianshu.com/p/dda945be6bc2

local breakSocketHandle,debugXpCall = require("LuaDebugjit")("localhost",7003)

XLua代码提示(luaide):

在vscode设置中搜索:apiType --> xlua

隐藏.mete文件

在settings.json文件中加入"files.exclude": 栏
添加 "*/.meta":true 项
如:

image.png

使用lua的基本思路

调用mian文件时,给mian文件加上新的类(例如:start)的元表,在新的类(例如:start)中去初始化其他业务类,并把业务类存储到一个inittable中,在__index中设置awake,update等方法,并遍历所有的inittable,调用其中的awake,update等方法,然后再c#中相应的函数中调用这些函数,以实现初始化,update等特定需求。

使用静态列表和动态列表配置C#文件供lua脚本使用

using System.Collections.Generic;
using System;
using XLua;
using System.Reflection;
using System.Linq;

public static class HotfixCfg
{
    [Hotfix]
    public static List<Type> by_property
    {
        get
        {
            return (from type in Assembly.Load("Assembly-CSharp").GetTypes()
                    where type.Namespace == "XLua"
                    select type).ToList();
        }
    }
}
using System.Collections.Generic;
using System;
using XLua;
using System.Reflection;
using System.Linq;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;

public static class StaticCfg
{
    [LuaCallCSharp]
    public static List<Type> mymodule_lua_call_cs_list = new List<Type>()
    {
        typeof(GameObject),
        typeof(Dictionary<string, int>),
        typeof(GameObject),
        --typeof(PrefabsMap),
    };
}

以上文件放到XLua中的Editor文件夹中才会生效。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容