Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Malzbier on July 24, 2012, 04:26:28 AM

Title: Button and drag behavior on mac vs iOS
Post by: Malzbier on July 24, 2012, 04:26:28 AM
Both clever admins gave me some nice tips to get my special Drag and drop , to work. ( http://www.tasharen.com/forum/index.php?topic=1085.0 (http://www.tasharen.com/forum/index.php?topic=1085.0) )
On mac , its running like a charm, but on iOS its misbehaving.


How is the button / input behavior different between both platforms?
Title: Re: Button and drag behavior on mac vs iOS
Post by: ArenMook on July 24, 2012, 04:31:40 AM
iOS doesn't receive any form of hover events, but everything else should function as expected. Be sure to turn off 'mouse events' on the UICamera if you're using the Unity Remote.
Title: Re: Button and drag behavior on mac vs iOS
Post by: Malzbier on July 24, 2012, 04:42:09 AM
Im not using Unity Remote , and im not targeting any hover animation / events.

The color ( and the size) of the button is keeping after pressed, is the color that is set for Pressed and not for Hover.


edit: is there a way to have 2 events on one script? (like OnPress and OnRelease)
Title: Re: Button and drag behavior on mac vs iOS
Post by: ArenMook on July 24, 2012, 05:46:05 AM
What version of NGUI are you using and what is your approach for your drag & drop?

OnPress() has a parameter -- OnPress(bool isPressed). This means when the button is pressed you get OnPress(true), and when it's released you get OnPress(false).
Title: Re: Button and drag behavior on mac vs iOS
Post by: Malzbier on July 24, 2012, 06:30:54 AM
My approach is : Press a button , create a drag-drop object under input (touch) then drag this onto something other, then release.

Im using  NGUI: Free Edition Version 2.0.7c.

I tested out that OnPress is only called with the parameter "true" , once if the press beginn's, and never with the parameter "false".
Title: Re: Button and drag behavior on mac vs iOS
Post by: ArenMook on July 24, 2012, 06:54:29 AM
Yeah 2.0.7 might have this issue. Full version is 2.1.2 and should be fine.
Title: Re: Button and drag behavior on mac vs iOS
Post by: Malzbier on July 24, 2012, 07:50:56 AM
I hope so that the last version fixed it ... i don't like to explain to my boss that we have spend 90€ at a system that does not work because its buggy.
Title: Re: Button and drag behavior on mac vs iOS
Post by: PhilipC on July 24, 2012, 09:25:55 AM
I'm surprised that you got the free version to work at all on iOS. I was so sure that the dll's that the free version requires would not be compatible (which might also be the issue)..
Title: Re: Button and drag behavior on mac vs iOS
Post by: Malzbier on July 24, 2012, 10:14:47 AM
Thats a good pint. I have to test it when i get the full version.
Title: Re: Button and drag behavior on mac vs iOS
Post by: ArenMook on July 24, 2012, 05:07:41 PM
Free version is only meant as a preview. You wouldn't be able to use it in a product anyway.
Title: Re: Button and drag behavior on mac vs iOS
Post by: Malzbier on July 25, 2012, 03:08:03 AM
Yea i know that i cant use it in a final product but i have to test if that what we have to achieve is possible with NGUI.
If i can proof that it is work like it should i get permission to buy NGUI.
Title: Re: Button and drag behavior on mac vs iOS
Post by: Malzbier on July 31, 2012, 07:41:06 AM
So now with the new and bought version.
On the button:
  1. public void OnPress (bool isPressed)
  2. {
  3.         Debug.Log(" is pressed = " + isPressed);
  4. }

Output:  is pressed = False

Same error as before...
Title: Re: Button and drag behavior on mac vs iOS
Post by: ArenMook on July 31, 2012, 08:02:27 AM
Set up a UICamera.genericEventHandler -- make it point to some dummy object and add a script there that listens to OnPress(). When you get the event, print UICamera.currentTouch.collider.name to see what intercepts your event.
Title: Re: Button and drag behavior on mac vs iOS
Post by: Malzbier on July 31, 2012, 09:59:15 AM
Id do not work the way i understand you:
  1.         void Start ()
  2.         {
  3.         UICamera.genericEventHandler.active = true;
  4.         }
  5.  
  6.  
  7.                 public void OnPress (bool isPressed)
  8.         {
  9.                 Debug.Log(UICamera.currentTouch.collider.name);
  10.         }


Quote
Assets/GUI/Scripts/GUILevelCreator.cs(80,49): error CS1061: Type `UICamera.MouseOrTouch' does not contain a definition for `collider' and no extension method `collider' of type `UICamera.MouseOrTouch' could be found (are you missing a using directive or an assembly reference?)
Title: Re: Button and drag behavior on mac vs iOS
Post by: ArenMook on July 31, 2012, 10:20:33 AM
Change
  1. UICamera.genericEventHandler.active = true;
to
  1. UICamera.genericEventHandler = gameObject;

This script can be attached anywhere, by the way. I suggest putting it on the same object as your UICamera.
Title: Re: Button and drag behavior on mac vs iOS
Post by: Malzbier on July 31, 2012, 10:56:12 AM
Thanks for the hint with the event system.

But i do not think that UICamera.currentTouch.collider.name works, because UICamera.currentTouch odes not have a .collider .
Maybe you mean UICamera.MouseOrTouch.pressed ? not sure because its not documented only by the fact that its there.
Title: Re: Button and drag behavior on mac vs iOS
Post by: ArenMook on July 31, 2012, 12:03:30 PM
You're right, I'm missing one thing. It should be:
  1. UICamera.currentTouch.pressed.collider
Title: Re: Button and drag behavior on mac vs iOS
Post by: Malzbier on August 07, 2012, 05:51:44 AM
Just tested around and found something interesting.

In my drag and drop script that is mainly a copy of yours i found the following line:

  1. if (UICamera.currentTouchID == -1)

On my mac currentTouchID == -1
On my IPad currentTouchID == 0

So that does not work on mobile.

is there any specific reason why currentTouchID should be -1 ?
I just overwrote the line with
  1.  if(true)
and its works now.

The only thing I am not sure if its a bug or misbehaving because of my fix, but the drag movement is very smoothed out / delayed. (cant tell if its writhe that way because i did never seen any drag movement on mobile before.)
Title: Re: Button and drag behavior on mac vs iOS
Post by: JRoch on August 07, 2012, 10:21:38 AM
http://www.tasharen.com/?page_id=160

Quote
Inside your event functions you can always figure out who sent the event (UICamera.currentCamera), RaycastHit that resulted in this event (UICamera.lastHit), as well as the on-screen position of the touch or mouse (UICamera.lastTouchPosition). You can also determine the ID of the touch event (UICamera.currentTouchID), which is ‘-1′ for the left mouse button, ‘-2′ for right, and ‘-3′ for middle.
Title: Re: Button and drag behavior on mac vs iOS
Post by: Malzbier on August 07, 2012, 10:59:03 AM
Ok thats a thanks for you JRoch.

Now is the only remaining question is the delayed / super smoothed behavior of the dragged object normal at touch input?
Title: Re: Button and drag behavior on mac vs iOS
Post by: ArenMook on August 07, 2012, 12:32:04 PM
Yeah it's normal.