Author Topic: UITweener gets disabled before running (bug)  (Read 7052 times)

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
UITweener gets disabled before running (bug)
« on: February 18, 2015, 08:12:20 AM »
OK I am going to describe the scenario that happens then my explanation as to why it's happening, and hopefully you can fix it.

I discovered this in on iOS but am able to repro it in the editor. (Latest version of NGUI as of time of writing)

* I have a gameObject with alpha tween on it.  It is currently not enabled. (The tween duration is short - 0.25s and is set to play once)
* With the game running I leave the editor (the application pauses)
* I return to the editor (application resumes) and within the first frame I invoke my tween (via an OnClick event)
* The tween does not occur (and any OnFinish delegates are omitted also)

Having debugged a bit I figure whats happening (see  ***comments***):

My code:
void OnClick() {
myTween.ResetToBegining();
myTween.PlayForward();
}

NGUI UITweener Code:
  1. void Update ()
  2.         {
  3. *****************************delta time is the time period which I the application was paused, say 10.0f sec****************************************************
  4.                 float delta = ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime;
  5.                 float time = ignoreTimeScale ? RealTime.time : Time.time;
  6.  
  7.                 if (!mStarted)
  8.                 {
  9.                         mStarted = true;
  10.                         mStartTime = time + delay;
  11.                 }
  12.                
  13.                 if (time < mStartTime) return;
  14.  
  15. *****************************calculated mFactor far too high, should be zero****************************************************
  16.                 // Advance the sampling factor
  17.                 mFactor += amountPerDelta * delta;
  18.  
  19.                 // Loop style simply resets the play factor after it exceeds 1.
  20.                 if (style == Style.Loop)
  21.                 {
  22.                         if (mFactor > 1f)
  23.                         {
  24.                                 mFactor -= Mathf.Floor(mFactor);
  25.                         }
  26.                 }
  27.                 else if (style == Style.PingPong)
  28.                 {
  29.                         // Ping-pong style reverses the direction
  30.                         if (mFactor > 1f)
  31.                         {
  32.                                 mFactor = 1f - (mFactor - Mathf.Floor(mFactor));
  33.                                 mAmountPerDelta = -mAmountPerDelta;
  34.                         }
  35.                         else if (mFactor < 0f)
  36.                         {
  37.                                 mFactor = -mFactor;
  38.                                 mFactor -= Mathf.Floor(mFactor);
  39.                                 mAmountPerDelta = -mAmountPerDelta;
  40.                         }
  41.                 }
  42.  
  43.                 // If the factor goes out of range and this is a one-time tweening operation, disable the script
  44. *****************************calculated mFactor too high, should be zero****************************************************
  45.                 if ((style == Style.Once) && (duration == 0f || mFactor > 1f || mFactor < 0f))
  46.                 {
  47.                         mFactor = Mathf.Clamp01(mFactor);
  48.                         Sample(mFactor, true);
  49.  
  50.                         // Disable this script unless the function calls above changed something
  51.                         if (duration == 0f || (mFactor == 1f && mAmountPerDelta > 0f || mFactor == 0f && mAmountPerDelta < 0f))
  52.                                 enabled = false;********************************* never had a chance to this tween in action *********************************
  53.  
  54. *********************************************** well atleast our OnFinish delegate is called not breaking any game logic *********************************
  55.                         if (current == null) ***************** oh wait, current is static and not null (we can't invoke other tweens from OnFinish?!)************************
  56.                         {
  57.                                 current = this;
  58.  
  59.                                 if (onFinished != null)
  60.                                 {
  61.                                         mTemp = onFinished;
  62.                                         onFinished = new List<EventDelegate>();
  63.                                        
  64.                                         // Notify the listener delegates
  65.                                         EventDelegate.Execute(mTemp);
  66.                                        
  67.                                         // Re-add the previous persistent delegates
  68.                                         for (int i = 0; i < mTemp.Count; ++i)
  69.                                         {
  70.                                                 EventDelegate ed = mTemp[i];
  71.                                                 if (ed != null && !ed.oneShot) EventDelegate.Add(onFinished, ed, ed.oneShot);
  72.                                         }
  73.                                         mTemp = null;
  74.                                 }
  75.  
  76.                                 // Deprecated legacy functionality support
  77.                                 if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
  78.                                         eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
  79.  
  80.                                 current = null;
  81.                         }
  82.                 }
  83.                 else Sample(mFactor, false);
  84.         }
  85.  
  86.  

Thanks
« Last Edit: February 24, 2015, 11:16:10 AM by beermoney »

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
Re: UITweener gets disabled before running (bug)
« Reply #1 on: February 23, 2015, 05:39:09 AM »
*bump*

I have a work around for this but I do think the issue should be resolved within NGUI

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITweener gets disabled before running (bug)
« Reply #2 on: February 24, 2015, 11:14:37 AM »
It's really hard to read code that hasn't been wrapped in a [code] block.

I believe this should already be resolved in the latest Pro version.

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
Re: UITweener gets disabled before running (bug)
« Reply #3 on: February 24, 2015, 11:18:06 AM »
I'll look out for the release version with a fix in it.

Thanks