xlua的迁入与hotfix的环境配置
转载自:https://blog.csdn.net/qq_35422344/article/details/85929276
using UnityEngine;
using XLua;
[Hotfix]//添加这个标签后,就可以对类中任一方法进行更改
public class HotfixTest : MonoBehaviour
{
LuaEnv luaenv = new LuaEnv();// lua虚拟环境
public int tick = 0; //如果是private的,在lua设置xlua.private_accessible(CS.HotfixTest)后即可访问 // Use this for initialization void Start() { } // Update is called once per frame [LuaCallCSharp]//添加标签,在Lua中调用C# void Update() { if (++tick % 50 == 0) { Debug.Log(">>>>>>>>Update in C#, tick = " + tick); } } void OnGUI() { if (GUI.Button(new Rect(10, 10, 300, 80), "Hotfix")) { //对类中某个方法打补丁 //xlua.hotfix(CS.HotfixTest,)//(类名,想要修复的方法,替换代码) luaenv.DoString(@" xlua.hotfix(CS.HotfixTest, 'Update', function(self) --找到主相机,并输出名字 在Update中使用lua调用c#,要在Update上添加标签 [LuaCallCSharp] local a= CS.UnityEngine.GameObject.Find('Main Camera') CS.UnityEngine.Debug.Log(a.name) self.tick = self.tick + 1 if (self.tick % 50) == 0 then print('<<<<<<<<Update in lua, tick = ' .. self.tick) end end) "); } string chHint = @"在运行该示例之前,请细致阅读xLua文档,并执行以下步骤:
1.宏定义:添加 HOTFIX_ENABLE 到 ‘Edit > Project Settings > Player > Other Settings > Scripting Define Symbols’。
(注意:各平台需要分别设置)
2.生成代码:执行 ‘XLua > Generate Code’ 菜单,等待Unity编译完成。
3.注入:执行 ‘XLua > Hotfix Inject In Editor’ 菜单。注入成功会打印 ‘hotfix inject finish!’ 或者 ‘had injected!’ 。";
string enHint = @"Read documents carefully before you run this example, then follow the steps below:
- Define: Add ‘HOTFIX_ENABLE’ to ‘Edit > Project Settings > Player > Other Settings > Scripting Define Symbols’.
(Note: Each platform needs to set this respectively)
2.Generate Code: Execute menu ‘XLua > Generate Code’, wait for Unity’s compilation.
3.Inject: Execute menu ‘XLua > Hotfix Inject In Editor’.There should be ‘hotfix inject finish!’ or ‘had injected!’ print in the Console if the Injection is successful.";
GUIStyle style = GUI.skin.textArea;
style.normal.textColor = Color.red;
style.fontSize = 16;
GUI.TextArea(new Rect(10, 100, 500, 290), chHint, style);
GUI.TextArea(new Rect(10, 400, 500, 290), enHint, style);
}
}
1、将Xlua Assets中的内容copy到目标项目的Assets内
2、将XLua内的Tools复制到项目Assets外
3、打开项目,在项目的Build Settings——Other Settings——Scripting Define Symbols填入:HOTFIX_ENABLE
4、将本地Unity目录下的\Editor\Data\Managed下的Unity.Cecil.dll、Unity.Cecil.Mdb.dll、Unity.Cecil.Pdb.dll三个文件复制到项目中的\Assets\XLua\Src\Editor文件夹下
注意:不可将XLua放在中文目录下
5、逐步运行Unity中的XLua—Generate Code、Hotfix Inject In Editor(若第一次未出现,再重复运行一次).
6、打包发布时,需删掉XLua中的Examples,并且重新运行:XLua—Clear Generated Code—Generate Code—Hotfix Inject In Editor
- xlua的迁入与hotfix的环境配置
- xlua框架unity环境配置及lua和C#的链接 xluaHotFix热更新
- cocos2dx-lua开发环境搭建及Cocos2d-JS环境配置教程windows打包apk同样在mac环境也一样打包ios的ipk
- VC6.0配置LUA编译环境及LUA调用C++函数的简单示例
- 【最新版】从零开始在 macOS 上配置 Lua 开发环境
- Cocos2dx 3.4 BabeLua 3.0.1.0 Windows下lua环境配置
- Lua环境配置
- VC6.0+Lua 5.1.4 环境配置
- sublimeText 使用技巧及配置Lua开发环境
- Sublime Text 2配置Lua开发环境
- window 下vs 配置lua 环境 c/c++与lua交互
- 详解LUA开发工具及其环境配置
- Windows+Sublime Text3配置Lua开发环境的图文详细步骤
- Lua - 环境配置
- 详解LUA开发工具及其环境配置
- MinGW+Lua环境配置小结
- Lua For Windows环境配置及Editplus编辑工具使用
- lua——环境配置
- 详解LUA开发工具及其环境配置
- 编译Lua库并配置开发环境