- 수정됨
SkeletonGraphic bones get the same world position
I use the SkeletonGraphic in my UI
Spine version is spine-unity-4.0-2020-10-28-beta
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine.Unity;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
SkeletonGraphic skg;
skg = GetComponent<SkeletonGraphic>();
Debug.Log("00000000001");
Debug.Log(transform.position);
for (int i = 0, n = skg.Skeleton.Bones.Count; i < n; i++)
{
Spine.Bone bone = skg.Skeleton.Bones.Items[i];
Debug.Log(bone.Data.Name);
Debug.Log(bone.GetLocalPosition());
Debug.Log(bone.GetWorldPosition(skg.transform));
}
}
}
I wonder what is wrong?
thanks!
I also use the spine example Getting Started/6 SkeletonGraphic
SkeletonGraphic (Spineboy) add my script to test
void Update()
{
//SkeletonAnimation skg;
SkeletonGraphic skg;
skg = GetComponent<SkeletonGraphic>();
for (int i = 0; i < skg.Skeleton.Bones.Count; i++)
{
Spine.Bone bone = skg.Skeleton.Bones.Items[i];
bone.UpdateWorldTransform();
Debug.Log(bone.Data.Name);
Vector3 pos = bone.GetWorldPosition(transform);
Debug.Log(pos);
}
}
the pos is all the same
Sorry, can you please describe the problem you are having? You've shown some code but I don't know what you want to do, what you expected, and how that compares to what actually happened.
Nate wrote
I want to get the unity world position of the specified name bone.
I create a SkeletonGraphic in UI,the SkeletonGraphic is subobject of a panel.
when the SkeletonGraphic play an animation,I want to get the world postion of the specified name bone.
But I find the world postion of every bone is same.
SkeletonGraphic skg = GetComponent<SkeletonGraphic>();
Spine.Bone bone = skg.Skeleton.FindBone(boneName);
bone.UpdateWorldTransform();
Vector3 pos = bone.GetWorldPosition(skg.transform);
The pos is always the same as the pos of the root bone
I create a Bone Follower Graphic with the specified name bone.
The Bone Follower Graphic is subobject of the SkeletonGraphic .
I can get the right unity postion of the Bone Follower Graphic.
Transform a = transform.Find("Arm");
Debug.Log(a.position);
In general, you should always use the SkeletonGraphic.UpdateWorld
delegate when getting or setting bone locations, otherwise when called in Update()
your script might be called before SkeltonGraphic
and thus return the previous frame's bone location.
When using SkeletonGraphic
, you need to scale the location by the parent Canvas.referencePixelsPerUnit
value, which is typically 100. This is most likely the cause why you see everything at root position.
I have updated the documentation section to mention these pitfalls:
spine-unity Runtime Documentation: Getting and Setting Bone Transforms Manually