Where is all the SetX() functionality when using DoTween.TOX?
« on: September 22, 2015, 04:20:39 AM »
I'm trying to animate Time.timescale using an easing function.

Tweening the value itself seems to work:

Code: [Select]
DG.Tweening.DOTween.To(value => Time.timeScale = value, 1, 0, 0.4f);
But all the SetX() methods mentioned in the documentation are not available on the object this returns and while I found out that I could set the `timeScale` property, there doesn't seem to be any way to use an easing function for this tween.

What am I missing?

(cross posted from http://stackoverflow.com/questions/32707355/how-do-you-animate-unity-time-timescale-using-an-easing-function-with-dotween, since SO doesn't seem to have a lot of DOTween questions).

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Where is all the SetX() functionality when using DoTween.TOX?
« Reply #1 on: September 22, 2015, 10:51:44 AM »
Hi,

The object returned is a Tween, and you can use all the Set(X) method on it. Are you storing the returned reference the right way? For example, this totally works:
Code: [Select]
// Animated the timeScale to 2 in 0.4 seconds
Tween t = DOTween.To(()=> Time.timeScale, x=> Time.timeScale = x, 2, 0.4f);
t.SetEase(Ease.InQuad);
// Set the tween as independent from the timeScale (since you're animating that)
t.SetUpdate(true);
and this too, with direct chaining without a direct reference:
Code: [Select]
DOTween.To(()=> Time.timeScale, x=> Time.timeScale = x, 2, 0.4f).SetEase(Ease.InQuad).SetUpdate(true);
P.S. no need to write the full "DG.Tweening.DOTween.To". You can just write DOTween.To as in my example if you add a using directive on the top of your class:
Code: [Select]
using DG.Tweening;
Cheers,
Daniele

EDIT: I also modified the content of your tween to use the generic way correctly
« Last Edit: September 22, 2015, 10:55:33 AM by Daniele »

Re: Where is all the SetX() functionality when using DoTween.TOX?
« Reply #2 on: September 22, 2015, 11:41:53 PM »
First, thanks for the reply and the correction of the tween itself.

I figured out what the problem was. I preferred to not include
Code: [Select]
using DG.Tweening; and unfortunately it seems that all the SetX() methods are implemented as extension methods. Therefore, if the namespace is not included, these methods are simply not available.

It's an odd choice to implement core functionality as extension methods, rather than directly on the Tweening object. Any particular reason for this?

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Where is all the SetX() functionality when using DoTween.TOX?
« Reply #3 on: September 23, 2015, 07:54:32 PM »
I used extension methods both to keep actual classes lighter, and to allow safer operations in some cases (for example, calling myTween.Kill() will not throw an error even if myTween is not instantiated - and thus already killed, in a way).