spine - unity3D(摘自博主softimagewht)

摘自:(博主 http://www.cnblogs.com/softimagewht/p/4149118.html)

//skeletonData
SkeletonAnimation skeletonAnimation = GetComponent<SkeletonAnimation>();
Debug.Log(skeletonAnimation.name);//获取角色名
Debug.Log(skeletonAnimation.skeleton.bones[5].ToString()); //获取所有骨骼数组list<spine.Bone>
Debug.Log(skeletonAnimation.skeleton.slots[5].ToString());//获取所有插槽数组
Debug.Log(skeletonAnimation.skeleton.data.animations[0].name.ToString());//获取所有动画数组
skeletonAnimation.skeleton.FindBone("root").flipX = true;//根据骨骼名获取骨骼
Debug.Log(skeletonAnimation.skeleton.FindBoneIndex("root").ToString());//根据骨骼名获取骨骼的index
Debug.Log(skeletonAnimation.skeleton.FindSlot("torso").attachment.Name);//根据slot名获取slot
Debug.Log(skeletonAnimation.skeleton.FindSlotIndex("torso").ToString());//根据slot名获取slot index
Debug.Log(skeletonAnimation.skeleton.data.FindAnimation("walk").name);//根据动画名获取动画

//skin
Debug.Log(skeletonAnimation.skeleton.data.skins[0].name.ToString());//获取所有 skin
Spine.Attachment _attachment = skeletonAnimation.skeleton.data.skins[0].GetAttachment(5,"left lower leg");//从skin通过slot的index attachment的名获取attachment

//BoneData
Spine.Bone _bone = skeletonAnimation.skeleton.FindBone("left upper leg");
Debug.Log(_bone.parent.ToString());//获取骨骼的父骨骼
Debug.Log(_bone.data.length.ToString());//获取骨骼长度
Debug.Log(_bone.rotation.ToString());//获取骨骼旋转
Debug.Log(_bone.data.scaleX.ToString());//获取骨骼放缩
Debug.Log(_bone.data.scaleY.ToString());
Debug.Log(_bone.data.inheritRotation.ToString());// 是否旋转值相对父骨骼 true是相对父骨骼
Debug.Log(_bone.data.inheritScale.ToString());//是否放缩值相对父骨骼 true是相对父骨骼

//SlotData
Spine.Slot _slot = skeletonAnimation.skeleton.FindSlot("torso");
Debug.Log(_slot.data.name);//获取slot的名字
Debug.Log(_slot.data.boneData.name);//获取slot挂靠的bone
Debug.Log(_slot.r.ToString());//获取slot的颜色R值
Debug.Log(_slot.data.attachmentName);//获取pose下slot的attachment名
_slot.data.additiveBlending = true;//获取或设置slot时候用additive blending来渲染 注释:用于特效?

//Animation
Debug.Log(skeletonAnimation.skeleton.data.animations[0].duration.ToString());//动画持续时间?
List<Spine.Timeline> _timeline = skeletonAnimation.skeleton.data.animations[0].timelines;//获取动画timeline

//Skeleton
Spine.SkeletonData _data = skeletonAnimation.skeleton.data;//获取SkeletonData
Debug.Log(_data.bones[0].ToString()); //获取所有骨骼
Debug.Log(_data.slots[0].ToString());//获取所有slots
Debug.Log(skeletonAnimation.skeleton.drawOrder[0].attachment.Name);//获取所有DrawOder
Debug.Log(skeletonAnimation.skeleton.skin.name);//获取当前skin名
skeletonAnimation.skeleton.r = 0.5f;//对skin的整体偏色 有rgba四个参数
Debug.Log(skeletonAnimation.skeleton.time.ToString());//?
skeletonAnimation.skeleton.flipX = true;//skeleton翻转轴向
skeletonAnimation.skeleton.flipY = true;
skeletonAnimation.skeleton.x = 0;//skeleton的坐标
skeletonAnimation.skeleton.y = 0;
skeletonAnimation.skeleton.SetBonesToSetupPose();
skeletonAnimation.skeleton.SetSlotsToSetupPose();
skeletonAnimation.skeleton.SetToSetupPose();

//skeletonAnimation.skeleton.GetAttachment();//获取GetAttachment
//skeletonAnimation.skeleton.SetAttachment();
skeletonAnimation.skeleton.Update(0.5f);//??
}

--换装函数,但是必须在slot里有这个attachMent名

skeletonAnimation = GetComponent<SkeletonAnimation>();
skeletonAnimation.skeleton.SetAttachment("rear_upper_arm","muzzle");
skeletonAnimation.skeleton.GetAttachment();

 

--动画翻转

if(x > 0)
skeletonAnimation.skeleton.FlipX = false;
else if(x < 0)
skeletonAnimation.skeleton.FlipX = true;

 

--播放动画

skeletonAnimation.state.SetAnimation(0, hitAnimation, false);
skeletonAnimation.state.AddAnimation(0, currentAnimation, true, 0);

注:(起始帧,动画名,是否loop)

 

//角色之间的绘制排序

renderer.sortingOrder = -5;

本人新增:

Spine.AnimationState spineAnimationState = skeletonAnimation.state;
spineAnimationState.SetAnimation(0, animationName, true);

第一个参数trackIndex是指通道序号。所谓通道Track,就是把动画分层,让角色在同一时间可以播放几个Spine动画。高层级的通道会覆盖低层级的Track:越大的通道数字就拥有越高的优先级。

第二个参数是动画的名字,第三个参数是动画是否循环。 


//
由于spine在切换动画的时候自动补偿,用于动画的平稳过度。但是会导致残影等bug,这时候需要在SetAnimation前调用下面两句
skeletonAnimation.skeleton.SetToSetupPose();
spineAnimationState.ClearTracks();
//添加事件:
skeletonAnimation.state.Start//:开始播放
skeletonAnimation.state.End//:动画被清除或者中断
skeletonAnimation.state.Interrupt//:动画被打断
skeletonAnimation.state.Complete//:播放结束
skeletonAnimation.state.Event//:用户自定义事件
skeletonAnimation.state.Event += ;
//事件设置采用lambda表达式:
skeletonAnimation.state.Complete += (state, trackIndex, loopCount) => {
   Debug.log("");
};

posted @ 2017-10-18 13:36  IT_yanghui  阅读(948)  评论(0编辑  收藏  举报