gpt4 book ai didi

javascript - 转换 SCORM.js 以与 Unity 5 配合使用

转载 作者:行者123 更新时间:2023-12-03 06:05:18 25 4
gpt4 key购买 nike

我正在尝试让 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”不是“Boo.Lang.Hash”的成员

好的。有人告诉我应该使用哈希表而不是普通的 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");

您还可以从外部 .js 文件调用 GameObjects 脚本组件中的 C# 函数:

SendMessage (GameObjectName, 'functionName', 'parameter');

因此,我将所有直接 SCORM 交互封装在 SCORM.js 文件中 - 它使所有 LMSSetValue('cmi.objectives... 和 LMSGetValue("cmi.core.lesson_status... 更新和管理哪些目标之前已经完成。Unity 只是告诉 SCORM 它应该初始化哪些目标。一切正常。

已排序!

关于javascript - 转换 SCORM.js 以与 Unity 5 配合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39575267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com