SetNonUIHitDelegate Not Working?

SetNonUIHitDelegate Not Working?

Postby John B » Sun Feb 13, 2011 4:02 pm

Is this not working in 1.053? I've used it before and it worked, now in this project it does not. My method never gets called, either from mouse clicks in Unity or from touches on iPad. Not sure why as I copied code from a project that works (although with an older version of EZ GUI). Here's my code:

Code: Select all
function Start () {
   UIManager.instance.SetNonUIHitDelegate(ClickDispatch);
}

function ClickDispatch (ptr: POINTER_INFO) {
   Debug.Log("hit");   
}


Any ideas why this is no longer working?
John B
 
Posts: 249
Joined: Sat Jul 10, 2010 6:19 pm

Re: SetNonUIHitDelegate Not Working?

Postby Malveka » Sun Feb 13, 2011 4:37 pm

John,

You might try changing it to AddNonUIHitDelegate(). I believe the 'Set' version was more or less deprecated in 1.052.

Cheers,
Mal
Malveka
 
Posts: 152
Joined: Sun Jul 11, 2010 1:56 am

Re: SetNonUIHitDelegate Not Working?

Postby Malveka » Sun Feb 13, 2011 8:20 pm

Hmm... I believe John is right. I'm also seeing problems with my NonUIHit delegate handling. It doesn't seem to be getting called anymore. Changing the method from 'Set' to 'Add' doesn't make any difference.

I poked around in UIManager - DispatchHelper() and it looks to me like the code for invoking a NonUIHit delegate has been moved inside the Raycast test, whereas previously it was outside. It seems the implication of this is that our handlers will no longer be called on any input event that does not involve a UI control hit. Instead, they will only be called on an input event that hits something that is not a UI control. This means that an actual raycast hit must occur, which was not previously the case.

I tested this by placing a game object with a big box collider on my GUI layer, behind everything else in the scene. Sure enough, I'm now getting my NonUIHit calls again. Unfortunately, it seems to have broken my other controls, especially buttons, when running on the device.

Can anyone else confirm/deny issues with NonUIHit handling? I'm surprised there haven't been more complaints. Or did this behavior just change in 1.054? I'd like to see this go back to the previous behavior of always receiving the delegate calls when there's not a UI hit, unless there was a vital reason for it to change. As it stands, my app is completely broken. :(

Mal
Malveka
 
Posts: 152
Joined: Sun Jul 11, 2010 1:56 am

Re: SetNonUIHitDelegate Not Working?

Postby Brady » Sun Feb 13, 2011 9:27 pm

There are two issues involved here as I can tell:

1) If you have multiple calls in your code to SetNonUIHitDelegate(), then only the last call will work, since the "Set" version unsets any previous delegates, and changes it to only call the most recently set one. The "Add" version, instead, cumulatively adds delegates to be called. This has been the issue for a few people, and changing all their calls to Add instead of Set have solved their issues.

