将SCORM.js转换为Unity 5
Converting SCORM.js to work with Unity 5
我正在尝试让SCORM 1.2与我们的Unity 5 WebGL项目一起工作。
我想我会逐渐引入SCORM代码;以下是我想要"翻译"的代码,以便它在Unity中工作:
var vault = {}; //vault 'namespace' helps ensure no conflicts with possible other "SCORM" variables
vault.UTILS = {}; //For holding UTILS functions
vault.debug = { isActive: true }; //Enable (true) or disable (false) for debug mode
vault.SCORM = { //Define the SCORM object
version: null, //Store SCORM version.
handleCompletionStatus: true, //Whether or not the wrapper should automatically handle the initial completion status
handleExitMode: true, //Whether or not the wrapper should automatically handle the exit mode
API:{handle: null, isFound: false}, //Create API child object
connection: { isActive: false }, //Create connection child object
data: { completionStatus: null, exitStatus: null}, //Create data child object
debug:{} //Create debug child object
};
当我使用该代码时,Unity告诉我'Utils' is not a member of 'Boo.Lang.Hash'
OK。我被告知我应该使用哈希表而不是普通的javascript对象。这是我目前得到的:
var vault:Hashtable = new Hashtable(); //vault 'namespace' helps ensure no conflicts with possible other "SCORM" variables
vault['UTILS'] = new Hashtable(); //For holding UTILS functions
vault['debug'] = new Hashtable(); //Enable (true) or disable (false) for debug mode
vault['debug']['isActive'] = true;
vault['SCORM'] = { //Define the SCORM object
version: null, //Store SCORM version.
handleCompletionStatus: true, //Whether or not the wrapper should automatically handle the initial completion status
handleExitMode: true, //Whether or not the wrapper should automatically handle the exit mode
API:{handle: null, isFound: false}, //Create API child object
connection: { isActive: false }, //Create connection child object
data: { completionStatus: null, exitStatus: null}, //Create data child object
debug:{} //Create debug child object
};
但是现在Unity抛出以下错误:
Type 'Object' does not support slicing
…在vault['debug']['isActive'] = true;
线上。
所以-我如何添加属性到一个变量嵌套的哈希表?
我最终遵循了这个页面的建议:
https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html它建议将外部。js文件正常加载到包含的html文件中(你必须设置一个自定义的WebGL html模板来做到这一点),然后你可以从c#调用这些。js函数,使用:
Application.ExternalCall("functionName", "parameter");
你也可以在GameObjects的脚本组件中调用c#函数,从外部.js文件中,使用:
SendMessage (GameObjectName, 'functionName', 'parameter');
所以,我在SCORM.js文件中封装了所有直接的SCORM交互—它使所有的LMSSetValue('cmi. aims ....和LMSGetValue("cmi.core.lesson_status…更新和管理哪些目标已经完成。Unity只是告诉SCORM应该初始化哪些目标。一切正常。
排序!
相关文章:
- 如何在JavaScript中将字符串转换为函数引用
- 如何在Javascript中将JSon对象转换为数组
- 使用JS将数组转换为json对象
- 如何使用json将对象列表从java转换为javascript
- 偶尔结结巴巴地说“;堆叠的”;translate()上的转换(v4.0.0-alpha40)
- 为什么在单独的函数中应用时转换会闪烁/断断续续(D3)
- 在Javascript中转换对象数组
- 将数字转换为一定数量的硬币
- 将纯文本URL转换为可单击链接
- 当图像转换为本地存储的DataURL时,EXIF被删除
- 如何使用js将SNAPSHOT内部版本号转换为3位数的整数
- 如何将TypeScript对象转换为普通对象
- 检测个位数整数时正在转换毫秒
- 从javascript到jquery的转换
- DOM事件通过JSON转换为java
- 将圆柱体转换为弯管
- 混合 ui-sref 和 $state.go 在 Angular ui-router 中进行状态转换
- JavaScript代码问题:我正在将对象转换为数组
- 如何将字母转换为二进制代码
- 将SCORM.js转换为Unity 5