在调用local trackEntry = animationState:SetAnimation(0, animationName, loop)时,如何在trackEntry 的播放期间调用update,就是这个动画播放期间每一帧都可以调用的方法回调,我不想在MonoBehaviour的LateUpdate中做,问下spine这边还有使用方法可以达到我这个目的吗
Spine播放动画时调用Update问题
@yuanjiashun 我不确定我是否正确理解你的问题,因为机器翻译有点含糊。
如果您询问如何在“Update()”之外的其他位置更新动画,那么请将“SkeletonAnimation”检查器属性“Advanced - Animation Update”设置为例如 “修复更新”,如此处所述。
如果您想在“LateUpdate”之外的其他位置生成“MeshRenderer”网格:您能否解释一下为什么要这样做,以及您想何时更新它?
您可以设置 SkeletonAnimation.GenerateMeshOverride
委托给您自己的方法,然后您负责自己更新网格,并且可以随时调用它。
您还可以创建“SkeletonAnimation”的子类并覆盖子类中的“LateUpdateMesh”以不更新网格。
I'm not sure I understand your question correctly, as machine translation was a bit ambiguous.
If you're asking how to update animations somewhere else than in Update()
, then please set the SkeletonAnimation
Inspector proeprty Advanced - Animation Update
to e.g. Fixed Update
as described here.
If you want to generate the MeshRenderer
mesh somewhere else than in LateUpdate
: could you please explain why do you want to do that, and when would you like to update it instead?
You could set the SkeletonAnimation.GenerateMeshOverride
delegate to your own method, then you're responsible for updating the mesh yourself and could call that whenever you want.
You could also create a subclass of SkeletonAnimation
and override LateUpdateMesh
in your subclass to not update the mesh.
I want to implement a callback in the following way
not OnUpdate Function,Is there any other way to achieve the same effect?
@yuanjiashun 感谢您提供额外信息。 TrackEntry
和 AnimationState
不是 Unity MonoBehaviours,也不是 Unity 实体,没有可以挂钩的 OnUpdate
。
请描述你想要实现什么(你的目标是什么),你想要解决什么问题,而不是你想如何称呼某件事。
Thanks for the additional info. TrackEntry
and AnimationState
are not Unity MonoBehaviours and also not Unity entities, there is no OnUpdate
to hook into.
Please describe what you want to achieve (what your goal is), what problem you want to solve, not how you want to do something.
我想在播放某个动画的期间,每一帧都调用某个回调,这是我的目标!
感谢您回复我们。 每个“TrackEntry”没有可用的直接回调,每帧都会调用它。
可用的 TrackEntry
回调(可在各个 TrackEntry
和所有条目的 AnimationState
处使用)如下所述:
https://zh.esotericsoftware.com/spine-unity#%E5%A4%84%E7%90%86AnimationStates%E4%BA%8B%E4%BB%B6
和这里:
http://esotericsoftware.com/spine-api-reference#AnimationStateListener-start
您可以使用这些回调通过“trackEntry.Start”注册所需的方法,并通过“trackEntry.End”结束调用您的回调。
在“SkeletonAnimation”中每帧调用的合适回调是“SkeletonAnimation.BeforeApply”和“SkeletonAnimation.UpdateLocal”,如此处。
void Start(){
TrackEntry trackEntry = AnimationState.AddAnimation(..);
trackEntry.Start += (entry) => { SkeletonAnimation.UpdateLocal += EveryFrameCallback; };
trackEntry.End += (entry) => { SkeletonAnimation.UpdateLocal -= EveryFrameCallback; };
}
void EveryFrameCallback (ISkeletonAnimation skeletonAnimation) {
Debug.Log("your callback called");
}
当然,您可以相应地修改源代码,并自己添加一个回调方法,类似于其他回调委托,如“Start”、“End”等。
Thanks for getting back to us. There is no direct callback available per TrackEntry
which is called every frame.
The available TrackEntry
callbacks (available at individual TrackEntry
, and AnimationState
for all entries) are described here:
https://zh.esotericsoftware.com/spine-unity#%E5%A4%84%E7%90%86AnimationStates%E4%BA%8B%E4%BB%B6
and here:
http://esotericsoftware.com/spine-api-reference#AnimationStateListener-start
You could use these callbacks to register your desired method with trackEntry.Start
and end calling your callback with trackEntry.End
.
Suitable callbacks which are called every frame at SkeletonAnimation
are SkeletonAnimation.BeforeApply
and SkeletonAnimation.UpdateLocal
, as described here.
void Start () {
TrackEntry trackEntry = animationState.AddAnimation(..);
trackEntry.Start += (entry) => { skeletonAnimation.UpdateLocal += EveryFrameCallback; };
trackEntry.End += (entry) => { skeletonAnimation.UpdateLocal -= EveryFrameCallback; };
}
void EveryFrameCallback (ISkeletonAnimation skeletonAnimation) {
Debug.Log("your callback called");
}
You could of course modify the source code accordingly and add a callback method yourself analogous to the other callback delegates like Start
, End
, and so on.
Thanks for being so useful, you're the best official I've ever seen!!
感谢您的客气话,很高兴有帮助!
Thanks for your kind words, very glad it helped!