APSchmidt 发表于 2021-9-24 07:34

使用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{        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{        public static List<Type> mymodule_lua_call_cs_list = new List<Type>()    {      typeof(GameObject),      typeof(Dictionary<string, int>),      typeof(GameObject),      --typeof(PrefabsMap),    };}
以上文件放到XLua中的Editor文件夹中才会生效。
页: [1]
查看完整版本: 使用VSCode+XLua开发Unity