Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.33k stars 348 forks source link

DOPunchScale not calling OnComplete #541

Open Sylvus opened 2 years ago

Sylvus commented 2 years ago

I have a move sequence and when I DoPunScale does not trigger my callback function but when I insert it into the sequence in some other way it does get called. Here is the code:

private Sequence _moveSequenceBase = null;
private IEnumerator ScaleUpDownValue(float duration, int newValue, Action callback)
    {
        if (duration == 0)
        {
            SetInfoValue(newValue);
            if (callback != null)
            {
                callback();
            }
            yield break;
        }
        if (_moveSequenceBase == null || !_moveSequenceBase.IsPlaying())
        {
            // Create a new sequence:
            _moveSequenceBase = DOTween.Sequence();
            var rectTransform = CurrentValueTextObj.GetComponent<RectTransform>();
            _moveSequenceBase.InsertCallback(duration/2f, () => SetInfoValue(newValue));
            /* THIS WORKS
            if (callback != null)
            {
                _moveSequenceBase.InsertCallback(duration, () => callback());
            }
           */          
            _moveSequenceBase.Append(rectTransform.DOPunchScale(new Vector3(1f, 1f, 1f), duration).OnComplete(() => {
                // THIS DOES NOT WORK
                if (callback != null)
                {
                    callback();
                }
            }));
            yield return _moveSequenceBase.WaitForCompletion();
        }
        else
        {
            // Wait for the sequence to finish
            yield return null;
            // then call ourselves to try again.
            yield return ScaleUpDownValue(duration, newValue, callback);
        }
    }

Sorry for the complicated code but I don't have time to reduce the example further right now and hopefully it's not too hard to understand.