tothegons / dotween

Automatically exported from code.google.com/p/dotween
0 stars 0 forks source link

.Then() and .And() extension methods #10

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This is a wish list sort of thing, but it would be really awesome if we there 
were .And and .Then methods on Tweeners.

.And on a Tweener would take and return create another Tweener after setting 
the Delay to the current Tweener's delay.

.Then on a Tweener would take and return another Tweener with the Delay set to 
the current Tweener's delay + its duration.

These could also be implemented more efficiently via Sequences, but sequences 
are a bit more verbose to build, and usually, I prefer the conciseness over the 
speed.

I can't quite implement these using extension methods currently, because 
there's no method to get the delay from a Tweener.

Thanks!

Original issue reported on code.google.com by thematth...@gmail.com on 7 Sep 2014 at 7:59

GoogleCodeExporter commented 8 years ago
These are very interesting extensions, thanks to you for the suggestion, I'm 
totally gonna do that (and I'll also add a Delay method that returns the delay 
duration, just in case). Should be ready tomorrow or Tuesday.

Original comment by daniele....@gmail.com on 7 Sep 2014 at 8:51

GoogleCodeExporter commented 8 years ago
I started implementing this and got derailed by API complications. The thing 
is, the And/Then should still contain a new tween creation chain, so I'm not 
sure how this:

myTransform.DOMoveX(45, 1).SetDelay(2).Then(myTransform.DOMoveY(4, 1));

would be much less verbose than this:

DOTween.Sequence().Insert(2, myTransform.DOMoveX(45, 
1)).Append(myTransform.DOMoveY(4, 1))

It is less verbose, but slightly so. What you think? Maybe I'm missing some API 
part that you had in mind?

Original comment by daniele....@gmail.com on 8 Sep 2014 at 10:00

GoogleCodeExporter commented 8 years ago
I like myTransform.DOMoveX(45, 1).SetDelay(2).Then(myTransform.DOMoveY(4, 1)) a 
little better, but your right, it's not a massive improvement.  The greater 
improvement is on And's, then Then's provide some symmetry.  I end up doing a 
lot of parallel rather than sequenced operations.

The use case is, I have a bouncing ball animation.  For each bounce, I'd do the 
X axis as linear easing, but the Y axis as OutSine + InSine.  Then create a 
series of bounces, so I have to manually track the delays + durations to sync 
everything.

It might not be as general a problem as I may have thought though.

Original comment by thematth...@gmail.com on 8 Sep 2014 at 12:37

GoogleCodeExporter commented 8 years ago
Let's consider it a little more then :) An And() like this:

myTransform.DOMoveX(45, 1).SetDelay(2).And(myTransform.DOMoveY(4, 1));

would instead become like this with a Sequence:

DOTween.Sequence().Insert(2, myTransform.DOMoveX(45, 1)).Insert(2, 
myTransform.DOMoveY(4, 1));

Still not much of an improvement.

The thing that bugs me more, is that introducing Then() and And() would need a 
fair improvement, because it also introduces some possible misconceptions. For 
example, if you do this:

Tween myTween = myTransform.DOMoveX(45, 
1).SetDelay(2).And(myTransform.DOMoveY(4, 1));
myTween.Goto(0.5f);

you're actually sending the second tween to 0.5, and not the first. That's 
because you would obviously store the last thing in the chain, which is the 
second tween.

Using a Sequence instead and then Goto, you would send both tweens to 0.5, 
which seems less "mistake prone" and more intuitive.

Again, let me know your thoughts.

Original comment by daniele....@gmail.com on 8 Sep 2014 at 7:07

GoogleCodeExporter commented 8 years ago

Original comment by daniele....@gmail.com on 8 Sep 2014 at 7:07

GoogleCodeExporter commented 8 years ago
P.S. thinking about it more, maybe a cooler thing would be if I found a way to 
tween more than one thing at the same time, like this (following your example 
use case):

myTransform.MoveX(45, 1).MoveY(5, 1).SetDelay(2);

Which could create and return a Sequence in the background.

Original comment by daniele....@gmail.com on 8 Sep 2014 at 7:10

GoogleCodeExporter commented 8 years ago
Yeah, that looks ideal, but then it gets a little hairy once you throw things 
like loops, or easing into it.  I think you're right about the possible 
misconceptions outweighing the benefits.   Maybe the helpers aren't such a good 
idea.  

If Sequences supported parallel operations, you could do something like have 
.And and .Then operate on both Tweeners and Sequences, but both returning 
Sequences.  Something like:

Sequence mySequence = myTransform.DOMoveX(45, 1).SetDelay(2)
                                         .Then(myTransform.DOMoveY(4, 1).SetEase(Ease.SineOut))
                                         .And(myTransform.DOMoveZ(10,1)); 

Original comment by thematth...@gmail.com on 10 Sep 2014 at 1:05

GoogleCodeExporter commented 8 years ago
I like some parts of the idea of having And and Then roll Sequences instead 
than tweens, but other parts leave me worried about additional confusion.

In your example, what would the And do? Insert the tween as a parallel to the 
immediately preceding one, or insert it at the beginning of the Sequence? Maybe 
there could be an additional "With":
- Then: appends the tween at the end of the Sequence
- And: inserts the tween at the beginning of the Sequence
- With: inserts the tween in parallel to the tween that is currently the last 
one in the Sequence

Original comment by daniele....@gmail.com on 10 Sep 2014 at 12:25

GoogleCodeExporter commented 8 years ago
Sorry for the delay in response here.  I was originally thinking of "And" as 
being the same as "With".  I agree that "With" is a better name for it.  

Original comment by thematth...@gmail.com on 30 Sep 2014 at 8:14

GoogleCodeExporter commented 8 years ago
Hey, my time to be delayed here sorry :P I'm now deep into the path plugin 
architecture so I'm postponing thoughts about Then and And, but I actually 
think of implementing them with some kind of "multi-tween" creation method in 
the future.

Original comment by daniele....@gmail.com on 9 Oct 2014 at 8:25

GoogleCodeExporter commented 8 years ago
Multi-tween sounds awesome.  I think covers the same use-case Then/And were 
targeting, but sounds like a more general solution that covers a number of 
other cases as well.  I appreciate the time & effort you've put into the 
library, and consideration you've given to the feature.

Thanks!!!

Original comment by thematth...@gmail.com on 9 Oct 2014 at 1:15

GoogleCodeExporter commented 8 years ago
Just to throw an update here. I tried various solutions for multi-tweens and a 
couple for And and Then but none satisfied me. Didn't forget about this though 
:)

Original comment by daniele....@gmail.com on 29 Jan 2015 at 11:26