Scorm API
Scorm packages run on LMS that run on Web Browsers.
IScormService scormService; #if UNITY_EDITOR scormService = new ScormPlayerPrefsService(); // PlayerPrefs implementation (for editor testing) #else scormService = new ScormService(); // Real implementation #endif bool result = scormService.Initialize(Scorm.Version.Scorm_1_2); // Begins communication with the LMS if (result) { scormService.SetMinScore(0); // Sets a min score of 0 scormService.SetMaxScore(10); // Sets a max score of 10 scormService.SetRawScore(6.5f); // Sets a score of 6.5
scormService.Commit(); // Commit the pending changes scormService.Finish(); // Ends communication with the LMS } |
.
A heavy code rewritten happened between 1.x and 2.x versions so you need to follow this guide if you want to upgrade an existing project.
Before updating remove “Assets/ScormAPI” folder and then import the new package. I have removed some files between 1.x and 2.x so if you don’t do this you will mix old and new version together creating many errors.
Example code has also been upgraded so maybe you can see there the required changes.
- ScormAPI is now ScormService.
- ScormService is no longer a MonoBehaviour so you don't need to drag it as a component.
- ScormService is no longer following Singleton pattern, it's up to the developer if he wants to use it that way.
For allowing an easier upgrade you can copy this code in a new script file. This way you can used it as a Singleton like before.
public class Singleton<T> where T : class, new() { private static T instance = null; public static T Instance { get { if (instance == null) { instance = new T(); } return instance; } } } public class ScormAPI : Singleton<ScormService> { } |
- ScormService implements an interface to make it easier to fake it in editor and be able to test it there.
- To establish a new connection with the LMS you need to call:
scormService.Initialize(Scorm.Version.Scorm_1_2); // Scorm 1.2 scormService.Initialize(Scorm.Version.Scorm_2004); // Scorm 2004 |
- IsInitialized is now IsConnected.
- Enums are no longer inside ScormAPI class.
- All events have been removed. "Get*" methods are no longer "void" and return directly the value that was send previously in the event.
- GetCommentsFromLMS becomes GetCommentsFromLms.
- Exit becomes SetExitReason.
- OnUserClosed event has been removed because there is no way to ensure that when users closes a browser tab or the entire browser it will send that pending request. You need to save your data on regular intervals or have checkpoints like in games to ensure that user doesn’t lost any data.
You need to remove this block in index.html file because it no longer requires template customization (that’s why I don’t provide any custom templates anymore):
<script type="text/javascript" src="js/ostynscormtime.js"></script> <script type="text/javascript" src="js/scorm.js"></script> <script type="text/javascript"> var processedUnload = false; var scorm = new Scorm("Scorm %UNITY_CUSTOM_SCORM_VERSION%"); window.onbeforeunload = function(e) { doUnload(); }; window.onunload = function(e) { doUnload(); }; function doUnload() { if (processedUnload) return; processedUnload = true; SendMessage("ScormAPI", "Close"); } </script> |
It can build a “*.zip” file ready to upload to a LMS:
Every time you build to WebGL/WebPlayer platform, it will generate a “*.zip” file in the desired path.
If you don’t have or can’t have access to a LMS you can test it with the following applications:
Supports 1.2/2004:
https://rusticisoftware.com/resources/test-scorm/
Supports only 1.2.
http://www.reload.ac.uk/scormplayer.html
Note: It’s a really old software that has some issues like not allowing to have double quotes on string values. For example, you can encounter issues testing suspend data if you store JSON data.
Implemented all the equivalent 1.2/2004 API:
https://scorm.com/scorm-explained/technical-scorm/run-time/run-time-reference/
Properties |
public string IsConnected { get; } public Version Version { get; } |
Methods |
public void Initialize(Version version); public void Commit(); public void Finish(); |
Methods |
public string GetStringValue(string element); bool SetValue(string element, string value); int GetIntValue(string element); bool SetValue(string element, int value); float GetFloatValue(string element); bool SetValue(string element, float value); |
Methods |
public string GetLearnerId(); |
Methods |
public string GetLearnerName(); |
Methods |
public string GetLessonLocation(); public bool SetLessonLocation(string value); |
Methods |
public CreditType GetCredit(); |
Methods |
public LessonStatus GetLessonStatus(); public bool SetLessonStatus(LessonStatus value); |
Methods |
public EntryType GetEntry(); |
Methods |
public float GetRawScore(); public bool SetRawScore(float value); |
Methods |
public float GetMaxScore(); public bool SetMaxScore(float value); |
Methods |
public float GetMinScore(); public bool SetMinScore(float value); |
Methods |
public int GetTotalTime(); |
Methods |
public LessonMode GetLessonMode(); |
Methods |
public bool SetExitReason(ExitReason value); |
Methods |
public bool SetSessionTime(int milliseconds); |
Methods |
public string GetSuspendData(); public bool SetSuspendData(string value); |
Methods |
public string GetComments(); |
Methods |
public string GetCommentsFromLms(); |
Methods |
public List<ObjectiveData> GetObjectives(); public void SetObjective(ObjectiveData value); |
Methods |
public string GetLanguage(); |
Unity generates a “.htaccess” file that it’s not a valid file for Docebo. You must remove it from the output Scorm zip file.