Spine动画 skeletonAnimation.state
1.当前动画播放完毕后自动播放下一个动画
SkeletonGraphic spine_ = new SkeletonGraphic();
spine_.AnimationState.SetAnimation(0, "start", false);
spine_.AnimationState.AddAnimation(0, "idle", true, 0);
public static void PlaySpine(GameObject obj, string name, Action callback = null) {
var ske = obj.GetComponent<Spine.Unity.SkeletonGraphic>();
if (ske == null) {
return;
}
var state = ske.AnimationState;
state.SetAnimation(0, name, false);
if (callback != null) {
Spine.AnimationState.TrackEntryDelegate onComplete = null;
onComplete = delegate {
state.Complete -= onComplete;
callback();
};
state.Complete += onComplete;
}
}
public static void PlaySpine(GameObject obj, string name, bool loop) {
var ske = obj.GetComponent<Spine.Unity.SkeletonGraphic>();
if (ske == null) {
return;
}
var state = ske.AnimationState;
state.SetAnimation(0, name, loop);
}
public static void SpineEvent(GameObject obj, Action<Event> callback = null) {
var ske = obj.GetComponent<Spine.Unity.SkeletonGraphic>();
if (ske == null) {
return;
}
if (callback == null) {
return;
}
Spine.AnimationState.TrackEntryEventDelegate onEvent = delegate (TrackEntry entry, Event e) { callback(e); };
ske.AnimationState.Event += onEvent;
}
2.自动动画补偿问题
1)由于spine在切换动画的时候自动补偿,用于动画的平稳过度。但是会导致残影等bug,这时候需要在SetAnimation前调用
skeletonAnimation.skeleton.SetToSetupPose ();
spineAnimationState.ClearTracks (); 或 skeletonGraphic.AnimationState.ClearTracks();
来消除前一个动画的影响。2)也可以执行重置spine
在播放下一个动画前调用: skeletonGraphic.Initialize(true);
3.事件
skeletonAnimation.state.Start:开始播放
skeletonAnimation.state.End:动画被清除或者中断
skeletonAnimation.state.Interrupt:动画被打断
skeletonAnimation.state.Complete:播放结束
skeletonAnimation.state.Event:用户自定义事件事件设置采用lambda表达式:
skeletonAnimation.state.Complete += (state, trackIndex,loopCount) => {
Debug.log("");
};
4.动态获取slot的坐标:
Vector3 pos = skeletonAnimation.skeleton.FindSlot("hat_1").Bone.GetWorldPosition(transform);
Spine之SkeletonGraphic与Button并存
文章来源:https://www.toymoban.com/news/detail-516169.html
重置动画:Initialize
Spine.Unity.SkeletonGraphic skeleton;
skeleton.Initialize(true);
Refrence:
Unity Spine动画常用API_skeletonanimation_AT巡礼的博客-CSDN博客文章来源地址https://www.toymoban.com/news/detail-516169.html
到了这里,关于Spine(Unity)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!