转换 SCORM.js 以使用 Unity 5

Converting SCORM.js to work with Unity 5

我正在尝试让 SCORM 1.2 与我们的 Unity 5 WebGL 项目一起工作。

我以为我会逐步介绍SCORM代码;这是我想要 'translate' 以便它在 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'

好的。有人告诉我应该使用 Hashtables 而不是普通的 ol' 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 模板来执行此操作),然后您可以调用这些 .js 文件。来自 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 它应该初始化哪些目标。一切正常。

已排序!