Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Device emulation

Discussion in 'Input System' started by greggman, Apr 13, 2016.

  1. greggman

    greggman

    Joined:
    Nov 30, 2013
    Posts:
    24
    I have a library that allows players to use smartphones as controllers. This allows 50-100+ players to join a game.

    While you can use it make all kinds of custom controllers, to make it easy to get started I created a simple DPad emulator.

    The issue I ran into was AFAICT there was no way for me to inject the data into "Input". So, users had to change their code. I made my own Input class, HFTInput, and they then had to go through their code and remove references to Input and change them to HFTInput

    The new system sounds like I can add custom devices but that's not really a solution for me. Basically I want to be able to emulate standard devices (a gamepad) so that users have to change NOTHING. No need to configure some custom device and make a custom ActionMap for it, rather they just install the library and magically get as many controllers as there are. They can make a custom ActionMap later if they want to access more features but ti get started I want them to have to do nothing.

    To do this I need the new system to support a few things

    1. Let me add/remove virtual gamepads at runtime

    Provide a way for me to add/remove gamepads to the system

    2. A way for the game to be told about added/removed game pads

    I saw something in the video about getting notified a player wants to play. It wasn't clear if that was enough. Even with real controllers players might add or remove controllers on purpose or accident.

    I'm probably forgetting something.

    While writing that library another thing that came up was the ability to record and playback input. Sure I can wrap all your stuff but again that requires me to get my users to use my library as their API instead of yours which means 3rd party plugins need to get re-written etc to use my library where as if there was a way to inject/inspect that data in your library then I could write my recording/playback library in a way that would just work for everything.
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    You can make a custom device that inherits from Gamepad. Then it will be recognized as a Gamepad and will work with existing ActionMaps with gamepad-based control schemes.

    At which level of abstraction do you want to record and playback input events?

    - Get all events that come through the input system (for various devices) and record some of those (for example all gamepad events)?
    - Get events that corresponds to changes in actions for a specific ActionMap for a specific player and record those?
     
  3. greggman

    greggman

    Joined:
    Nov 30, 2013
    Posts:
    24
    Both? But off the top of my head I'd be more interested in

    > - Get all events that come through the input system (for various devices) and record some of those
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    You can do that by adding an InputEventTree node to the InputSystem.consumerStack which has callbacks to your own methods.