Search Unity

Detecting Pinch Zoom Via Interactions or Processors

Discussion in 'Input System' started by GingerLoaf, Apr 8, 2021.

  1. GingerLoaf

    GingerLoaf

    Joined:
    Dec 5, 2012
    Posts:
    18
    I am using the new Input System to abstract away the specific details behind the devices used, and I really love that aspect of the new system. I am having a big issue trying to lump the mouse wheel and pinch to zoom into a single "zoom" action.

    I do know a solution, but I don't like it. I can make an action specifically for touch devices alone that does a zoom specifically with actual knowledge of two touches... but that breaks my design because it makes assumptions about technologies used to cause actions.

    So, I find myself trying to somehow compose the Vector2 for the "zoom" action by making a composite control made up of touches. This doesn't seem to work since the composite parts are expected to be up, down, left, and right. I don't see a way I can make this happen and wanted to reach out and see if anyone had ideas for me to try out.
     

    Attached Files:

    Tony_Max likes this.
  2. GingerLoaf

    GingerLoaf

    Joined:
    Dec 5, 2012
    Posts:
    18
    I might be making progress here:

    Code (CSharp):
    1. #if UNITY_EDITOR
    2.     [InitializeOnLoad]
    3. #endif
    4.     public class test : InputProcessor<Vector2>
    5.     {
    6.        
    7. #if UNITY_EDITOR
    8.         static test()
    9.         {
    10.             Initialize();
    11.         }
    12. #endif
    13.  
    14.         [RuntimeInitializeOnLoadMethod]
    15.         static void Initialize()
    16.         {
    17.             InputSystem.RegisterProcessor<test>();
    18.         }
    19.  
    20.         public override Vector2 Process(Vector2 value, InputControl control)
    21.         {
    22.             //$$ snag both positions and then produce your vector2 here
    23.             var potentialControl0 = control.device.TryGetChildControl<Vector2Control>("/touch0/position");
    24.             var potentialControl1 = control.device.TryGetChildControl<Vector2Control>("/touch1/position");
    25.             return value;
    26.         }
    27.  
    28.     }
     
    Tony_Max likes this.
  3. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    353
    Have you came up with something? Can you share processor final code?
    I have a trouble with checking
    InputControl
    state. It seems like for /touch0/position there is no way to get propert
    IsActuated()
    (probably because it doesn't support magnitude evaluation). So how you handle case, when input system detect touch0 without touch1?

    UPD0: Figured out that for such purposes modifiers suits better

    UPD1: finally got it to work (described in this thread)
     
    Last edited: Dec 5, 2022