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

Implementing a "virtual" input device - Where to fill in the data?

Discussion in 'Input System' started by TomasRiker, Aug 20, 2019.

  1. TomasRiker

    TomasRiker

    Joined:
    Jan 26, 2012
    Posts:
    48
    I'm trying to implement a virtual input device with only two controls:
    position
    (type
    Vector3
    ) and
    orientation
    (type
    Quaternion
    ). These should simply be copied from a
    Transform
    's position and orientation.

    So I created this class (following something I found in the documentation):
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3. using UnityEngine.InputSystem.Controls;
    4. using UnityEngine.InputSystem.Layouts;
    5.  
    6. #if UNITY_EDITOR
    7. [UnityEditor.InitializeOnLoad]
    8. #endif
    9. [InputControlLayout(updateBeforeRender = true)]
    10. public class TransformInputDevice : InputDevice
    11. {
    12.     [InputControl]
    13.     public Vector3Control position { get; private set; }
    14.  
    15.     [InputControl]
    16.     public QuaternionControl orientation { get; private set; }
    17.  
    18.     static TransformInputDevice()
    19.     {
    20.         InputSystem.RegisterLayout<TransformInputDevice>();
    21.     }
    22.  
    23.     [RuntimeInitializeOnLoadMethod]
    24.     private static void InitializeInPlayer()
    25.     {
    26.     }
    27.  
    28.     protected override void FinishSetup()
    29.     {
    30.         base.FinishSetup();
    31.  
    32.         position = GetChildControl<Vector3Control>(nameof(position));
    33.         orientation = GetChildControl<QuaternionControl>(nameof(orientation));
    34.     }
    35. }
    Now what I don't know is how to actually make this device return some data.
    InputDevice
    doesn't have any methods like
    Update
    etc. that I could override, so where do the devices actually get its real input? I don't find anything about this anywhere in the documentation ...
     
  2. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    We recently added some documentation for this. Not sure when exactly we pushed it so could be it's not yet in 0.9.3.

    Let me know if something's not clear.
     
    TomasRiker likes this.
  3. TomasRiker

    TomasRiker

    Joined:
    Jan 26, 2012
    Posts:
    48
    Great, thanks for pointing it out! Exactly what I was looking for.