Author Topic: UIButtonTween resetOnPlay fails every other time  (Read 1617 times)

kjenkins_oculus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
UIButtonTween resetOnPlay fails every other time
« 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonTween resetOnPlay fails every other time
« Reply #1 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.