骨骼常用API

2019-07-23  本文已影响0人  JJJJJJJJJJC

获取当前0轨道动画时间:

当前轨道动画总时长
SkeletonAnimation.state.GetCurrent(0).AnimationEnd

替换资源:

骨骼动画.state.Event += 攻击事件;

骨骼动画.state.GetCurrent(0).Event += 攻击事件;


获取插槽和设置碰撞盒

        var 受击边框盒 = 骨骼.GetAttachment("body", "body") as BoundingBoxAttachment;
        var 受击盒插槽 = 骨骼.FindSlot("body");
        受击盒.SetPath(0, 受击边框盒.GetWorldVertices(受击盒插槽, null));

判断碰撞盒是否消失

  Debug.Log(玩家_.攻击盒插槽.Attachment);//如果为null就是消失. 否则输出附加者(名称)
//也可以考判断是否为null.

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();

播放动画

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

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

角色之间的绘制排序

renderer.sortingOrder = -5;

UGUI 与 Spine 的完美结合

SkeletonGraphic.cs       代替官方的  SkeletonAnimation.cs   使用(对象/预制体上)
SkeletonGraphic.shader   代替 官方的   Spine/Skeleton  shader 使用(赋值给材质上)
上一篇下一篇

猜你喜欢

热点阅读