[笔记][Unity3D]DoTweenAnimation可视化使用问题记录

4,254 阅读1分钟

1、动态赋值endValue3后,调用DoPlay并没有按想要的情况执行

在Editor中将DoTweenAnimation添加到GameObject后,目的坐标需要动态赋值,保留(0, 0, 0)。然后在代码中获取DoTweenAnimation,赋值endValue3,调用DoPlay,发现Tween播放失败。

_focusPosTween = gameObject.GetComponent<DOTweenAnimation>();

...

_focusPosTween.endValueV3 = courierFocusPos[_curFocusCourierIdx];
_focusPosTween.DOPlay();

查过DoTweenAnimatin源码之后,发现需要重新设置才行,正确代码如下

_focusPosTween = gameObject.GetComponent<DOTweenAnimation>();

...

_focusPosTween.DOKill();   //新增,重置原来的数据
_focusPosTween.CreateTween();   //新增,重新创建Tween
_focusPosTween.endValueV3 = courierFocusPos[_curFocusCourierIdx];
_focusPosTween.DOPlay();

Tween运行正常了。

2、关于onComplete并没有被回调

_focusPosTween.onComplete.AddListener(OnFocusPosTweenComplete);

代码中加了onComplete事件之后,需要在Editor中,将DoTweenAnimation视图的Events属性里的OnComplete按钮点亮:

这样就可以了。