spine共享骨骼
项目中遇到使用多个相同spine的问题:
我们需要获取骨骼位置的时候,要拿下面这个类的信息
spine工具给的更新方案是:每个spine在Update中每帧更新,根据当前spine更新骨骼信息。
这样比较费,比如我们项目场景中有五个角色,每个角色有五个编制,那光友方单位就是25个spine,很难蚌。
优化方案:每个角色设置一个主体spine,主体spine在Update中更新数据,剩下的4个相同spine在获取骨骼接口的时候同步一下主体spine的位置就可以(反正都是相对坐标,都是一致的)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | public void CopyMainframeSkeletonData() { //主体spine if (mainframeSkeletonAnimation.skeleton == null ) return ; if (skeleton == mainframeSkeletonAnimation.skeleton) return ; for ( int i = 0, j = skeleton.bones.Count; i < j; i++) { Bone thisBone = skeleton.bones[i]; Bone sharedBone = mainframeSkeletonAnimation.skeleton.bones[i]; thisBone.x = sharedBone.x; thisBone.y = sharedBone.y; thisBone.rotation = sharedBone.rotation; thisBone.rotationIK = sharedBone.rotationIK; thisBone.scaleX = sharedBone.scaleX; thisBone.scaleY = sharedBone.scaleY; thisBone.flipX = sharedBone.flipX; thisBone.flipY = sharedBone.flipY; thisBone.m00 = sharedBone.m00; thisBone.m01 = sharedBone.m01; thisBone.m10 = sharedBone.m10; thisBone.m11 = sharedBone.m11; thisBone.worldX = sharedBone.worldX; thisBone.worldY = sharedBone.worldY; thisBone.worldRotation = sharedBone.worldRotation; thisBone.worldScaleX = sharedBone.worldScaleX; thisBone.worldScaleY = sharedBone.worldScaleY; thisBone.worldFlipX = sharedBone.worldFlipX; thisBone.worldFlipY = sharedBone.worldFlipY; } // 复制slot信息 for ( int i = 0, j = skeleton.slots.Count; i < j; i++) { Slot thisSlot = skeleton.slots[i]; Slot sharedSlot = mainframeSkeletonAnimation.skeleton.slots[i]; thisSlot.Attachment = sharedSlot.Attachment == null ? null : skeleton.GetAttachment(i, sharedSlot.Attachment.Name); } // 复制order信息 if (mainframeSkeletonAnimation.skeleton.drawOrderToSetupIndex == null ) { skeleton.drawOrder.Clear(); skeleton.drawOrder.AddRange(skeleton.slots); } else { for ( int k = 0, n = mainframeSkeletonAnimation.skeleton.drawOrderToSetupIndex.Length; k < n; k++) skeleton.drawOrder[k] = skeleton.slots[mainframeSkeletonAnimation.skeleton.drawOrderToSetupIndex[k]]; } } |
在获取骨骼位置的时候调用一下这个函数刷新就可以了。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了