exdev / ex2d-dev

2D framework and pipeline for Unity3D
ex-dev.com/ex2d
GNU General Public License v3.0
6 stars 3 forks source link

exSpriteAnimation.AddAnimation 如果覆盖一个原来已有的动画,那么会自动播放. #61

Closed jwu closed 9 years ago

jwu commented 10 years ago

重现方法可以通过最新的 mw2,然后将

Item.SetLevel() 函数中的最后一段 spAnim.Stop() 注释掉。那么在新加入的硬币如果使用原来回收的硬币。就会发现硬币一出现就再播放旋转的动画。

jareguo commented 10 years ago

这里的问题主要出在spAnim的enabled状态。由于在AddAnimation时,spAnim是enabled,所以硬币自然会播放动画。

jareguo commented 10 years ago

@jwu 我觉得这里应该在spawn后做一个reset的操作

jwu commented 10 years ago

spawn 之前是有 reset 操作的。应该说,当 spawn 出来的东西,被 return (也就是回收的时候)。我们会调用 comp.enabled = false. 和 go.SetActive(false); 前者会调用到 comp 的 OnDisable ,在这个问题里对应的就是 Item, Coin 的 OnDisable.

而 OnDisable 做的事情里就是 Reset 的相关操作。

所以在 Spawn 一个物体的时候,是能够保证他拿出来的东西在调用 OnEnable 的时候是处于 OnDisable 里设置的状态。

jareguo commented 10 years ago

那在OnEnable时,应该把 spAnim.enabled = true; 去掉

jwu commented 10 years ago

可是OnDisable 的时候已经设置spanim enabled 为false。为什么不在OnEnable里设置true?

jareguo commented 10 years ago

因为你在OnDisable做的事是Reset,如果OnEnable又设回true,spawn后就不是正确reset过的状态。现在是reset -> OnDisable(disable animation) -> spawn -> OnEnable(enable animation),所以最后一出现就会播动画。

jwu commented 10 years ago

我有点糊涂了。当 spAnim 在 OnDisable 时,他被设置成 enabled = false; 这个时候应该动画就被 Stop 了对吧。那为什么 OnEnable 的时候 spAnim.enabled = true; 后会播放动画呢?

jareguo commented 10 years ago

因为SpriteAnimation是被设计成根据enabled与否来播放/停止动画的。这跟Animation的设计保持一致,否则enabled与否不就失去意义。

jwu commented 10 years ago

我记得Unity 中只有当 Animation 的 play automatically 为 true 才会生效。而 Unity 中还有 animation state。只有 animationState.enabled = true 才是播放该 animation.

jareguo commented 10 years ago

SpriteAnimation没有play automatically和animationState.enabled这两个参数,所以就默认自动播放。 不过如果只是disable再enable,Unity的Animation确实是会继续播放动画。

jareguo commented 10 years ago

问题在于,是否需要在exSpriteAnimation里保存isPlaying? 如果多了isPlaying,则同时还要加入play automatically。 目前是用enabled来取代isPlaying和play automatically,我个人觉得这样会简单一点。

jareguo commented 9 years ago

印象中已经改过了