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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

What's the right way to switch Input Modules per device?

Discussion in 'Scripting' started by rorylane, Nov 11, 2015.

  1. rorylane

    rorylane

    Joined:
    Apr 10, 2013
    Posts:
    22
    Hi all.

    I am cross-developing between mobile and VR.

    In VR, I want to use a 3D cursor that floats on a global canvas.

    On mobile, I want to use regular touch events.

    I have developed an input module that simulates touch events on a world canvas with a 3D cursor in VR mode.

    However, I'm not sure what the best way is to switch between which interface module is used when on different devices.


    Here's my project so far:
    WIN 64:
    http://www.arthavoc.com/VR_Cursor/VR_Cursor_Builds.7z

    Unity Package:
    http://www.arthavoc.com/VR_Cursor/VR_Cursor_Package.unitypackage

    I'm sure I could use the Platform Defines to enable and disable the needed input module. I just want to make sure that's the best way to do it.

    Here are my scenarios:
    In editor, I want it to use the touch input device, which uses mouse events in preview mode. Also, I need to hide the 3D cursor.

    On a tablet, I need it to use a regular touch input device, and hide the 3D cursor.

    When executing the Windows build with VR enabled, I want it to use my custom module with the 3D cursor visible.

    Is the right way to do this just enabling and disabling the various modules on the EventSystem using platform defines?

    Thanks
    -Rory-
     
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    One thing I've done to take it further was to use a scenepostprocessor to remove certain objects in certain build setups.
     
  3. rorylane

    rorylane

    Joined:
    Apr 10, 2013
    Posts:
    22

    So, using the Platform Defines is the right way to do it?

    You just have both input modules on the EventSystem, and disable the one you're not using?
     
  4. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Sure. There is also the Application.platform property you can check. But why do runtime checks if you dont need to. In the end, using the eventsystem, you will need to remove or disable features youre not using.