Interhaptics SDK for Unity 1.6
Loading...
Searching...
No Matches
HapticCapabilityCheck.cs
Go to the documentation of this file.
1/* ​
2* Copyright (c) 2023 Go Touch VR SAS. All rights reserved. ​
3* ​
4*/
5
6using UnityEngine;
7using UnityEngine.XR;
8
10{
11 public class HapticCapabilityCheck : MonoBehaviour
12 {
13 [SerializeField]
14 private bool debugMode = false;
15
16 void Start()
17 {
18 // Check for iOS
19#if UNITY_IOS
20 if (UnityEngine.iOS.Device.generation > UnityEngine.iOS.DeviceGeneration.iPhone8 &&
21 UnityEngine.iOS.Device.systemVersion.CompareTo("13") > 0)
22 {
23 DebugMode("Haptic capabilities supported on iOS.");
24 }
25 else
26 {
27 DebugMode("Haptic capabilities not supported on this iOS device.");
28 }
29#endif
30
31 // Check for Android
32#if !ENABLE_METAQUEST && !ENABLE_OPENXR && UNITY_ANDROID && !UNITY_EDITOR
33 AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
34 AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
35 AndroidJavaObject vibrator = currentActivity.Call<AndroidJavaObject>("getSystemService", "vibrator");
36 bool hasVibrator = vibrator.Call<bool>("hasVibrator");
37
38 if (hasVibrator)
39 {
40 DebugMode("Haptic capabilities supported on Android.");
41 }
42 else
43 {
44 DebugMode("Haptic capabilities not supported on this Android device.");
45 }
46#endif
47
48// Check for Windows
49#if UNITY_STANDALONE_WIN
50 if (Input.GetJoystickNames().Length > 0)
51 {
52 DebugMode("GameInput/XInput controller connected on Windows. Haptic feedback enabled.");
53 }
54 else
55 {
56 DebugMode("No GameInput/XInput controller connected on Windows. No haptic feedback.");
57 }
58#endif
59
60// Check for Meta Quest/Open XR
61#if ENABLE_METAQUEST || ENABLE_OPENXR
62 if (XRSettings.enabled)
63 {
64 DebugMode("Meta Quest/Open XR enabled.");
65 }
66 else
67 {
68 DebugMode("Meta Quest/Open XR not enabled.");
69 }
70#endif
71
72// Check for PS5
73#if UNITY_PS5
74 DebugMode("Platform is PS5. Haptic feedback enabled.");
75#endif
76
77// Check for Nintendo Switch
78#if UNITY_SWITCH
79 DebugMode("Platform is Nintendo Switch. Haptic feedback enabled.");
80#endif
81 }
82 public void DebugMode(string message)
83 {
84 if (debugMode)
85 {
86 Debug.Log(message);
87 }
88 }
89 }
90}