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