Spine(Unity)

>>>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();
			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();
			if (ske == null) {
				return;
			}

			var state = ske.AnimationState;
			state.SetAnimation(0, name, loop);
		}

		public static void SpineEvent(GameObject obj, Action callback = null) {
			var ske = obj.GetComponent();
			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并存

Spine(Unity)_第1张图片

地址记录:

Unity Spine动画常用API_skeletonanimation_AT巡礼的博客-CSDN博客

你可能感兴趣的:(Unity,spine,unity,游戏引擎)