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:
void Update ()
{
*****************************delta time
is the time period which I the application was paused, say 10
.0f sec
**************************************************** float delta = ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime;
float time = ignoreTimeScale ? RealTime.time : Time.time;
if (!mStarted)
{
mStarted = true;
mStartTime = time + delay;
}
if (time < mStartTime) return;
*****************************calculated mFactor far too high, should be zero****************************************************
// Advance the sampling factor
mFactor += amountPerDelta * delta;
// Loop style simply resets the play factor after it exceeds 1.
if (style == Style.Loop)
{
if (mFactor > 1f)
{
mFactor -= Mathf.Floor(mFactor);
}
}
else if (style == Style.PingPong)
{
// Ping-pong style reverses the direction
if (mFactor > 1f)
{
mFactor = 1f - (mFactor - Mathf.Floor(mFactor));
mAmountPerDelta = -mAmountPerDelta;
}
else if (mFactor < 0f)
{
mFactor = -mFactor;
mFactor -= Mathf.Floor(mFactor);
mAmountPerDelta = -mAmountPerDelta;
}
}
// If the factor goes out of range and this is a one-time tweening operation, disable the script
*****************************calculated mFactor too high, should be zero****************************************************
if ((style == Style.Once) && (duration == 0f || mFactor > 1f || mFactor < 0f))
{
mFactor = Mathf.Clamp01(mFactor);
Sample(mFactor, true);
// Disable this script unless the function calls above changed something
if (duration == 0f || (mFactor == 1f && mAmountPerDelta > 0f || mFactor == 0f && mAmountPerDelta < 0f))
enabled = false;********************************* never had a chance to this tween in action *********************************
*********************************************** well atleast our OnFinish
delegate is called not breaking any game logic
********************************* if (current
== null) ***************** oh wait, current
is static and not
null (we can
't invoke other tweens from OnFinish?!)************************ {
current = this;
if (onFinished != null)
{
mTemp = onFinished;
onFinished = new List<EventDelegate>();
// Notify the listener delegates
EventDelegate.Execute(mTemp);
// Re-add the previous persistent delegates
for (int i = 0; i < mTemp.Count; ++i)
{
EventDelegate ed = mTemp[i];
if (ed != null && !ed.oneShot) EventDelegate.Add(onFinished, ed, ed.oneShot);
}
mTemp = null;
}
// Deprecated legacy functionality support
if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
current = null;
}
}
else Sample(mFactor, false);
}
Thanks