*

par

  • ***
  • 9
    • View Profile
Retrieving tween object from callback function
« on: December 15, 2015, 06:21:51 PM »
How would I access the actual tween that is responsible for the callback?

Code: [Select]
     public void someMethod(Transform transform) {
          transform.DOScale(Vector3.zero, 1).OnComplete(doSomethingAfterTween);
     }

     public void doSomethingAfterTween() {
          Tween theTween = ????
     }

Thanks!

PAR

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Retrieving tween object from callback function
« Reply #1 on: December 15, 2015, 06:25:31 PM »
Hi Par!

You can't. But you could always store it as a reference and pass it to the callback as a lambda:

Code: [Select]
public void someMethod(Transform transform) {
   Tween t = transform.DOScale(Vector3.zero, 1);
   t.OnComplete(()=> doSomethingAfterTween(t));
}
public void doSomethingAfterTween(Tween t) {
   Tween theTween = t;
}

*

par

  • ***
  • 9
    • View Profile
Re: Retrieving tween object from callback function
« Reply #2 on: December 15, 2015, 06:27:51 PM »
Awesome, I actually like this more than a lot of other patterns used for this type of thing.  Passing in the reference is way cleaner than searching in some monolithic static class.

Thanks!

PAR