Hi,I have a problem with UIPlayTween onFinished event here.
When I do play tween group 1 with UIPlayTween, and assign a method eventdelegate to it's onFinished, it works fine.
In the method I detach the method itself, and reset the played tweens group to zero.
But when I continues to set some other tweens group to 1, assign another onFinished method, and then play these tweens in this method, it goes strange. The new onFinished eventdelegate will be called immediately after UIPlayTween.play method is called, and makes the logic sequence confused.
I run the code and always, when I do play the tween from the start, the first always goes right, the immediate second play always goes unexpected.
I set a break in my method, and view the stack trace, it seemed the new onFinished method calling stack is normal, it's called from UIPlayTween onFinished method, and UITweener.Update method,but when I put debug codes in these functions, they didn't work inside the calling play method and onFinish delegate method.
After I did more debug, I find the new on Finish delegate method (named onreelimate) is called immediately after UIPlayTween.play method runned, and I can't find where is the caller. And if I remove the code in onreelimate which is to remove itself's eventdelegate, this method will be called again when the second tweens play end.
So here is the secord tween play code, beginRollback is called in the first tween onFinished delegate method.
void beginRollback()
{
......
UIPlayTween pt
= (UIPlayTween
)gameObject
.GetComponent(typeof(UIPlayTween
)); EventDelegate eventDelegate
= new EventDelegate
(this,
"onreelimate"); teventDelegate = eventDelegate;
eventDelegate
.parameters[0] = new EventDelegate
.Parameter(this,
"teventDelegate"); EventDelegate.Add (pt.onFinished, eventDelegate);
Debug.Log ("playing reelimate at :" + System.DateTime.Now.ToLongTimeString ());
pt.Play (true);
}
void onreelimate(EventDelegate edelegate)
{
Debug.Log ("finish reelimate at :" + System.DateTime.Now.ToLongTimeString ());
UIPlayTween pt
= (UIPlayTween
)gameObject
.GetComponent(typeof(UIPlayTween
)); EventDelegate.Remove (pt.onFinished, edelegate);
}
and in the UIPlayTween, I add some debug codes in the play and onFinished method
public void Play (bool forward)
{
Debug.Log ("start playing");
mActive = 0;
GameObject go = (tweenTarget == null) ? gameObject : tweenTarget;
......
tw.Play(forward);
}
}
}
}
Debug.Log ("end playing");
}
void OnFinished ()
{
if (--mActive == 0 && current == null)
{
Debug.Log ("on finish called at " + System.DateTime.Now.ToString ());
current = this;
EventDelegate.Execute(onFinished);
// Legacy functionality
if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
eventReceiver.SendMessage(callWhenFinished, SendMessageOptions.DontRequireReceiver);
eventReceiver = null;
current = null;
}
}
and log result in the attach.
The tween duration is set to 2 seconds, and the onreelimate method debug time is same as the caller beginRollback debug time.
And if code
EventDelegate.Remove (pt.onFinished, edelegate);
is removed, there will be another calling debug output 2 seconds later.