2) A few versions ago, non-UI hit delegates were "fixed" so that they were only called if non-UI objects were, in fact hit. This was the intended behavior from the beginning, but for a good while, EZ GUI was erroneously reporting non-UI hits even though nothing was actually hit. However, it seems now that many people may have made industrious use of this "bug". :) Perhaps I should have called it a "feature" instead? :) But one of the biggest problems with this aberrant behavior was that if you had more than one camera, you could get multiple notifications of the same non-UI event (I won't say "hit" since nothing was hit). This is because, among other things, any "miss" from one camera is just as valid a notification as a "miss" from another camera. So lacking any good reason to report one camera's miss over another's, you would just get repeated notifications of the same pointer event, but from the perspective of different cameras. Which is not very helpful.

But not to worry. There are a couple of other ways to go about it. If you only have a single camera and therefore aren't worried about multiple reports of the same input event, you can use AddMouseTouchPtrListener() instead, which will report every mouse and/or touchpad pointer in exactly the same manner as SetNonUIHitDelegate() used to, except that it will also include UI hit pointers as well. However, you can quickly skip over the pointers that hit UI objects, thanks to the newly-added feature in 1.054, and that is the new DidPointerHitUI() method, which lets you specify a pointer ID, and it returns whether that pointer hit a UI object in the current frame. So combining these two, you would get something like this:
Code: Select all
AddMouseTouchPtrListener(MyPointerListener);
...
void MyPointerListener(POINTER_INFO ptr)
{
   if(UIManager.instance.DidPointerHitUI(ptr.id))
      return;

   // Else, do our thing!
}


If you do have multiple cameras and are worried about repeat notifications, then you can still use the new DidPointerHitUI() method, and combine it with your own input polling. The ID sent to DidPointerHitUI() corresponds to the fingerID reported by Unity's touch API, and when using a mouse, the ID is 0. Or if using both mouse and touchpad, the mouse ID is 1 greater than total number of supported touches.

The reason I suggest your own device polling if you want ALL input, including total misses, while using multiple cameras is, as mentioned before, there's no real logical way for EZ GUI to pick which camera's pointer object to report, and which to not report when there is a total miss, since all of them are equally "misses".

If anyone has additional suggestions regarding this, I'm definitely open to considering other approaches. Thanks!
Brady
 
Posts: 5361
Joined: Tue Jul 06, 2010 11:33 pm

Re: SetNonUIHitDelegate Not Working?

Postby John B » Sun Feb 13, 2011 10:22 pm

Thanks. That explains why this worked in a previous app where I was looking for hits on particular object, while in this one I'm just looking for any touch.
John B
 
Posts: 249
Joined: Sat Jul 10, 2010 6:19 pm

Re: SetNonUIHitDelegate Not Working?

Postby John B » Sun Feb 13, 2011 10:35 pm

Spoke too soon. My listener method is now being called continuously, at least in Unity with the pointer type set to mouse. It doesn't matter if the mouse is up or down or even over the window. I haven't tried it on iPad, but as is I can't really test it. I'm using this to stop an ongoing process by touching anywhere on the screen, but now the process stops as soon as it starts.

Is there some way to just trap actual mouse clicks or touches?
John B
 
Posts: 249
Joined: Sat Jul 10, 2010 6:19 pm

Re: SetNonUIHitDelegate Not Working?

Postby Brady » Sun Feb 13, 2011 10:47 pm

Right, unlike touchpad touches which only exist if the screen is being touched, the mouse pointer is always there. However, you can test to see if it's "active" (being clicked) by checking the ptr.active flag. For touches, .active will always be true if the touch exists.
Brady
 
Posts: 5361
Joined: Tue Jul 06, 2010 11:33 pm

Re: SetNonUIHitDelegate Not Working?

Postby Malveka » Sun Feb 13, 2011 11:06 pm

OK, that explanation is very helpful. I've changed to using AddMouseTouchPtrListener and then checking DidPointerHitUI. That seems to work. My non-GUI touch handling is working fine. But I'm still plagued by this completely borked button behavior that occurs only on the device. Previously I was convinced this was related to the NonUIHit handling, but now I'm unsure.

When I press a button on when running on the device, the button freezes in its Active state (the Active state sprite is displayed), and the change value delegate for it is not fired. Once stuck in the active state, it cannot be reset without restarting the app. In the Xcode console I'm seeing lots of these:

InvalidCastException: Cannot cast from source type to destination type.
at UIManager.set_FocusObject (IUIObject value) [0x00000] in <filename unknown>:0
at UIManager.DispatchHelper (.POINTER_INFO& curPtr, Int32 camIndex) [0x00000] in <filename unknown>:0
at UIManager.DispatchInput () [0x00000] in <filename unknown>:0
at UIManager.Update () [0x00000] in <filename unknown>:0

Any ideas what could be causing this?

Mal
Malveka
 
Posts: 152
Joined: Sun Jul 11, 2010 1:56 am

Re: SetNonUIHitDelegate Not Working?

Postby Malveka » Sun Feb 13, 2011 11:19 pm

OK, that explanation is very helpful. I've changed to using AddMouseTouchPtrListener and then checking DidPointerHitUI. That seems to work. My non-GUI touch handling is working fine.

Ignore all of the following. That was my bad. I had a faulty debug print statement causing those exceptions. Now it's working :oops:

But I'm still plagued by this completely borked button behavior that occurs only on the device. Previously I was convinced this was related to the NonUIHit handling, but now I'm unsure.

When I press a button on when running on the device, the button freezes in its Active state (the Active state sprite is displayed), and the change value delegate for it is not fired. Once stuck in the active state, it cannot be reset without restarting the app. In the Xcode console I'm seeing lots of these:

InvalidCastException: Cannot cast from source type to destination type.
at UIManager.set_FocusObject (IUIObject value) [0x00000] in <filename unknown>:0
at UIManager.DispatchHelper (.POINTER_INFO& curPtr, Int32 camIndex) [0x00000] in <filename unknown>:0
at UIManager.DispatchInput () [0x00000] in <filename unknown>:0
at UIManager.Update () [0x00000] in <filename unknown>:0

Any ideas what could be causing this?


Mal
Malveka
 
Posts: 152
Joined: Sun Jul 11, 2010 1:56 am

Re: SetNonUIHitDelegate Not Working?

Postby trojanlw » Mon Feb 21, 2011 4:40 pm

I am running 1.055. However is can't find this new function "DidPointerHitUI".

error CS1061: Type `UIManager' does not contain a definition for `DidPointerHitUI' and no extension method `DidPointerHitUI' of type `UIManager' could be found (are you missing a using directive or an assembly reference?)

However UIManager.instance.AddMouseTouchPtrListener(CursorControl); works fine.

What am I missing ?

Thanks
trojanlw
 
Posts: 4
Joined: Mon Feb 21, 2011 1:13 pm

Next

Return to EZ GUI General

Who is online

Users browsing this forum: No registered users and 3 guests

cron