Author Topic: Suggested change to UIPlayAnimation  (Read 3726 times)

ShinyMark

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Suggested change to UIPlayAnimation
« on: December 31, 2013, 02:54:38 PM »
Hi there,

Currently if you setup a UIPlayAnimation component on a UIButton to trigger on OnPress, it will play its animation in reverse twice if you follow this sequence of events:

1. Click/Touch the button and hold down your mouse/finger.
2. Drag off the button - OnDragOut() is called and UIPlayAnimation plays the animation in reverse (good so far)
3. Release your click/touch - OnPress(false) is called and UIPlayAnimation plays the animation in reverse again

#3 is the problem - I don't think the animation should be played again here. It looks odd.

I've fixed this locally by simply adding a bool that tracks if OnDragOut() occurred after OnPress(true). If that bool is true, OnPress(false) does not play the animation in reverse again.

Is this something that should be integrated into NGUI directly? I can't think of a use-case for the current behavior.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Suggested change to UIPlayAnimation
« Reply #1 on: December 31, 2013, 03:37:58 PM »
OnPress and OnDragOver/Out are different notifications, so I'm not sure if I follow you here... UIPlayAnimation doesn't track OnDrag at all. Just OnPress, which only occurs when you press, and then again when you release. It does not get called when you drag out of the area. OnDragOut is called instead. Are you sure you have the latest version of NGUI?

ShinyMark

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Suggested change to UIPlayAnimation
« Reply #2 on: January 02, 2014, 01:27:11 PM »
I made a screen recording video with narration showing the behavior that I think should be changed. Hopefully this will explain it clearly.

https://dl.dropboxusercontent.com/u/2003612/UIPlayAnimationSuggestion.mov

~7.6mb

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Suggested change to UIPlayAnimation
« Reply #3 on: January 03, 2014, 04:39:16 AM »
Got it, thanks! I've fixed it so you will see it in f4.

ShinyMark

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Suggested change to UIPlayAnimation
« Reply #4 on: January 03, 2014, 01:10:03 PM »
Thanks, works great.

ShinyMark

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Suggested change to UIPlayAnimation
« Reply #5 on: January 03, 2014, 04:48:56 PM »
I found a small bug in the update with more than one button using UIPlayAnimation in the same panel.

1. Click and hold down the left mouse over button #1 - animation played forward (good)
2. Drag off of button #1 - animation played backward (good)
3. Drag on top of a different button, button #2 - animation played forward on button #2 (debatable if this is good or not... in my opinion this should not occur)
4. Let go of the mouse button while hovering over button #2 - button #2 is stuck in the fully "forward" position, the animation doesn't play backwards on button #2 on OnPress(false)

I'm going to PM you my version of the file, a simple modification from 3.0.8f3, which doesn't have this behavior and will hopefully be useful reference. My modification may not cover all UIPlayAnimation trigger conditions but it does give me the behavior I'm looking for when using OnPress.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Suggested change to UIPlayAnimation
« Reply #6 on: January 04, 2014, 09:19:09 AM »
I've again made the necessary changes and you will see them in f5. :)

In the meantime you can add this:
  1.         void OnDrop (GameObject go)
  2.         {
  3.                 if (enabled && trigger == Trigger.OnPress && UICamera.currentTouch.dragged != gameObject)
  4.                         Play(false, true);
  5.         }