日落20181024002 - Unity插件应用之tolua

系统:Windows 10
引擎:Unity 2017.2.1f1
插件:tolua

(1)下载tolua。

tolua 的 github 资源库查看, https://github.com/topameng/tolua
下载tolua-master.zip,https://github.com/topameng/tolua/archive/master.zip
在这里插入图片描述

(2)tolua-master压缩后,把其中的Assets目录内容复制到工程目录的Assets目录里面。

在这里插入图片描述

(3)做一个简单实例

(3-1)场景布局如下:

在这里插入图片描述

(3-2)加一个LuaHelper.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LuaHelper {

	public static void PrintA(string strMsg)
	{
		GameObject go = GameObject.Find ("TextA");
		Text txt = go.GetComponent<Text>();
		txt.text = strMsg;
	}
}
(3-3)把刚创建的类LuaHelper加载到Assets\Editor\Custom\CustomSettings.cs
//在这里添加你要导出注册到lua的类型列表
public static BindType[] customTypeList =
{
	// 省略默认代码...
	_GT(typeof(LuaHelper)),
};
(3-4)先用菜单Lua/Clear wrap files,清空生成wrap文件,再用菜单Lua/Generate Al,生成全部wrap文件。
(3-5)把Lua/Main.lua的Main函数内容改为
--主入口函数。从这里开始lua逻辑
function Main()					
	print("logic start")
	require("MuyTest")
	MuyTest:Init()
end
(3-6)添加MuyTest.lua文件到Lua目录下,代码内容为:
MuyTest = {}

function MuyTest:Init()
	print("MuyTest")
	LuaHelper.PrintA("aaaaaaaaaaa");
end
(3-7)Resources方式打包的话,参考官方例子TestCustomLoader。

目录:[工程目录]\Assets\ToLua\Examples\13_CustomLoader
点击菜单Lua/Copy Lua files to Resources,会把Lua文件复制到Resources目录。

(3-8)Bundle方式打包的话,参考官方例子TestABLoader。

目录:[工程目录]\Assets\ToLua\Examples\18_Bundle
先点击菜单Lua/Copy Lua files to Resources,再点击菜单Lua/Build bundle files not jit,会把Lua文件复制到temp/Lua目录。

(4)打包效果:

(4-1)Resources方式:

在这里插入图片描述

(4-2)Bundle方式:(Bundle方式尚未能用Lua调用CSharp接口,所以没有aaaaa,研究中…)

在这里插入图片描述

以上简单回顾。

参考资料:
Unity3D中tolua的“安装部署和使用“教程
http://www.cnblogs.com/rekcah1986/p/6846425.html

toLua简单使用
https://blog.csdn.net/u012941657/article/details/51671854

用好Lua+Unity,让性能飞起来——Lua与C#交互篇
http://www.cnblogs.com/zwywilliam/p/5999924.html
http://www.cnblogs.com/zwywilliam/p/5999980.html

安卓报错LuaException: cannot open tolua.lua: No such file or directory
https://github.com/topameng/tolua/issues/75

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值