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 ...
随机推荐
- 16. 3Sum Closest
题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given ...
- 【Java EE 学习 34】【struts2学习第一天】
一.struts2简介 struts2是一个用来开发MVC应用程序的框架.它提供了Web应用程序开发过程中的一些常见问题的解决方案. 1.struts2的作用域范围:三层架构当中的第一层,相当于MVC ...
- Logistic回归的使用
Logistic回归的使用和缺失值的处理 从疝气病预测病马的死亡率 数据集: UCI上的数据,368个样本,28个特征 测试方法: 交叉测试 实现细节: 1.数据中因为存在缺失值所以要进行预处理,这点 ...
- SAP 传感器辅助定位
一.简述 SAP:Sensor Assist Position 传感器辅助定位.高通公司提供的技术方案,旨在提升当卫星信号较差或终端短暂丢失卫星信号时终端的定位能力.该方案可分为三个阶段,第一.二阶段 ...
- Intent传递list<bean>集合
首先你定义的bean需要继承Serializable接口 //传递list<bean>集合Intent intent = new Intent(ViolationOfTheQueryAct ...
- Codeforces Round #370 - #379 (Div. 2)
题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi ...
- 限制Xamarin获取图片的大小
限制Xamarin获取图片的大小在App开发中,经常会使用网络图片.因为这样不仅可以减少App的大小,还可以动态更新图片.但是手机使用网络环境千差万别.当网络环境不是理想的情况下,加载网络图片就是一个 ...
- ORACLE操作列
一.下面介绍oracle数据库操作列的CURD操作 --学生表 STUDENT CREATE TABLE STUDENT( ID NUMBER(18) NOT NULL, NAME VARCHAR2( ...
- Android 图标尺寸与设计
样例和图解 外框:整体大小 ↑ 边框:图标留白大小 ↓ 图标:外图标的大小 ↑ 阴影:阴影特效大小 ↓ 图形:内图标的大小 ↑ 可选视图权重:使用两种类型的图形尺寸可以达到统一的视觉权重(可选), ...
- 2016 CCPC长春重现赛
1.2016中国大学生程序设计竞赛(长春)-重现赛 2.总结:会做的太少,应变能力也不行,或者说猜题目的能力不行 02 水 04 HDU 5914 Triangle 1.题意:1~n,n个数,问 ...