using System; using System.Runtime.InteropServices; using UnityEngine; /// /// C# interface for the native OpenVR access plugin. /// This script provides access to the native plugin functions. /// public static class OpenVRNativeAccess { // Import functions from the native plugin #if UNITY_STANDALONE_WIN private const string PluginName = "VRIMUDriver"; #elif UNITY_STANDALONE_OSX private const string PluginName = "VRIMUDriver"; #elif UNITY_STANDALONE_LINUX private const string PluginName = "VRIMUDriver"; #else private const string PluginName = "VRIMUDriver"; #endif // Initialize the plugin and connect to OpenVR [DllImport(PluginName)] public static extern bool InitializePlugin(); // Shutdown the plugin and disconnect from OpenVR [DllImport(PluginName)] public static extern void ShutdownPlugin(); // Get raw gyroscope data from the headset [DllImport(PluginName)] public static extern bool GetRawGyroscopeData(out float x, out float y, out float z); // Get raw accelerometer data from the headset [DllImport(PluginName)] public static extern bool GetRawAccelerometerData(out float x, out float y, out float z); // Check if the headset is connected [DllImport(PluginName)] public static extern bool IsHeadsetConnected(); // Get the current tracking state [DllImport(PluginName)] public static extern bool IsTrackingValid(); // Get the driver name [DllImport(PluginName)] public static extern IntPtr GetDriverName(); // Helper method to get the driver name as a string public static string GetDriverNameString() { IntPtr namePtr = GetDriverName(); if (namePtr != IntPtr.Zero) { return Marshal.PtrToStringAnsi(namePtr); } return "Unknown"; } }