• International中文
  • 通过SkeletonData来更换技能会导致原本监听的Event和Complete事件被移除

我想请教一个问题:我创建了一个SkeletonAnimation对象,然后添加了sk.AnimationState.Event()和Complete()事件。当我通过加载新的SkeletonData数据并把它赋值给这个sk对象时,调用了sk.Initialize(true)方法重新渲染,然后发现我的Event和Complete事件被清了,导致我必须重新添加这两个事件。有没有好的办法能让我改变SkeletonData情况下又不影响它的Event和Complete事件,或者说有其它办法能让我用一个SkeletonAnimation组件替换不同的SkeletonData数据

Related Discussions
...

@x_bin Yes, you can use AnimationState.AssignEventSubscribersFrom() or AnimationState.AddEventSubscribersFrom() to assign the previous subscribers:

AnimationState oldAnimationState = skeletonAnimation.AnimationState;
skeletonAnimation.Initialize(true);
skeletonAnimation.AnimationState.AssignEventSubscribersFrom(oldAnimationState);
  • x_bin ha risposto a questo messaggio
  • x_bin ha messo mi piace.

    Harald 频繁的这么操作会出现性能上的问题么?因为我之前的处理方式是,在更换SkeletonData时频繁的移除和添加事件,会出现性能上的问题,所以才想问问有没有好的处理方式

    @x_bin I'm not sure I understand your question correctly. If you worry about performance problems in regards to re-adding event callbacks, the bigger performance impact is the call to Initialize(true) to re-initialize the Skeleton structures. If you even go as far as to replace the SkeletonDataAsset with a different asset and reload the SkeletonData, this will be the by far most expensive operation. It will then not really matter if you re-add callback subscribers or not.

    • x_bin ha risposto a questo messaggio

      Harald 那我应该如何处理呢?我现在的需求是有不同的技能,每个技能一个SkeletonData,每次释放技能可能都会播放不同的技能,我目前是通过一个SkeletonAnimation组件,然后更换SkeletonData来播放不同的技能!有没有好的处理方式推荐一下的,谢谢!

      @x_bin Unfortunately machine translation translated your message not very clearly. The translation says that you are using different skeletons for different skills. If skills is the correct translation, what skills would these be, could you provide a few examples of what your different skeletons are? Why do you need different skeletons for that, and not e.g. different animations or skins for each skill?

      • x_bin ha risposto a questo messaggio

        Harald For example, I have a role with several skills, and each skill is exported in a spine file separately. The reason why different animations or skins are not made is that too many skills may lead to too large exported atlas.Do you think it's better to do it with a different animation or skin than the way I'm doing it now?

        @x_bin I unfortunately still don't quite undestand why skills require lots of attachments and will make the atlas grow. Could you provide an example of what a skill actually is, and what the skeleton then shows, then it's a bit easier to help.

        In general it depends on how often and at what time you change your SkeletonDataAsset and reload your skeleton. If that's at non-critical timepoints, it might not be a problem at all. The best answer is anyway to profile the scenario on your target device (e.g. with a stress test of the worst-case scenario), then you can say how much performance it really costs.

        • x_bin ha risposto a questo messaggio

          Harald Ok!Thanks, brother.