xxl

我在开发一套技能系统,每个技能由多个Spine动作组成。
在监听事件时遇到了许多代码问题。

无论是动画开始事件还是动画结束事件,Spine都不能保证一定会触发。
接口设计的非常不直观,如果你的事件不能保证触发,各种情况都可能导致事件被跳过,那么这个接口提供的意义在哪里。

希望得到简单直接的使用方法,监听的事件可以保证会被触发。
xxl
  • Postovi: 21

Harald

很遗憾听到您发现事件界面不直观。 Spine 保证发布您的事件,但根据您可能还不知道的规则。

很可能您在混用和 EventThreshold 方面遇到问题:
TrackEntry eventThreshold
事件阈值:浮动
当混合百分比 (mixTime / mixDuration) 小于 eventThreshold 时,在混合此动画时应用事件时间线。默认为 0,因此在混合此动画时不会应用事件时间线。
或如此处所述:
Coding for Spine Events and AnimationState callbacks: User events during mixing
# 混合期间的用户事件
TrackEntry 的“EventThreshold”控制在混音期间如何处理用户事件。

- 使用默认值“0”,下一个动画开始播放时立即停止引发用户事件。
- 如果将其设置为“0.5”,则用户事件在交叉淡入淡出/混音的中途停止引发。
- 如果您将其设置为“1”,事件将继续上升,直到交叉淡入淡出/混合的最后一帧。

EventThreshold 设置为您的动画的适当值很重要,因为您可能有重叠的动画,它们具有相同的动画并且不应该引发相同的动画,或者希望即使动画被中断也仍然引发事件。
-----
Sorry to hear that you find the event interface unintuitive. Spine guarantees that your events are issued, but according to rules which you may not know yet.

Most likely you are facing problems with mixing out and EventThreshold:
TrackEntry eventThreshold
eventThreshold: float
When the mix percentage (mixTime / mixDuration) is less than the eventThreshold, event timelines are applied while this animation is being mixed out. Defaults to 0, so event timelines are not applied while this animation is being mixed out.
Or as described here:
Coding for Spine Events and AnimationState callbacks: User events during mixing
# User events during mixing
A TrackEntry's EventThreshold controls how user events are treated during the mix duration.

- With the default value 0, user events stop being raised immediately when the next animation starts playing.
- If you set it to 0.5, user events stop being raised halfway through the crossfade/mix.
- If you set it to 1, events will continue to be raised up until the very last frame of the crossfade/mix.

Setting EventThreshold to the appropriate value for your animations is important, as you may have overlapping animations that have the same animations and shouldn't raise the same ones, or want events to still be raised even if the animation has been interrupted.
Avatar
Harald

Harri
  • Postovi: 4104

xxl

我的所有动画都没有混合时间。所有动画的混合时间都是0,依然不能保证触发。

经过仔细的测试,

开始事件无法触发的原因如下:

我通过 SetAnimation 接口播放动画,然后从接口返回的 TrackEntry 添加 Start 事件。Start 事件无法被触发。这在 Spine Unity 运行时文档中提到过。
从代码角度讲这很合理,但从接口设计上来说,并不方便。我用过一些其他一些动画库,它们都没有这个问题,我调用播放动画,然后设置开始事件的回调,一切正常。但 Spine 运行库做不到。
xxl
  • Postovi: 21

Harald

开始事件无法触发的原因如下:

我通过 SetAnimation 接口播放动画,然后从接口返回的 TrackEntry 添加 Start 事件。Start 事件无法被触发。这在 Spine Unity 运行时文档中提到过。
从代码角度讲这很合理,但从接口设计上来说,并不方便。我用过一些其他一些动画库,它们都没有这个问题,我调用播放动画,然后设置开始事件的回调,一切正常。但 Spine 运行库做不到。
很高兴听到您已经解决了,感谢您回复我们。 确实很遗憾,感谢反馈。
-----
The start event fails to fire for the following reasons:

I play the animation through the SetAnimation interface and then add the Start event from the TrackEntry returned by the interface. The Start event cannot be fired. This is mentioned in the Spine Unity runtime documentation.
This is reasonable from a code point of view, but inconvenient from an interface design point of view. I've used some other animation libraries and none of them have this problem, I call play animation and then set callback for start event and everything works fine. But the Spine runtime can't.
Glad to hear you've figured it out, thanks for getting back to us. It is indeed unfortunate, thanks for the feedback.
Avatar
Harald

Harri
  • Postovi: 4104


Natrag na 中国Spine用户