Search Unity

Need to ignore all mouse input

Discussion in 'UGUI & TextMesh Pro' started by SiBlack, Mar 23, 2015.

  1. SiBlack

    SiBlack

    Joined:
    Jun 12, 2013
    Posts:
    22
    Hi,

    I'm making a joypad only menu (hiding and locking the mouse). It all works fine using SetSelectedGameObject to focus on buttons etc.

    However there is one critical failing; If the mouse button is clicked the menu loses its selection and it is not possible to get it back, so the player becomes stuck.

    Is there a way to get Ugui to ignore the mouse completely?

    Thanks.
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Only way to remove the mouse would be to disable or remove the current input modules.

    Might be better if you only want to use gamepad, to create your own input module attached to the event system with just gamepad controls. (using the existing input modules as a template)
    You can see the source for the existing input modules here:
    https://bitbucket.org/Unity-Technol...ityEngine.UI/EventSystem/InputModules/?at=4.6

    Hope this helps
     
  3. SiBlack

    SiBlack

    Joined:
    Jun 12, 2013
    Posts:
    22
    Thanks for pointing me at the source for the StandaloneInputModule. That got it sorted. It was a simple fix;

    Code (CSharp):
    1. private bool UseMouse(bool pressed, bool released, PointerEventData pointerData)
    2.         {
    3.             if (DisableMouse && (pressed || released || pointerData.IsPointerMoving() || pointerData.IsScrolling()))
    4.                 return false;
    5.             else if (pressed || released || pointerData.IsPointerMoving() || pointerData.IsScrolling())
    6.                 return true;
    7.            
    8.             return false;
    9.         }
    Using a bool to throw away the mouse input means I can toggle it on and off with ease.

    Much appreciated :)
     
    SimonDarksideJ likes this.