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; }
private void Apply() { SkeletonGraphic component = base.GetComponent <SkeletonGraphic>(); Skeleton skeleton = component.Skeleton; if (this.customSkin == null) { } this.customSkin = new Skin("custom skin"); Skin skin = skeleton.Data.FindSkin(this.baseSkinName); int slotIndex = skeleton.FindSlotIndex(this.visorSlot); Attachment attachment = skin.GetAttachment(slotIndex, this.visorKey).GetRemappedClone(this.visorSprite, this.sourceMaterial, true, true, false); this.customSkin.SetAttachment(slotIndex, this.visorKey, attachment); int num2 = skeleton.FindSlotIndex(this.gunSlot); Attachment attachment4 = skin.GetAttachment(num2, this.gunKey).GetRemappedClone(this.gunSprite, this.sourceMaterial, true, true, false); if (attachment4 != null) { this.customSkin.SetAttachment(num2, this.gunKey, attachment4); } if (this.repack) { Skin destination = new Skin("repacked skin"); destination.Append(skeleton.Data.DefaultSkin); destination.Append(this.customSkin); destination = destination.GetRepackedSkin("repacked skin", this.sourceMaterial, out this.runtimeMaterial, out this.runtimeAtlas, 0x400, 2, TextureFormat.RGBA32, false, true); skeleton.SetSkin(destination); } else { skeleton.SetSkin(this.customSkin); } skeleton.SetToSetupPose(); component.Update(0f); component.OverrideTexture = this.runtimeAtlas; Resources.UnloadUnusedAssets(); }
public void EquipNewSprite(string animationName, Sprite sprite) { EquipData data = GetEquipData(animationName); if (data == null) { Log.e("Error, equip data is null"); return; } //sprite = SpriteLoader.S.GetSpriteByName("bing_1"); //sprite = Resources.Load("bing_1", typeof(Sprite)) as Sprite; int slotIndex = skeleton.FindSlotIndex(data.slot); Attachment baseAttachment = baseSkin.GetAttachment(slotIndex, data.key); // STEP 1.1 Attachment newAttachment = baseAttachment.GetRemappedClone(sprite, sourceMaterial); // STEP 1.2 - 1.3 if (newAttachment != null) { customSkin.SetAttachment(slotIndex, data.key, newAttachment); // STEP 1.4 } if (repack) { var repackedSkin = new Skin("repacked skin"); repackedSkin.Append(skeleton.Data.DefaultSkin); repackedSkin.Append(customSkin); repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas); skeleton.SetSkin(repackedSkin); } else { skeleton.SetSkin(customSkin); } skeleton.SetToSetupPose(); skeletonGraphic.Update(0); skeletonGraphic.OverrideTexture = runtimeAtlas; }
private void Update() { _skeletonGraphic.Update(Time.deltaTime); }