Skip to content

Releases: imDanoush/Unity-DirectInput

Direct Input Manager v1.0f

11 Jan 21:05
Compare
Choose a tag to compare

🎮 Unity DirectInput Force Feedback & Input Mapping System - Major Update

image

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
  • FFB device re-attach now works without DInput Mapper interruptions

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

Demo Software

11 Jan 21:19
433ea03
Compare
Choose a tag to compare

Unity DirectInput Force Feedback Demo 🎮

Experience the power of DirectInput force feedback with this comprehensive demo application! This showcase demonstrates the capabilities of the Unity DirectInput system with an intuitive, runtime-configurable interface.

Key Features

  • Real-time FFB Configuration - Fine-tune your force feedback effects during gameplay, including:

    • Basic forces (Constant, Damper, Friction, Inertia, Spring)
    • Periodic effects (Sine, Square, Triangle, Sawtooth)
    • Collision simulation testing
  • Dynamic Input Mapping - Configure your DirectInput device mappings on the fly:

    • Visual input detection system
    • Real-time axis value monitoring
    • Automatic device detection
    • Persistent configuration storage

User Experience

  • Toggle FFB configuration with F3
  • Access input mapping with F2
  • Right-click sliders to reset values
  • Save/load configurations between sessions
  • Smart device search and auto-connection

Perfect for racing game developers and simulation enthusiasts looking to implement professional-grade force feedback and input systems in their Unity projects.

Built based on the DirectInput plugin of MrTimCackes and ATG-Simulator's improvements, this demo provides a complete reference implementation for DirectInput device management in Unity with Unity's Input System.