Author Topic: UIDraggblePanel: event when it comes to a halt  (Read 1866 times)

Oinobareion

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
UIDraggblePanel: event when it comes to a halt
« on: November 19, 2013, 07:41:34 AM »
Hey guys,

I use the "OnDragFinished" Event Listener to detect when I have finished dragging a UIDraggblePanel. This works fine but what I actually want to know is when the UIPanel comes to a halt after being dragged and the momentum being applied. So how can I figure out, when the UIPanel stops after being dragged?

Thanks for your help!

drZigfri

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: UIDraggblePanel: event when it comes to a halt
« Reply #1 on: November 19, 2013, 08:08:51 AM »
I suppose one way would be to check previous and current game object position in the Update/FixedUpdate function.

Oinobareion

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UIDraggblePanel: event when it comes to a halt
« Reply #2 on: November 19, 2013, 09:04:41 AM »
Yes, that's how it works. Thanks for help. I did it like this:

  1.         void OnDragFinished()
  2.         {      
  3.                 isMoving = true;
  4.                 StartCoroutine(CheckIfPanelStandsStill());
  5.         }
  6.        
  7.         private IEnumerator CheckIfPanelStandsStill ()
  8.         {
  9.                 while (isMoving)
  10.                 {
  11.                         // the current drag momentum
  12.                         float currentDragMomentum = panel.clipRange.y;
  13.                
  14.                         // wait some time
  15.                         yield return new WaitForSeconds(0.1f);
  16.                        
  17.                         // the drag momentum after some time
  18.                         float dragMomentumAfterSomeTime = panel.clipRange.y;
  19.                        
  20.                         // this means that our panel stands still
  21.                         if (currentDragMomentum == dragMomentumAfterSomeTime)
  22.                         {
  23.                                 CheckListElements();
  24.                                 isMoving = false;
  25.                         }
  26.                 }
  27.         }
  28.  
  29.