Unity WebGL MoonSharp崩溃问题
当前Unity的代码更新方案基本都选择的ULua,而我们项目还需要考虑Web平台,ULua不支持WebGL,所以决定选择MoonSharp。MoonSharp(http://www.moonsharp.org/)是一个纯C#实现的Lua解释器,支持多种平台。
测试环境:Unity5.4 + WebGL + MoonSharp 1.6.0.0
测试代码:
double MoonSharpFactorial()
{
string script = @"
-- defines a factorial function
function fact (n)
if (n == 0) then
return 1
else
return n*fact(n - 1)
end
end return fact(5)"; DynValue res = Script.RunString(script);
return res.Number;
}
在Web浏览器中却崩溃了,后经过定位发现是MoonSharp.Interpreter.Loaders.UnityAssetsScriptLoader.LoadResourcesWithReflection出错,Bug和我的修改已经在GitHub提交给作者了,预计很快会合并到主干代码中。
void LoadResourcesWithReflection(string assetsPath)
{
try
{
Type resourcesType = Type.GetType("UnityEngine.Resources, UnityEngine");
Type textAssetType = Type.GetType("UnityEngine.TextAsset, UnityEngine"); MethodInfo textAssetNameGet = textAssetType.GetProperty("name").GetGetMethod();
MethodInfo textAssetTextGet = textAssetType.GetProperty("text").GetGetMethod(); MethodInfo loadAll = resourcesType.GetMethod("LoadAll",
new Type[] { typeof(string), typeof(Type) }); Array array = (Array)loadAll.Invoke(null, new object[] { assetsPath, textAssetType });//此处崩溃,估计是Unity导出代码有Bug for (int i = ; i < array.Length; i++)
{
object o = array.GetValue(i); string name = textAssetNameGet.Invoke(o, null) as string;
string text = textAssetTextGet.Invoke(o, null) as string; m_Resources.Add(name, text);
}
}
catch (Exception ex)
{
#if !PCL
Console.WriteLine("Error initializing UnityScriptLoader : {0}", ex);
#endif
}
}
可以改为
void LoadResourcesWithReflection(string assetsPath)
{
try
{
#if UNITY_WEBGL
UnityEngine.TextAsset[] arrayTextAsset = UnityEngine.Resources.LoadAll<UnityEngine.TextAsset>(assetsPath);
for (int i = ; i < arrayTextAsset.Length; i++)
{
UnityEngine.TextAsset text = arrayTextAsset[i];
m_Resources.Add(text.name, text.text);
}
return;
#endif Type resourcesType = Type.GetType("UnityEngine.Resources, UnityEngine");
Type textAssetType = Type.GetType("UnityEngine.TextAsset, UnityEngine"); MethodInfo textAssetNameGet = textAssetType.GetProperty("name").GetGetMethod();
MethodInfo textAssetTextGet = textAssetType.GetProperty("text").GetGetMethod(); MethodInfo loadAll = resourcesType.GetMethod("LoadAll",
new Type[] { typeof(string), typeof(Type) }); Array array = (Array)loadAll.Invoke(null, new object[] { assetsPath, textAssetType }); for (int i = ; i < array.Length; i++)
{
object o = array.GetValue(i); string name = textAssetNameGet.Invoke(o, null) as string;
string text = textAssetTextGet.Invoke(o, null) as string; m_Resources.Add(name, text);
}
}
catch (Exception ex)
{
#if !PCL
Console.WriteLine("Error initializing UnityScriptLoader : {0}", ex);
#endif
}
}
Unity WebGL MoonSharp崩溃问题的更多相关文章
- 关于 Unity WebGL 的探索(二)
关于 Unity WebGL 的探索(二) 上一篇博客记录了关于 WebGL 移植的第一步:部分 C/C++ 插件的编译,目前项目中的部分插件使用该方法通过,接下来比较大的一部分工作量是网络模块 We ...
- 关于 Unity WebGL 的探索(一)
到今天为止,项目已经上线一个多月了,目前稳定运行,各种 bug 也是有的.至少得到了苹果的两次推荐和 TapTap 一次首页推荐,也算是结项后第一时间对我们项目的一个肯定. 出于各种各样的可描述和不可 ...
- Unity WebGL 窗口自适应
unity 打包好WebGL后,用文本编辑器编辑打包生成的 index.html 文件 在生成的html里面修改代码 <script type="text/javascript ...
- Unity WebGL请求Http接口出现的Cors跨域问题
1.运行环境 (1)WebGL运行浏览器:Firfox Quantum 67.0(64位) (2)服务端API运行环境:IIS,.Net Core 2.1 API 2.问题:CORS 头缺少Acces ...
- Unity WebGL WebSocket
在线示例 http://39.105.150.229/UnityWebSocket/ 快速开始 安装环境 Unity 2018.3 或更高. 无其他SDK依赖. 安装方法 通过 OpenUPM 安装 ...
- Unity WebGL
路过弄了个unity Unity导出WebGL不支持c#socket和unity的network 可以用javascript的websocket实现... c#一般通过www从phpserver获取. ...
- Unity发布WebGL时如何修改默认的载入进度条
Unity发布WebGL版本后,需要去除Unity的Logo,首先关闭Splash Image去除Made with Unity启动画面(在File->Build Settings->Pl ...
- Unity发布WebGl注意事项
unity 版本是5.5,不过看了2017的文档好像也是差不多,绝大部分都是根据官方文档,希望有帮助,如果有错误或者你知道更多这方面的只是,请告知下,大恩言谢. 1:对webgl发布的工程文件说明 ...
- 【Unity】开发WebGL内存概念具体解释和遇到的问题
自增加unity WebGL平台以来.Unity的开发团队就一直致力于优化WebGL的内存消耗. 我们已经在Unity使用手冊上有对于WebGL内存管理的详尽分析,甚至在Unite Europe 20 ...
随机推荐
- 关于Promise模式 整理中。。。
http://blog.csdn.net/womendeaiwoming/article/details/49849055 研究了几天Promise模式,因为在项目里也遇到了所谓的“回调陷阱”,就是多 ...
- c#接口
//接口中方法 属性 事件等默认都是public 不允许用修饰符修饰 public interface IEventInterFace { string this[int index] { get; ...
- mac在终端下中用sublime text 2 打开文件
alias subl=\''/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'\'然后subl 要打开的文件名即可但是这 ...
- linux升级openssl
wget https://www.openssl.org/source/openssl-1.0.2j.tar.gz ./config shared zlib-dynamicconfig完成后执行 ma ...
- DOM动画效果的基础入门2
一.动画效果 Transform字面上就是变形,改变的意思,在css3中transform主要包括以下几种: 选转 rotate,扭曲 skew 缩放 scale 和移动translate 以及矩形变 ...
- mybatis 书写
查询语句是使用 MyBatis 时最常用的元素之一 select元素配置细节如下 属性 描述 取值 默认 id 在这个模式下唯一的标识符,可被其它语句引用 parameterType 传给此语 ...
- IP地址,子网掩码,默认网关,DNS服务器详解
为了更深入的学习TCP/IP协议,最近看了不少有关资料,收集整理记录如下,以备后面的使用和方便各位学习: IP地址,子网掩码,默认网关,DNS服务器是什么意思? (一) 问题解析 001. 问: ...
- SQLite -- 分页查询
原文:http://blog.csdn.net/lu1024188315/article/details/51734514 参考:http://www.runoob.com/sqlite/sqlite ...
- DTD文档模型和HTML基础
html是超文本标记语言,现在常用到的2中文档格式是html5和XHTML 1.0 Transitiona(过渡). <!DOCTYPE html> <!--当前文档为html5-- ...
- Ubuntu防火墙设置
转载自:http://baisongfly.blog.163.com/blog/static/30135117200923005956159/ 1.安装 sudo apt-get install uf ...