• 中文
  • Unity中使用SkeletonMecanim的有关问题

你好,
我正在用Unity做一个2D项目,然后我spine制作了人物骨骼动画并导入进了unity,
之后使用SkeletonMecanim的模式创建了一个玩家物体,并设置好了动画状态机。

之后人物移动和动画状态切换都没有什么问题,但是没有办法像官方案例中控制玩家骨骼的旋转。
因为没有使用SkeletonAnimation模式,所以我直接用animator.GetBoneTransform来试着获取所需骨骼,
但可能是因为我没有设置Avatar,所以无法通过这种方式获取到骨骼。
但是我也尝试使用了Spine的API,利用skeletonAnimation.Skeleton.FindBone获取骨骼,
这样是可以获取到由Spine创建的骨骼的,但是可能是因为动画正在被Animator控制,所以我无法使用bone.Rotation来改变骨骼的旋转。

请问有没有方法可以满足我使用Animator来控制骨骼呢?谢谢你们。

hello,
I am working on a 2D project with unity,
and I create a player from spine skeletondata by using SkeletonMecanim because I want to use unity animator controller to control player animation.

But I got a problem that I cannot get player bones through animator.GetBoneTransform or SkeletonAnimation neither.
With the GetBoneTransform,I guess the problem is because that I cannot set a avatar to the player animator controller so it couldn't find the bone.And with the skeletonAnimation.Skeleton.FindBone,I guess it is because I didn't use the SkeletonAnimation,so that even though it find the correct bone,I also cannot use bone.Rotation to set its rotation.
But I don't know is there any other way to solve this problem.

I am afraid of that google translate cannot translate it correctlly,but I cannot describe this issue clearly in English neither.
So I wrote this forum in both languages,but the English version not directly translate from Chinese version.
Thanks a lot.

Related Discussions
...

调用animator.GetBoneTransform()是不行的,因为SkeletonMecanim不使用Unity的骨骼做动画,所以没有添加Animator的骨骼。

但是,skeletonMecanim.Skeleton.FindBone()后面的bone.Rotation = angleSkeletonMecanim所支持的。和往常一样,你必须确保在动画计算出局部旋转之后,在正确的时间调用它,否则动画会覆盖你的改变。可以通过使用回调委托skeletonMecanim.UpdateLocal来实现,如下所示。

skeletonMecanim.UpdateLocal -= UpdateLocal。
skeletonMecanim.UpdateLocal += UpdateLocal;

void UpdateLocal (ISkeletonAnimation anim) {
    bone = skeletonMecanim.Skeleton.FindBone(boneName)。
    bone.Rotation = angle;
}

Calling animator.GetBoneTransform will not work because SkeletonMecanim does not use Unity's bones for animation, so no Animator bones are added.

However, skeletonMecanim.Skeleton.FindBone() followed by bone.Rotation = angle is supported by SkeletonMecanim. As always, you have to be sure to call it at the right time after the animation has calculated local rotations, otherwise animation will override your changes. This can be done by using the callback delegate skeletonMecanim.UpdateLocal as follows:

skeletonMecanim.UpdateLocal -= UpdateLocal;
skeletonMecanim.UpdateLocal += UpdateLocal;

void UpdateLocal (ISkeletonAnimation anim) {
    bone = skeletonMecanim.Skeleton.FindBone(boneName);
    bone.Rotation = angle;
}