Hello, I'm using Tween combinations to create animation effects (Like when you click on the popup list) - I want a good way to execute a method after the animation finishes.
I currently I'm doing something like this: (this is a snippet from my custom context menu, which is basically a popup list that appears on the mouse position)
// show on mouse, and seek to animate
if (show && hasFinshedAnimating) {
_transform.position = camera.ScreenToWorldPoint(Input.mousePosition);
if (isAnimated) {
hasFinshedAnimating = false;
for (int i = 0, len = entries.Count; i < len; ++i) {
Animate(entries[i]);
}
UIWidget.Animate(background, animSpeed);
StartCoroutine(WaitForAnim());
}
}
IEnumerator WaitForAnim()
{
yield return new WaitForSeconds
(animSpeed
+ .15f
); hasFinshedAnimating = true;
if (Random.Range(0, 10) > 6)
ResetEntriesDims();
}
void Animate(Entry entry)
{
UIWidget.Animate(entry.background, animSpeed);
UIWidget.Animate(entry.label, animSpeed);
}
public static void Animate(UIWidget widget, float animSpeed)
{
AnimateColor(widget, animSpeed);
AnimatePosition(widget, animSpeed);
AnimateScale(widget, animSpeed);
}
(Notice I'm actually calling Animate methods, but they internally operate on Tween)
It works fine, serves the purpose. But I wonder if there's something built-in for that, something I'm missing perhaps, anything?
In general, can this be done in a better more elegant way?
Thanks!