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

prevent StandaloneInputModule keyboard/gamepad from raking through UI controls

Discussion in 'UGUI & TextMesh Pro' started by djweinbaum, Sep 4, 2014.

  1. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I want to prevent StandaloneInputModule from raking through multiple UI objects when you only mean to move one over. I've attempted to illustrate it:


    The common solution to this is having some kind of lock that lets up after the player has held down a direction for a certain amount of time (like maybe half a second), at which point the lock lets up and it can start to quickly rake through buttons.

    I've been trying to set inputActionsPerSecond to 0 but for some it doesn't work again after I set it back to 20.
    Code (CSharp):
    1. bool _rakeLock = false;
    2. public bool RakeLock {
    3.     get {
    4.         return _rakeLock;
    5.     } set {
    6.         if (_rakeLock == value) return;
    7.         if (value) {
    8.             GameManager.standaloneInput.inputActionsPerSecond = 0f;
    9.         }
    10.         else {
    11.             GameManager.standaloneInput.inputActionsPerSecond = 20f;
    12.         }
    13.         _rakeLock = value;
    14.     }
    15. }
    How would you guys handle this?

    Thanks so much.
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    In the StandaloneInputModule there is this function:

    https://gist.github.com/stramit/ce455682b7944bdff0e7

    Code (csharp):
    1.  
    2. private bool SendMoveEventToSelectedObject()
    3. {
    4.     float time = Time.unscaledTime;
    5.  
    6.     if (!AllowMoveEventProcessing (time))
    7.         return false;
    8.  
    9.     Vector2 movement = GetRawMoveVector ();
    10.     //Debug.Log(m_ProcessingEvent.rawType + " axis:" + m_AllowAxisEvents + " value:" + "(" + x + "," + y + ")");
    11.     var axisEventData = GetAxisEventData (movement.x, movement.y, 0.6f);
    12.     if (!Mathf.Approximately (axisEventData.moveVector.x, 0f)
    13.         || !Mathf.Approximately (axisEventData.moveVector.y, 0f))
    14.     {
    15.         if (m_CurrentInputMode != InputMode.Buttons)
    16.         {
    17.             // so if we are chaning to keyboard
    18.             m_CurrentInputMode = InputMode.Buttons;
    19.  
    20.             // if we are doing a 'fresh selection'
    21.             // return as we don't want to do a move.
    22.             if (ResetSelection ())
    23.             {
    24.                 m_NextAction = time + 1f / m_InputActionsPerSecond;
    25.                 return true;
    26.             }
    27.         }
    28.         ExecuteEvents.Execute (eventSystem.currentSelectedObject, axisEventData, ExecuteEvents.moveHandler);
    29.     }
    30.     m_NextAction = time + 1f / m_InputActionsPerSecond;
    31.     return axisEventData.used;
    32. }
    33.  
    This is where we are using the input per second to handle the control lockout. If you want to make your own StandaloneModule that modifies this function then that's probably the best thing. If you figure out a nice way to do the raking I would love to take the code back into out main branch.
     
  3. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Thanks @Tim C for pointing me in the right direction. I'm trying to brew something up right now. I want to ask though, when I attempted to make a new module I copied the code from github StandaloneInputModule into my new class and got:
    Code (CSharp):
    1. Assets/Scripts/GUI/dw_StandaloneInputModule.cs(333,46): error CS1061: Type `UnityEngine.EventSystems.PointerEventData' does not contain a definition for `pressPositon' and no extension method `pressPositon' of type `UnityEngine.EventSystems.PointerEventData' could be found (are you missing a using directive or an assembly reference?)
    2.  
    pressPositon is actually supposed to be pressPosition. I'm confused. Is the GitHub not the latest one? I have b18.
     
  4. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
  5. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Ah okay, I see.

    So I've been working on this, and I'm too dense to decipher how the StandaloneInputModule works well enough to implement the raking thing. I got it working but sometimes it would miss your input if you were clicking buttons really quickly which feels terrible. I burned an entire day on it so I decided to give up trying to understand it. I simply made my own module that handles button navigation. I now have two, MouseInputModule which is a stripped down version of Standalone to only handle mouse, and ButtonInputModule which operates at full frame and does its own logic that figures out what button is in the direction you pushed. I've attached mouse input one in case anyone is looking for a mouse only (doesn't even process mouse clicks) module. My button input one is a bit specialized to my game so I don't think anyone would find it useful.
     

    Attached Files:

    Senshi likes this.