- Notifications
You must be signed in to change notification settings - Fork 26
Using with Unity
Matt edited this page Feb 28, 2023
·
3 revisions
To use this DLL with unity you need to add both hidapi.dll and AirAPI_Windows.dll to your unity project.
Configure both hidapi.dll and AirAPI_Windows.dll for x64
This demo creates a connection and prints the Euler and Quaternion data
//AirApi.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingSystem.Runtime.InteropServices;usingSystem;publicclassAirAPI:MonoBehaviour{[DllImport("AirAPI_Windows",CallingConvention=CallingConvention.Cdecl)]staticexternintStartConnection();[DllImport("AirAPI_Windows",CallingConvention=CallingConvention.Cdecl)]staticexternintStopConnection();[DllImport("AirAPI_Windows",CallingConvention=CallingConvention.Cdecl)]staticexternIntPtrGetQuaternion();[DllImport("AirAPI_Windows",CallingConvention=CallingConvention.Cdecl)]staticexternIntPtrGetEuler();float[]EulerArray=newfloat[3];IntPtrEulerPtr;float[]QuaternionArray=newfloat[4];IntPtrQuaternionPtr;voidStart(){// Start the connectionvarres=StartConnection();if(res==1){Debug.Log("Connection started");}else{Debug.Log("Connection failed");}}voidUpdate(){// Get array data from memoryQuaternionPtr=GetQuaternion();Marshal.Copy(QuaternionPtr,QuaternionArray,0,4);EulerPtr=GetEuler();Marshal.Copy(EulerPtr,EulerArray,0,3);// Print dataDebug.Log("Quaternion: "+QuaternionArray[0]+" "+QuaternionArray[1]+" "+QuaternionArray[2]+" "+QuaternionArray[3]);Debug.Log("Euler: "+EulerArray[0]+" "+EulerArray[1]+" "+EulerArray[2]);}}