Author Topic: Using NGUI drag detection to as alternative to Input.GetAxis?  (Read 4080 times)

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Using NGUI drag detection to as alternative to Input.GetAxis?
« on: November 25, 2013, 01:03:58 AM »
Hi.

I'm working on a project that will be shipped on touch-enabled Windows 7 PCs with some weird touch screen implementation, which is a problem for standard Unity input methods. Internally it works like a mouse, but I can't figure out how mouse drag is implemented there, which is a problem for some of my scripts. While Input.GetMouseButtonDown(0) works, Input.GetAxis("Mouse X") receives no value changes ever on that PC, for some reason. Here is an example of small script that rotates the models in front of a secondary 3D camera in my UI for as long as you press a mouse button and move your mouse horizontally. Ideally, it should also translate to "hold your finger on the screen and swipe":

  1. public float horizontalSpeed = 1.0f;
  2. public float drag = 0.95f;
  3. Vector3 v3Rotation = Vector3.zero;
  4.  
  5. void Update () {
  6.         if (Input.GetMouseButton(0)) {
  7.                 v3Rotation.y += horizontalSpeed * Input.GetAxis("Mouse X");
  8.         }
  9.         v3Rotation *= drag;
  10.         transform.Rotate (v3Rotation);
  11. }

Good thing is, I have noticed that all NGUI elements are still performing flawlessly on that PC even without a mouse, probably owing to using some custom methods that continue to work no matter if Unity writes down some stuff or not. In particular, scroll bars were still functional.

So, the question is: can I get a value similar to Input.GetAxis ("Mouse X") from NGUI scripts, or can I rewrite the code above in a way that will use NGUI drag detection? I have tried testing OnDrag () but it wasn't firing for some reason (maybe it's for objects that are being dragged and not something that gets called every time drag is done anywhere), so I would appreciate a proper example of using NGUI methods. I don't need anything fancy like collision detection, it's literally the "swipe anywhere on screen, rotate anything on screen" kind of deal.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using NGUI drag detection to as alternative to Input.GetAxis?
« Reply #1 on: November 25, 2013, 03:24:03 AM »
NGUI doesn't rely on getting the axis. Instead it calculates its own delta using the current mouse position and the frame's last mouse position. This is probably why it works.