Beispiel #1
0
        public void EnableForceFeedback()
        {
#if UNITY_STANDALONE_WIN
            if (ffbEnabled)
            {
                return;
            }

            if (UnityFFBNative.StartDirectInput() >= 0)
            {
                ffbEnabled = true;
            }
            else
            {
                ffbEnabled = false;
            }

            int deviceCount = 0;

            IntPtr ptrDevices = UnityFFBNative.EnumerateFFBDevices(ref deviceCount);

            Debug.Log($"[UnityFFB] Device count: {devices.Length}");
            if (deviceCount > 0)
            {
                devices = new DeviceInfo[deviceCount];

                int deviceSize = Marshal.SizeOf(typeof(DeviceInfo));
                for (int i = 0; i < deviceCount; i++)
                {
                    IntPtr pCurrent = ptrDevices + i * deviceSize;
                    devices[i] = Marshal.PtrToStructure <DeviceInfo>(pCurrent);
                }

                foreach (DeviceInfo device in devices)
                {
                    string ffbAxis = UnityEngine.JsonUtility.ToJson(device, true);
                    Debug.Log(ffbAxis);
                }

                if (autoSelectFirstDevice)
                {
                    SelectDevice(devices[0].guidInstance);
                }
            }
#endif
        }