Immerse SDK
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code

Using a code based approach to reporting provides more flexibility when sending statements. It is currently the only way to send a statement with attachments.

Each method for sending a statement has an async overload that can be awaited. This is useful for ensuring that statements are sent before continuing or before exiting the application.

Activities

To send an activity statement, first you need reference to the Activity asset you wish to report. Then use the ReportActivity or ReportActivityAsync method accordingly. A Result object must be supplied (optionally a ResultBuilder can be used instead)

Below is an example showing how to create an awaitable method that will send a statement with a score, with a success value driven by a threshold.

using System.Threading.Tasks;
using ImmerseSDK.Platform.Reporting.Statements;
using ImmerseSDK.Platform.Reporting.Structure;
using UnityEngine;

public class ActivityExample : MonoBehaviour
{
    [SerializeField] private Activity _activity;
    [SerializeField] private int _maxScore = 10;
    [SerializeField] private int _threshold = 8;

    public async Task SendScore(int score)
    {
        var result = new Result
        {
            Success = score >= _threshold,
            Score = new Score { Raw = score, Max = _maxScore }
        };

        await _activity.ReportActivityAsync(result);
    }
}

Actions

Action statements are similar to Activity statements in that they require an activity, but for the action it is used as it’s parent. The ReportAction and ReportActionAsync methods require a verb and a subject.

The example below is designed to report an action when an object is grabbed.

using ImmerseSDK.Platform.Reporting.Structure;
using ImmerseSDK.Platform.Reporting.Structure.Verbs;
using UnityEngine;

public class ActionExample : MonoBehaviour
{
    [SerializeField] private Activity _activity;
    [SerializeField] private VerbObject _verb; // Use 'Picked up' verb

    public void OnGrab(string target)
    {
        _activity.ReportAction(_verb, target);
    }
}