I think I found a bug in NGUI (paid) version 2.3.3f.
I have two gameobjects called Panel1 and Panel2, with the following attached:
* Panel1
* UIPanel
* TweenPosition: TweenGroup=0 (forward = moves panel off screen to the left).
* Button (name="next")
* UIButtonTween: Target=Panel1, TweenGroup=0, direction=forward, disableWhenFinished=DisableAfterForward
* UIButtonTween: Target=Panel2, TweenGroup=0, direction=forward, disableWhenFinished=DoNotDisable
* Panel2
* UIPanel
* TweenPosition: TweenGroup=0 (forward = moves panel onto screen from the right).
* TweenPosition: TweenGroup=1 (forward = moves panel off screen to the left).
* Button (name="back")
* UIButtonTween: Target=Panel1, TweenGroup=0, direction=reverse, disableWhenFinished=DoNotDisable
* UIButtonTween: Target=Panel2, TweenGroup=0, direction=reverse, disableWhenFinished=DisableAfterReverse
* Button (name="done")
* UIButtonTween: Target=Panel2, TweenGroup=1, direction=forward, disableWhenFinished=DisableAfterForward
The problem here is when I click the "back"-button. According to my setup, Panel2 should be disabled after the tweening is done (TweenGroup 0 on Panel2).
But this does not happen. I looked at the code, and I think it is because UIButtonTweener.Update() checks ALL the UITweener-objects of the target (which in
this case is Panel2), and sets properDirection=false since the UITweener of TweenGroup=1 is forward.
I fixed it by adding a check for tween group in UIButtonTween.Update(), i.e. changing it from
void Update ()
{
if (disableWhenFinished != DisableCondition.DoNotDisable && mTweens != null)
{
bool isFinished = true;
bool properDirection = true;
for (int i = 0, imax = mTweens.Length; i < imax; ++i)
{
UITweener tw = mTweens[i];
if (tw.enabled)
{
isFinished = false;
break;
}
else if ((int)tw.direction != (int)disableWhenFinished)
{
properDirection = false;
}
}
if (isFinished)
{
if (properDirection) NGUITools.SetActive(tweenTarget, false);
mTweens = null;
}
}
}
to
void Update ()
{
if (disableWhenFinished != DisableCondition.DoNotDisable && mTweens != null)
{
bool isFinished = true;
bool properDirection = true;
for (int i = 0, imax = mTweens.Length; i < imax; ++i)
{
UITweener tw = mTweens[i];
if (tw.tweenGroup == tweenGroup) // CHECK FOR TWEENGROUP!
{
if (tw.enabled)
{
isFinished = false;
break;
}
else if ((int)tw.direction != (int)disableWhenFinished)
{
properDirection = false;
}
}
}
if (isFinished)
{
if (properDirection) NGUITools.SetActive(tweenTarget, false);
mTweens = null;
}
}
}
Am I right, or am I using the NGUI system incorrectly?