Author Topic: UISprite not updated until press released  (Read 6050 times)

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
UISprite not updated until press released
« on: November 21, 2013, 10:14:47 AM »
Hello,

I have a problem with a UIImageButton in a UIDraggablePanel.
When the finger goes out of the draggable panel, I cancel the drag and spawn like a copy of the selected object to be dragged with the finger; it works pretty fine overall, except one thing: the item that was dragged inside the draggable panel (which has a draggablePanelContent component and a UIImageButton one) will not turn back to its "normal" sprite when I think it should.
Here is the code I use to stop the panel from being dragged:

  1. Debug.Log("Stop scroll input!");
  2.         //The currentSelectedItem is the object with the finger on, with two UIButtonMessage, one UIImageButton and one UIDragPanelContent
  3.         currentSelectedItem.gameObject.SendMessage("OnPress", false);
  4.  
  5.         UICamera.currentTouch.pressed = null;
  6.         UICamera.currentTouch.dragged = null;
  7.         //Tried to add the refresh to solve my problem, without success
  8.         draggablePanel.panel.Refresh();

So here is what happens:
- I press this button => UIImageButton component receives the event and turn the sprite to the pressed state
- I drag it around a bit
- I take it out of the draggable panel (triggering the above code) => UIImageButton component receives the OnPress event with "false" and assigns the normal spriteName to its target (it is correctly assigned); however, in the game view (and on device), the sprite stays "pressed"
- I drag my copy around, the draggable panel does not follow anymore, but the button sprite remains pressed
- In editor, if I release the button anywhere, the sprite finally updates to its normal state, except if I release over the button itself (the hover sprite is the same as normal); in this particular case, the sprite remains "pressed" until I take the mouse out of the collider (wtf??).
- On device, when my finger releases the touch, the sprite simply remains "pressed" until I tap on it again.

Any idea about how to force the update of the button sprite after its value has been changed by UIImageButton component?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISprite not updated until press released
« Reply #1 on: November 21, 2013, 02:05:47 PM »
Sounds unusual. Do you disable the collider while dragging the object like I do in the Drag & Drop example?

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: UISprite not updated until press released
« Reply #2 on: November 22, 2013, 04:00:00 AM »
Hey,

Sorry, I did not express myself very well...
In fact, it is not a copy that I drag around (I don't even know why I used this word in my message...), it is another object without collider (and without the other NGUI components), on another standard panel specifically in place for that, using the unity's Input. The object on which the drag started (inside the draggable panel, with all the ngui components) stays in the draggable panel, and I don't disable its collider.The draggable panel and this object stop receiving ngui drag events once I switch to the other item, then I just use the Input to set this other item position.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UISprite not updated until press released
« Reply #3 on: November 22, 2013, 06:24:24 AM »
Just because you tell the widget OnPress(false) doesn't mean that the UICamera actually lets it go. It will still send OnDrag messages and whatever else to that widget.

I think there's a function on UICamera that can force it to release the currently pressed object.

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: UISprite not updated until press released
« Reply #4 on: November 22, 2013, 06:52:11 AM »
Yes, I use this code for that:

  1.     UICamera.currentTouch.pressed = null;
  2.     UICamera.currentTouch.dragged = null;

What is more, my scroll menu (and therefore my dragged item) correctly stop receiving the events. I'll try to see if I find another more explicit function on the camera, but the code above (which I found on internet, maybe even in this forum ^^) seemed to be enough to stop the touch for the widgets.

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: UISprite not updated until press released
« Reply #5 on: November 22, 2013, 06:53:29 AM »
(And my UIImageButton correctly set the image to the "up" state at the right time, without setting it back to the "pressed" state after, but it does not affect the visual on screen, even if the "spriteName" field of the UIImageButton's target is correct.)

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: UISprite not updated until press released
« Reply #6 on: November 22, 2013, 08:25:08 AM »
Wow wow wow... nevermind, it was completely, stupidly my fault v_v I did not sent the event to the correct item..... Sorry for the time loss, thanks for trying to help anyway!