Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: kjenkins_oculus on October 07, 2013, 02:00:49 PM

Title: UIButtonTween resetOnPlay fails every other time
Post by: kjenkins_oculus on October 07, 2013, 02:00:49 PM
In UIButtonTween, if I set resetOnPlay to true, it will fail every other time it runs, starting the 2nd time

This happens between of this code:

// Toggle or activate the tween component
if (playDirection == Direction.Toggle) tw.Toggle();
else tw.Play(forward);
if (resetOnPlay) tw.Reset();

tw.Play(forward) will call Play(), with mFactor already set to 1.0 due to the prior execution

public void Play (bool forward)
{
   mAmountPerDelta = Mathf.Abs(amountPerDelta);
   if (!forward) mAmountPerDelta = -mAmountPerDelta;
   enabled = true;
   Update();
}

With Style.Once, Update() will then run this code:

// Disable this script unless the function calls above changed something
if (mFactor == 1f && mAmountPerDelta > 0f || mFactor == 0f && mAmountPerDelta < 0f)
{
enabled = false;
}

Lastly, Reset() will reset mFactor, but too late.


public void Reset ()
{
   mStarted = false;
   mFactor = (mAmountPerDelta < 0f) ? 1f : 0f;
   Sample(mFactor, false);
}

I believe the correct fix is in UIButtonTween.cs, it should call tw.Reset() first, then tw.Play() second.
Title: Re: UIButtonTween resetOnPlay fails every other time
Post by: ArenMook on October 08, 2013, 01:42:13 AM
There is no UIButtonTween anymore, and I am pretty sure this was already fixed a while back. You need to update your NGUI.