#if UNITY_ANDROID && !UNITY_EDITOR #define XREALPLUGIN_SUPPORTS_TARGET_PLATFORM #endif using System.Runtime.InteropServices; using UnityEngine; using UnityEngine.XR.Management; namespace Unity.XR.XREAL { /// /// Provides a set of utility functions and events for interacting with the XREAL XR Plugin. /// public static partial class XREALPlugin { /// /// Exits the application or editor, deinitializing the XR loader if active. /// public static void QuitApplication() { Debug.Log("[XREALPlugin] QuitApplication"); if (XREALUtility.GetActiveLoader() != null) { XRGeneralSettings.Instance.Manager.DeinitializeLoader(); } #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #elif UNITY_ANDROID if (XREALMultiResumeMediator.Singleton != null && XREALSettings.GetSettings().SupportMultiResume) { Debug.Log("[XREALPlugin] ForceKill"); XREALMultiResumeMediator.Singleton.ForceKill(); } else { Debug.Log("[XREALPlugin] Quit"); Application.Quit(); } #else Debug.Log("[XREALPlugin] Quit"); Application.Quit(); #endif } /// /// Sets the target frame rate for the application. /// /// The desired frame rate. public static void SetTargetFrameRate(int targetFrameRate) { #if XREALPLUGIN_SUPPORTS_TARGET_PLATFORM Internal.SetTargetFrameRate(targetFrameRate); #endif } /// /// Gets the current target frame rate of the application. /// /// The target frame rate. public static int GetTargetFrameRate() { #if XREALPLUGIN_SUPPORTS_TARGET_PLATFORM return Internal.GetTargetFrameRate(); #else return 0; #endif } /// /// Sets the dominant hand for controller interaction. /// /// True if the right hand is dominant; false for the left hand. public static void SetDominantHand(bool isRightHand) { #if XREALPLUGIN_SUPPORTS_TARGET_PLATFORM Internal.SetDominantHand(isRightHand); #endif } /// /// Recenters the controller's tracking rotation. /// public static bool RecenterController() { #if XREALPLUGIN_SUPPORTS_TARGET_PLATFORM return Internal.RecenterController(); #else return false; #endif } /// /// Gets the current input source for the XREAL input system. /// /// The current input source. public static InputSource GetInputSource() { #if XREALPLUGIN_SUPPORTS_TARGET_PLATFORM return Internal.GetInputSource(); #else return InputSource.Controller; #endif } /// /// Sets the input source for the XREAL input system. /// /// The input source to set. public static bool SetInputSource(InputSource inputSource) { #if XREALPLUGIN_SUPPORTS_TARGET_PLATFORM return Internal.SetInputSource(inputSource); #else return false; #endif } /// /// Switches the current input source between hands and controller. /// /// True if the input source was successfully switched; otherwise, false. public static bool SwitchInputSource() { #if XREALPLUGIN_SUPPORTS_TARGET_PLATFORM if (GetInputSource() == InputSource.Controller) return SetInputSource(InputSource.Hands); else return SetInputSource(InputSource.Controller); #else return false; #endif } /// /// Checks if hand tracking is supported by the XREAL input system. /// /// True if hand tracking is supported; otherwise, false. public static bool IsHandTrackingSupported() { #if XREALPLUGIN_SUPPORTS_TARGET_PLATFORM return Internal.IsHandTrackingSupported(); #else return false; #endif } private static partial class Internal { [DllImport(LibName)] public static extern void SetTargetFrameRate(int targetFrameRate); [DllImport(LibName)] public static extern int GetTargetFrameRate(); [DllImport(LibName)] internal static extern void SetDominantHand(bool isRightHand); [DllImport(LibName)] internal static extern bool RecenterController(); [DllImport(LibName)] internal static extern InputSource GetInputSource(); [DllImport(LibName)] internal static extern bool SetInputSource(InputSource inputSource); [DllImport(LibName)] internal static extern bool IsHandTrackingSupported(); } } }