代码之家  ›  专栏  ›  技术社区  ›  moosefetcher

正在转换SCORM。js与Unity 5合作

  •  0
  • moosefetcher  · 技术社区  · 8 年前

    我正在尝试让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'

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

    如何将属性添加到嵌套在变量中的Hashtable?

    1 回复  |  直到 8 年前
        1
  •  1
  •   moosefetcher    8 年前

    我最终听从了这一页的建议:

    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应该初始化哪些目标。所有工作都很好。

    排序!