cool_summer

你们好,我有个需求,就是获取到一个人物的手的位置,这个任务是一个循环动画,我现在

using System.Collections;
using System.Collections.Generic;
using Spine;
using Spine.Unity;
using UnityEngine;

public class test : MonoBehaviour
{
public SkeletonGraphic skeletonGraphic;
private BoneData bons;
private Bone bons2;
public SkeletonRenderer skeletonRenderer;
void Start()
{
skeletonGraphic = this.transform.GetComponent<SkeletonGraphic>();
// bons2 = skeletonRenderer.skeleton.FindBone("body_02");
// bons2.UpdateWorldTransform();
var exposedList = skeletonGraphic.skeletonDataAsset.GetSkeletonData(true).Bones;

foreach (var VARIABLE in exposedList)
{
if (VARIABLE.name == "body_02")
{
bons = VARIABLE;
// print(VARIABLE.parent);
// print(VARIABLE.X);
// print(VARIABLE.Y);
// print(VARIABLE.Rotation);
}

}
}

// Update is called once per frame
void Update()
{
// bons2 = skeletonRenderer.skeleton.FindBone("body_02");
// bons2.UpdateWorldTransform();
// bons2.GetWorldPosition(skeletonRenderer.transform);
print(bons.X);
print(bons.Y);
print(bons.Rotation);
}
}
打印的位置是不变的,请问怎么获取变化的,感谢各位
cool_summer
  • 帖子: 4

Harald

SkeletonDataAssetSkeletonData 保存由 Spine 编辑器保存的共享动画数据,而不是您的实例数据。 您需要改为访问“骨架”数据。 请参阅此处有关此共享数据与实例分离的文档:
SkeletonData
Skeleton

请始终先查看 spin-unity 文档页面,其中涵盖了许多常见用例,例如获取骨骼位置:
spine-unity 运行时文档: 手动获取和设置骨骼Transforms

一般来说(如果可能的话)你可以简单地使用 BoneFollowerGraphic 组件来让 Transform 跟随骨骼。

-----

SkeletonDataAsset and SkeletonData hold shared animation data as saved by the Spine Editor, not your instance data. You need to access the Skeleton data instead. See documentation here regarding this shared-data vs. instance separation:
SkeletonData
Skeleton

Please always have a look at the spine-unity documentation page first, which covers many common use cases such as getting a bone position:
spine-unity 运行时文档: 手动获取和设置骨骼Transforms

In general (if possible) you could simply use a BoneFollowerGraphic component to let a Transform follow a bone.
头像
Harald

Harri
  • 帖子: 4088

cool_summer

thanks,谢谢您的回复
cool_summer
  • 帖子: 4


回到 中国Spine用户