Hello. I'm currently making a sports game.
I need to get the time to certain event before starting the animation. (because I need to calculate when to start the animation by the event time. So I need the time before it plays.)
And I also need the position of bone at that time.
I used the following code to get the animation event time. But I'm not sure this is the best way.
Please recommend me any better ways to get the event time.
public float GetEventTimeOfAnimation(ANIMATION_INDEX index, string eventName) {
Spine.Animation animation = animationList[(int)index];
foreach (var timeline in animation.Timelines) {
var eventTimeline = timeline as Spine.EventTimeline;
if (eventTimeline != null) {
foreach (Spine.Event ev in eventTimeline.Events) {
if (ev.Data.Name == eventName) {
return ev.Time;
//change sec to mainFlow value.
}
}
}
}
And I used the following code to get the position of bone at certain time.
But this is not working. I need a changed Position but it returns the same position.
Please help me how to solve it.
Vector3 worldPosition = bone.GetWorldPosition(GetComponentInParent<Transform>());
Vector3 localPosition = skeletonAnimation.transform.InverseTransformPoint(worldPosition);
Debug.Log($"1. Bone At : {localPosition}");
skeletonAnimation.AnimationState.SetAnimation(0, animationList[(int)animationIndex], false);
skeletonAnimation.AnimationState.Update(time);
worldPosition = bone.GetWorldPosition(GetComponentInParent<Transform>());
localPosition = skeletonAnimation.transform.InverseTransformPoint(worldPosition);
Debug.Log($"2. It should be Changed : Bone At : {localPosition}");