Skip to content
Jack Brookes edited this page Apr 26, 2021 · 10 revisions

Ideas for getting the most out of UXF

Backup your datafiles

You can hook a method into the On Write File Event in the FileIOManager component of UXF Rig that copies files to a secondary location.

Singleton access

Even though it can lead to bad programming practices, you may opt to use a "singleton" programming technique to make accessing the UXF Session easier. Here is an example - attach this script to your UXF Rig and it will persist between scenes and be globally accessible with PersistentRigAccess.uxfSession.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PersistentRigAccess : MonoBehaviour
{

    public static UXF.Session uxfSession;

    private void Awake()
    {
        // make sure only one
        PersistentRigAccess[] rigs = GameObject.FindObjectsOfType<PersistentRigAccess>();
        if (rigs.Length > 1) Destroy(this.gameObject);

        DontDestroyOnLoad(this);

        uxfSession = GetComponentInChildren<UXF.Session>();
    }
}

Record audio

You can record audio on each trial using Unity's microphone class and then convert to a WAV byte array. Then you can safely store the data after each trial using the trial.SaveBytes() method:

        // method that converts audioclip to wav bytes
        byte[] data = WavUtility.FromAudioClip(newClip);
        string fname = string.Format("mic_T{0:000}.wav", trial.number);

        // save data, automatically puts it in the session folder.
        // it will also store the name in the trial_results file for easier referencing during analysis.
        trial.SaveBytes(data, fname);

๐Ÿง  Core topics

โ“ More help


๐Ÿ‘ฉโ€๐Ÿ’ป Programming reference

Unit tests

Clone this wiki locally