Skip to content
Jack Brookes edited this page Feb 28, 2020 ยท 10 revisions

Ideas for getting the most out of UXF

Backup your datafiles

You can hook a method into the 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;

[DontDestroyOnLoad]
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 file. Then you can safely store the files after each trial using the FileIOManager worker:

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

        // store in results, easier to access later
        trial.result["mic_filename"] = fname;

        // reference to FileIOManager
        fileIOManager.ManageInWorker(() => 
        {
            File.WriteAllBytes(outputLocation, data);
        });

๐Ÿง  Core topics

โ“ More help


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

Unit tests

Clone this wiki locally