Author Topic: UITrigger checkbox instant dis-/appear  (Read 2004 times)

Martin Schultz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
    • Decane
UITrigger checkbox instant dis-/appear
« on: March 29, 2014, 06:30:58 AM »
I've used the nicely animated checkbox from the NGUI examples. Now I'm fading to the options menu and while options menu fades in from a black curtain that covers the whole scene, I'm settings the checkbox value based on prefs. All good, but now the checkhook animates where I only want to set or not set it. I fail to see how I can disable the animation just for the specific moment when I enable the options menu and fade it in.

Any help greatly appreciated. Thanks!
Martin

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITrigger checkbox instant dis-/appear
« Reply #1 on: March 29, 2014, 06:40:25 AM »
Modify UIToggle, line 230 (at the very end):
  1.                         if (activeAnimation != null)
  2.                         {
  3.                                 ActiveAnimation aa = ActiveAnimation.Play(activeAnimation, state ? Direction.Forward : Direction.Reverse);
  4.                                 if (instantTween) aa.Finish();
  5.                         }
You will also need to add the Finish() function to the ActiveAnimation script:
  1.         /// <summary>
  2.         /// Immediately finish playing the animation.
  3.         /// </summary>
  4.  
  5.         public void Finish ()
  6.         {
  7.                 if (mAnim != null)
  8.                 {
  9.                         foreach (AnimationState state in mAnim)
  10.                         {
  11.                                 if (mLastDirection == Direction.Forward) state.time = state.length;
  12.                                 else if (mLastDirection == Direction.Reverse) state.time = 0f;
  13.                         }
  14.                 }
  15. #if USE_MECANIM
  16.                 else if (mAnimator != null)
  17.                 {
  18.                         mAnimator.Play(mClip, 0, (mLastDirection == Direction.Forward) ? 1f : 0f);
  19.                 }
  20. #endif
  21.         }
Lastly, you will need to modify UITrigger.Start function to the following:
  1.         void Start ()
  2.         {
  3.                 if (startsChecked)
  4.                 {
  5.                         startsChecked = false;
  6.                         startsActive = true;
  7. #if UNITY_EDITOR
  8.                         NGUITools.SetDirty(this);
  9. #endif
  10.                 }
  11.  
  12.                 // Auto-upgrade
  13.                 if (!Application.isPlaying)
  14.                 {
  15.                         if (checkSprite != null && activeSprite == null)
  16.                         {
  17.                                 activeSprite = checkSprite;
  18.                                 checkSprite = null;
  19.                         }
  20.  
  21.                         if (checkAnimation != null && activeAnimation == null)
  22.                         {
  23.                                 activeAnimation = checkAnimation;
  24.                                 checkAnimation = null;
  25.                         }
  26.  
  27.                         if (Application.isPlaying && activeSprite != null)
  28.                                 activeSprite.alpha = startsActive ? 1f : 0f;
  29.  
  30.                         if (EventDelegate.IsValid(onChange))
  31.                         {
  32.                                 eventReceiver = null;
  33.                                 functionName = null;
  34.                         }
  35.                 }
  36.                 else
  37.                 {
  38.                         mIsActive = !startsActive;
  39.                         mStarted = true;
  40.                         bool instant = instantTween;
  41.                         instantTween = true;
  42.                         Set(startsActive);
  43.                         instantTween = instant;
  44.                 }
  45.         }
I'll have all of these in 3.5.6 in any case.

Martin Schultz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
    • Decane
Re: UITrigger checkbox instant dis-/appear
« Reply #2 on: March 29, 2014, 02:50:14 PM »
Thanks, worked great! :-)