unity webgl Tolua/Ulua
我使用的版本:1.最新版LuaFrameWork地址 :
2.最新版tolua_runtime地址 :
参考大神的配置:
1.再网页中运行 出现Uncaught abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/kripken/emscripten/wiki/Linking") at Error
我查询了下 意思时不支持动态dll的意思.
Uncaught abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/kripken/emscripten/wiki/Linking") at Error
解决方法:添加 unity_webgl ,看图
luaDll.cs 中添加 UNITY_WEBGL
2. 因为添加了UNITY_WEBGL,没有webgl的dll,我就下载了大神提供的库,搬砖,避免以后大神关了,我就下不了。
链接:https://pan.baidu.com/s/1CKDFeTQaEqd0AWs4cqO_6A
提取码:sfme
把plugins 下webgl 目录放入自己项目中即可
webgl tolua 的库文件
.我尝试使用大神提供的包在unity2019.4.24上发布webgl,总是提示我有编译错误,没有提示再什么地方.
后来我查看代码,发现没有unityengine的依赖,在编辑器下(F12)都无法跳转,后来我就把整个项目导出*.unitypackage,新建一个项目,导入就可行了.
3. 再次发布版本的爆出一个 python.exe 打包错误,重启都没用,
解决方法: 最后把Library删除,重现编译打包成功
4.使用iis配置网站,其中网页中出现无法加载 *.unityweb 的错误
解决方法:
5. 运行又出错了 missing function: luaopen_sproto_core UnityLoader.js:1150
这时才想起没在unity编辑器下测试,直接运行就出现 EntryPointNotFoundException: luaL_newstate,按照大神的例子,我也添加了webgl库的,奇怪了.
解决方法:参考
方法1:把Library、Temp都删除掉,保留Assets、ProjectSettings、Packages, 重新打开工程。(亲测,有效)
方法1: 其他人的方法: EtyPoinNotfoundEception: luaL newstate这个错误是因为在如果在Unt中是没置了IPhone平台,但是ulua的代码没有排除Editor环境,Dillmport错误造成的。 (未找到,我没有ios平台)
editor webgl下没有错了
最后成功了: 这是一个简单的代码,纯lua,没有绑定c#, 走到这一步说明lua 虚拟机在webgl上运行是没有问题了,下一步继续
using System.Collections;
using System.Collections.Generic;
using LuaInterface;
using UnityEngine;
public class webglLua : MonoBehaviour
{
LuaState lua = null;
private string strLog = "";
void Start()
{
Application.logMessageReceived += Log;
lua = new LuaState();
lua.Start();
//如果移动了ToLua目录,自己手动修复吧,只是例子就不做配置了
string fullPath = Application.dataPath + "\\ToLua/Examples/02_ScriptsFromFile";
lua.AddSearchPath(fullPath);
}
void Log(string msg, string stackTrace, LogType type)
{
strLog += msg;
strLog += "\r\n";
}
private string luastr = @"print('12345')";
void OnGUI()
{
GUI.Label(new Rect(100, Screen.height / 2 - 100, 600, 400), strLog);
luastr = GUI.TextField(new Rect(700, Screen.height / 2 - 100, 600, 400), luastr);
if (GUI.Button(new Rect(50, 50, 120, 45), "DoString"))
{
strLog = "";
lua.DoString(luastr);
UnityEngine.Debug.Log("121");
}
lua.Collect();
lua.CheckTop();
}
void OnApplicationQuit()
{
lua.Dispose();
lua = null;
#if UNITY_5 || UNITY_2017 || UNITY_2018
Application.logMessageReceived -= Log;
#else
Application.RegisterLogCallback(null);
#endif
}
}
打印了内容
在这里已经完成了一部分了,接下来需要做的是:lua和c#的交互 webgl中
方案:1.把所有lua文件打包成一个AB,在webgl启动后先去加载ab,
2.设置c#warp的绑定等
目前我已经做成功了,稍后我会把中间遇到的问题、踩的坑一一记录下来
https://124.220.26.113/static/webglTolua/index.html
我共享了源码和发布的包:
页:
[1]