将SCORM.js转换为Unity 5

Converting SCORM.js to work with Unity 5

本文关键字:Unity 转换 SCORM js      更新时间:2023-09-26

我正在尝试让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应该初始化哪些目标。一切正常。

排序!