Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: zaddo on October 01, 2013, 07:21:00 AM

Title: Gamepad controller for custom cursor
Post by: zaddo on October 01, 2013, 07:21:00 AM
I want to use a gamepad to drive a custom cursor and interact with the NGUI menu as the mouse cursor would normally.  I am doing this for an Ouya version of my game.  (Yes I know, you can use the DPad to move between buttons, but this won't work for how I have structured my game)

I have the custom cursor working inside my game and interacting as a replacement for normal mouse.

However, I don't know if I am approaching this the wrong way, but I am finding this tricky to get it working with NGUI panels. i.e. getting events Hover, OnClick, etc to work as they normally would with the windows mouse.

I initially looked at using UICamera.onCustomInput, but I found that a lot of the stuff I needed to handle was already in UICamera.ProcessMouse()

So, for the first time, I started modding the base NGUI code.  I have copied the ProcessMouse method to a new method ProcessGamepad and calling this instead of the ProcessMouse.

It is going Ok, but I am just hitting a few hurdles and I am not sure how many I have left to jump before I get this working.

So... as I am a lazy programmer  ;) I searched this forum, but couldn't find any posts of a similar nature.

Before I leave, I just thought ask the community, if my approach is the easiest solution to achieve my objective?

Title: Re: Gamepad controller for custom cursor
Post by: ArenMook on October 01, 2013, 07:12:21 PM
I strongly suggest you make use of the onCustomInput functionality if you can, even if you have to duplicate code from inside the UICamera class. It will make it easier for you to stay up to date when you need to update NGUI. Aside from that, I don't see anything wrong with what you're trying to do.
Title: Re: Gamepad controller for custom cursor
Post by: Stridulent on November 06, 2013, 03:14:40 PM
I am doing something similar and could use some help.

I have a custom cursor that is a texture in its own panel and its position is driven by Input.GetAxis("Mouse X") and Input.GetAxis("Mouse Y"). This is so the user can use either the keyboard and mouse or an xbox controller. The movement works great, but I am not sure how to get it to interact with NGUI elements (such as buttons).

I see the mention of onCustomInput below, but I have no idea where to start with it. Could use some guidance. Thanks!
Title: Re: Gamepad controller for custom cursor
Post by: ArenMook on November 07, 2013, 04:53:58 AM
onCustomInput delegate gets called by UICamera, letting you add your own input logic. This thread from two days ago may help:

http://www.tasharen.com/forum/index.php?topic=6409

Some additional ones:
http://www.tasharen.com/forum/index.php?topic=6447.msg30601#msg30601
http://www.tasharen.com/forum/index.php?topic=6119.msg29013#msg29013

Just search for "MouseOrTouch" to find more.
Title: Re: Gamepad controller for custom cursor
Post by: littledrill on February 07, 2014, 07:13:25 AM
I'm developing for OUYA, and want to support the controller.
I have a bunch of buttons with UIButtonKeys set up. If I press arrow down it selects the below button.

I've added below script.
This "works", the below button will be selected when I press dpad-down, but there is no highlighting. The hover color is not shown when using the ouya controller. Should I approach this in another way?

  1.    void Start () {
  2.       UICamera.onCustomInput = OuyaNguiInput;
  3.    }
  4.  
  5.    void OuyaNguiInput() {
  6.       if (OuyaInput.GetButtonDown(OuyaButton.DD,OuyaPlayer.P01))
  7.             UICamera.Notify(UICamera.selectedObject, "OnKey", KeyCode.DownArrow);
  8. ...
  9. }
  10.  
Title: Re: Gamepad controller for custom cursor
Post by: ArenMook on February 08, 2014, 02:35:27 PM
You forgot to set
  1. currentScheme = ControlScheme.Controller;
Look at UICamera.ProcessOthers function. Line 1285 for example.