Giter Club home page Giter Club logo

unity-xapi-wrapper's Introduction

Unity xAPI Wrapper

Library for interacting with an LRS from within a Unity project.

At the time of writing, the library works primarily with the /statements API. Additional API interactions are in development, but, if you are solely interested in having your Unity project send and receive xAPI statements, then this library should work for you.

Using the functions and classes in this library might be a bit difficult if you are unfamiliar with xAPI.

Note: While this library has been used for a few projects without issue, it's still in development.

Issus and pull requests are welcome! ๐ŸŽˆ๐Ÿ‘

Setup

The setup will seem a bit involved, but most of this will just be typical Unity pageantry. To get the project:

  • Get the project (download as zip or clone)
  • Drop into your Unity project's Assets folder

To ensure the wrapper is working within your project:

  • Open Unity
  • Extract the required JSON.Net version for your system (see below)
  • Open the example scene (/Examples/Buttons)
  • (Optional) Create an LRS configuration (see below)
  • (Optional) Assign your LRS configuration
  • Run the example scene to check if everything's behaving โ˜•

If you didn't create an LRS configuration, the example scene will send statements to the public ADL LRS using the known tom:1234 credentials.

Additional Steps

While the example scene should work without issue, there are a few additional steps before xAPI will appear in a specified LRS -- namely: importing the required JSON.Net library and creating LRS configurations.

Extracting JSON.Net

Within Unity, double click the Json.Net Unity Package and extract the desired version (see below if confused). This should correct the sea of compiler errors and allow the example scene to run.

When you double click the Json.NET Unity Package, there will be 3 options to choose from:

  • .NET Standard 2.0 (most common)
  • .NET 4.0 (available for newer versions of Unity)
  • .NET 4.5

Json.NET Unity Package Import UI

Import the one matching your project's build settings, which can be checked at

Edit > Project Settings > Player > Api Compatibility Level

Unity Project Settings

There may be subtle differences between their .NET 4.0 and .NET 4.5 libraries, so mileage may vary between them.

Creating an LRS Configuration

To communicate with an LRS, the wrapper needs to know which LRS you intend to use. To create a new LRS Configuration:

  • Right-click inside of Unity's Project tab
  • Create > XAPI > LRS Configuration
  • Assign your endpoint
  • Assign your credentials

Once that's created, you'll need to assign that to the xAPI Messenger instance in your scene(s).

Note: This is a bit clunky, so we're open to different ways of assigning these.

Using the XAPIWrapper class and XAPI Objects

The XAPIWrapper class is intended to be your interface into sending and receiving xAPI statements with the configured LRS. The XAPI namespace itself contains class definitions for serializable xAPi objects as well as helper classes for handling timestamps and conversions.

From the included "Button" example:

public void SendSimpleStatement()
{
    var actor = Actor.FromAccount("https://auth.example.com", "some-long-user-id", name: "some-user-name");
    var verb = Verbs.Interacted;
    var activity = new Activity("https://lms.example.com", "Unity Button Example");

    var statement = new Statement(actor, verb, activity);

    XAPIWrapper.SendStatement(statement, res => {
        Debug.Log("Sent simple statement!  LRS stored with ID: " + res.StatementID); 
    });
}

Example Scene(s)

There is a simple example scene included that demonstrates how to send three different statement payloads to an LRS:

  • A single, simple statement
  • A pair of simple statements
  • A more complex statement using result and context with extensions

As this example is a bit dull, additional scenes may be added in the future or by request.

unity-xapi-wrapper's People

Contributors

vbhayden avatar the-mazzter avatar adl-trey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.