DOTween use Append(Tween) instead AppendCallback(()=> foo())

1.1k views Asked by At

How can I use Append(Tween) instead AppendCallback(()=> foo()) on Sequence. It will be useful to start some animation and return Tween with duration equals clip.duration

At the moment I can transfer duration of clip and use some public void to start animation:

_sequence
    .AppendCallback(some.Foo)
    .AppendInterval(some.FooDuration)

And I have to definite this:

class Some
{
    [SerializeField] private Animator _animator;
    [SerializeField] private AnimationClip _fooClip;
    
    public float FooDuration => _fooClip.length;

    public void Foo()
    {
        _animator.Play(_fooClip.name);
    }
}

I'm sure it can be better. Something like that:

_sequence
    .Append(some.Foo())

And it should be defined as like this:

class Some
{
    [SerializeField] private Animator _animator;
    [SerializeField] private AnimationClip _fooClip;
    
    private float _fooDuration => _fooClip.length;

    public Tween Foo()
    {
        _animator.Play(_fooClip.name);
        return DOTween.To(() => 0, (x) => x = 0, 0, _fooDuration); //Not this sheeet
    }
}

UPD: Sorry, I missed the brackets. But question is What I can return from Tween Foo() ? Not DOTween.To(() => 0, (x) => x = 0, 0, _fooDuration) but maybe some empty Tween with specific duration

1

There are 1 answers

4
Iggy On

Append requires a tween instead of a method.

_sequence
    .Append(some.Foo())