public void AnalysisConfig() { AssetBundlePackage pp = HFResourceManager.Instance.LoadAssetBundleFromFile("Common_Config"); TextAsset tt = pp.LoadAssetWithCache <TextAsset>("SpineExchangeConfig"); SpineEquipment ex = JsonMapper.ToObject <SpineEquipment>(tt.text); for (int i = 0; i < ex.Equipment.Count; i++) { EquipmentItem item = ex.Equipment[i]; equipmentInfoDic.Add(item.ID, item); } }
public void ExchangeEquipmentAndMergeUI(SkeletonGraphic skeletonAnimation, List <EquipmentItem> infos) { for (int i = 0; i < infos.Count; i++) { EquipmentItem info = infos[i]; string regionName = info.equipmentImageName; string defaultSkinName = info.defaultSkinName; string spineEquipmentType = info.spineEquipmentTypeName; AssetBundlePackage assetbundle = HFResourceManager.Instance.LoadAssetBundleFromFile(info.equipmentAssetbundleName); AtlasAsset atlasAsset = assetbundle.LoadAssetWithCache <AtlasAsset>(info.equipmentAtlasAssetName); float scale = skeletonAnimation.skeletonDataAsset.scale; Atlas atlas = atlasAsset.GetAtlas(); AtlasRegion region = atlas.FindRegion(regionName); Slot slot = skeletonAnimation.Skeleton.FindSlot(info.slotName); Attachment originalAttachment = slot.Attachment; if (region == null) { HFLog.C("没有找到图集里的 : 图片 " + regionName); slot.Attachment = null; } else if (originalAttachment != null) { slot.Attachment = originalAttachment.GetRemappedClone(region, true, true, 1); } else { var newRegionAttachment = region.ToRegionAttachment(region.name, scale); slot.Attachment = newRegionAttachment; } slot.Skeleton.Skin.SetAttachment(slot.Data.Index, info.slotPlaceholderName, slot.Attachment); } Skin repackedSkin = new Skin(RepackConst); repackedSkin.Append(skeletonAnimation.Skeleton.Data.DefaultSkin); // Include the "default" skin. (everything outside of skin placeholders) repackedSkin.Append(skeletonAnimation.Skeleton.Skin); // Include your new custom skin. Texture2D runtimeAtlas = null; Material runtimeMaterial = null; repackedSkin = repackedSkin.GetRepackedSkin(RepackConst, skeletonAnimation.SkeletonDataAsset.atlasAssets[0].materials[0], out runtimeMaterial, out runtimeAtlas); // Pack all the items in the skin. skeletonAnimation.Skeleton.SetSkin(repackedSkin); // Assign the repacked skin to your Skeleton. skeletonAnimation.Skeleton.SetSlotsToSetupPose(); // Use the pose from setup pose. skeletonAnimation.Update(0); // Use the pose in the currently active animation. skeletonAnimation.OverrideTexture = runtimeAtlas; }
/// <summary> /// 替换spine部件 但是不合并材质球 /// </summary> /// <param name="skeletonAnimation"></param> /// <param name="item"></param> public void ExchangeEquipment(SkeletonAnimation skeletonAnimation, EquipmentItem item) { AssetBundlePackage pg = HFResourceManager.Instance.LoadAssetBundleFromFile(item.equipmentAssetbundleName); Texture2D equipmentTexture = pg.LoadAssetWithCache <Texture2D>(item.equipmentImageName); // 找到具体的一个 插槽 Slot slot = skeletonAnimation.skeleton.FindSlot(item.slotName); // 通过插槽和一张图片创建对应插槽下的附件 Attachment attachment = null; if (item.attachmentType == (int)AttachmentType.Region) { attachment = CreateRegionAttachmentByTexture(slot, equipmentTexture); } else if (item.attachmentType == (int)AttachmentType.Mesh) { attachment = CreateMeshAttachmentByTexture(slot, equipmentTexture); } // 设置新的附件到插槽 slot.Skeleton.Skin.SetAttachment(slot.Data.index, item.slotPlaceholderName, attachment); }