🎮 Unity DirectInput Force Feedback & Input Mapping System - Major Update
This comprehensive update improves DirectInput force feedback implementation and adds new runtime configuration features.
Core Architecture Changes
- Replaced SAFEARRAY with direct memory management (const char**) for string arrays
- Added proper memory cleanup routines with RAII patterns
- Improved error handling with HRESULT returns
- Updated C# interop layer for reliable marshaling
New Features
-
Runtime FFB Configuration UI (F3 key toggle)
- Complete force feedback effects control panel
- Live axis value monitoring
- Device auto-detection with search functionality
- Persistent settings via PlayerPrefs
-
Runtime Input Mapping UI (F2 key toggle)
- Real-time input assignment system
- Visual feedback for the Input mapping process
- Right-click to reset values
- Duplicate mapping name detection
Editor Enhancements
- Edit mode mapping configuration
- Device search term management
- Input/device string editing
- Add/remove mapping functionality
- Improved error handling and validation
Technical Improvements
-
Memory Management
- Proper GUI cleanup and initialization
- Enhanced error handling for device connections
- Streamlined save/load system
- Eliminated SafeArray versioning issues
- Added proper cleanup of unmanaged resources
-
Device Communication
- Added DBTEvents enum for device state changes (0x0007, 0x8000, 0x8004)
- Implemented proper callback mechanism with __stdcall convention
- Added static callback storage (g_deviceCallback) to prevent garbage collection
- Fixed callback parameter type matching between C# and C++
-
UI/UX Enhancements
- Improved UI layout and styling
- Better runtime vs edit mode separation
- Enhanced error reporting with detailed messages
Files Modified
- DirectInputForceFeedback.h
- DirectInputForceFeedback.cpp
- DirectInputManager.cs
- DirectInputTypes.cs
- [UI related files]
Testing & Validation
- Verified string array marshaling works across different machines
- Confirmed memory cleanup works correctly
- Validated error handling in edge cases
- Tested UI functionality in both runtime and edit modes
Technical Impact
- Better memory management and resource handling
- Improved reliability across different machines
- Reduced potential for versioning conflicts
- Enhanced error reporting and user feedback
- More robust device connection handling
- Improved overall system stability