unity教程二:配置xlua环境

( 1 )先根据文档配置运行

1.下载Xlua源码
https://github.com/Tencent/xLua/

2.复制Assets和Tools里面文件到工程文件里面


WX20210823-173827.png
WX20210823-173838.png

3.添加宏HOTFIX_ENABLE


WX20210823-174413.png
WX20210823-174453.png
WX20210823-174526.png

4.生成注入代码


WX20210823-174638.png

5运行例子


WX20210823-174832.png

( 2 )优化存放目录结构

1.下面目录位置不变
Tools
Assets/Plugins

2.进入Assets/XLua目录
删除示范资源,Doc,Examples,Tutorial,Editor文件夹

移动Assets/XLua/Src/Editor 到 Assets/Editor(编辑器插件相关的都放这里), 并修改名字为XLua
移动Assets/XLua/Resources 到 Assets/AssetsPackage/Lua/ (AssetsPackage文件夹为项目资源文件夹), 并修改名字为XLua

剩下的文件,把Assets/XLua 移动到 Assets/Scripts/XLua

修改Assets/Editor/XLua/Generator.cs

// 修改前 public static string common_path = Application.dataPath + "/XLua/Gen/";
public static string common_path = Application.dataPath + "/Scripts/XLua/Gen/";

摆放好文件后,写个简单的代码测试下lua*

using UnityEngine;
using XLua;

public class Helloworld : MonoBehaviour
{
    // Use this for initialization
    void Start()
    {
        LuaEnv luaenv = new LuaEnv();
        luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')");
        luaenv.Dispose();
    }

    // Update is called once per frame
    void Update()
    {

    }
}

*有个小插曲,就是弄完这些后,代码运行总是提示LuaEnv找不到,折腾好久都没有成功,后来关机睡一觉第二天过来好像可以了?可能是因为要重启unity?暂时没找到原因,记录下。

你可能感兴趣的:(unity教程二:配置xlua环境)