private void Apply(SkeletonRenderer skeletonRenderer) { if (base.enabled) { this.atlas = this.atlasAsset.GetAtlas(); if (this.atlas != null) { float scale = skeletonRenderer.skeletonDataAsset.scale; foreach (SlotRegionPair pair in this.attachments) { Slot slot = skeletonRenderer.Skeleton.FindSlot(pair.slot); Attachment o = slot.Attachment; AtlasRegion atlasRegion = this.atlas.FindRegion(pair.region); if (atlasRegion == null) { slot.Attachment = null; } else if (this.inheritProperties && (o != null)) { slot.Attachment = o.GetRemappedClone(atlasRegion, true, true, scale); } else { RegionAttachment attachment2 = atlasRegion.ToRegionAttachment(atlasRegion.name, scale, 0f); slot.Attachment = attachment2; } } } } }
} // Allow checkbox in inspector void Apply(SkeletonRenderer skeletonRenderer) { if (!this.enabled) { return; } atlas = atlasAsset.GetAtlas(); float scale = skeletonRenderer.skeletonDataAsset.scale; foreach (var entry in attachments) { Slot slot = skeletonRenderer.Skeleton.FindSlot(entry.slot); Attachment originalAttachment = slot.Attachment; AtlasRegion region = atlas.FindRegion(entry.region); if (region == null) { slot.Attachment = null; } else if (inheritProperties && originalAttachment != null) { slot.Attachment = originalAttachment.GetRemappedClone(region, true, true, scale); } else { var newRegionAttachment = region.ToRegionAttachment(region.name, scale); slot.Attachment = newRegionAttachment; } } }
void Apply(SkeletonRenderer skeletonRenderer) { atlas = AtlasAsset.GetAtlas(); if (atlas == null) { return; } float scale = skeletonRenderer.skeletonDataAsset.scale; foreach (var entry in attachments) { Slot slot = skeletonRenderer.Skeleton.FindSlot(entry.slot); Attachment originalAttachment = slot.Attachment; AtlasRegion region = atlas.FindRegion(entry.region); if (region == null) { slot.Attachment = null; } else if (inheritProperties && originalAttachment != null) { slot.Attachment = originalAttachment.GetRemappedClone(region, true, true, scale); } else { var newRegionAttachment = region.ToRegionAttachment(region.name, scale); slot.Attachment = newRegionAttachment; } if (!entry.UseOriginalData) { RegionAttachment ra = slot.Attachment as RegionAttachment; if (ra == null) { return; } ra = (RegionAttachment)ra.Copy(); //HeroAnimImgList.SlotRegionPair PAIR = SDDataManager.Instance // .GetPairBySlotAndRegion(CM.SkeletonIndex, entry.slot, entry.region); //Vector2 _pos = PAIR.PositionOffset; //Vector2 _scale = PAIR.Scale; //ra.Width = ra.RegionWidth * scale * _scale.x; //ra.Height = ra.RegionHeight * scale * _scale.y; //ra.SetPositionOffset( _pos * scale * _scale ); ra.UpdateOffset(); slot.Attachment = ra; } } }
public static RegionAttachment ToRegionAttachmentPMAClone(this Sprite sprite, Shader shader, TextureFormat textureFormat = 4, bool mipmaps = false, Material materialPropertySource = null, float rotation = 0f) { if (sprite == null) { throw new ArgumentNullException("sprite"); } if (shader == null) { throw new ArgumentNullException("shader"); } AtlasRegion region = sprite.ToAtlasRegionPMAClone(shader, textureFormat, mipmaps, materialPropertySource); float scale = 1f / sprite.pixelsPerUnit; return(region.ToRegionAttachment(sprite.name, scale, rotation)); }
public static RegionAttachment ToRegionAttachment(this Sprite sprite, AtlasPage page, float rotation = 0f) { if (sprite == null) { throw new ArgumentNullException("sprite"); } if (page == null) { throw new ArgumentNullException("page"); } AtlasRegion region = sprite.ToAtlasRegion(page); float scale = 1f / sprite.pixelsPerUnit; return(region.ToRegionAttachment(sprite.name, scale, rotation)); }
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 SetAtttachment(SkeletonAnimation skeletonrenderer, string resName, string slotStrm) public void SetAttachment(SkeletonAnimation skeletonrenderer, string atlasName, string regionStr, string slotStr, string attachName = "") { // float scale = skeletonrenderer.skeletonDataAsset.scale; Slot slot = skeletonrenderer.skeleton.FindSlot(slotStr); if (slot == null) { return; //没有slot,可能表示没有该细节 } if (atlasName.Equals("")) //直接加载texture { Sprite tex = RoleGenerateManager.instance.LoadTexture(regionStr); if (tex == null) { Debug.LogErrorFormat("<RoleGenerator> 找不到贴图{0}", regionStr); return; } Attachment originalAttachment = slot.Attachment; if (originalAttachment != null) { slot.Attachment = originalAttachment.GetRemappedClone(tex, skeletonrenderer.SkeletonDataAsset.atlasAssets[0].materials[0]); } else { slot.Attachment = tex.ToRegionAttachment(skeletonrenderer.SkeletonDataAsset.atlasAssets[0].materials[0]); } } else { AtlasRegion atlasRegion = null; Atlas atlas = RoleGenerateManager.instance.LoadPartAtlas(atlasName).GetAtlas(); atlasRegion = atlas.FindRegion(regionStr); if (atlasRegion == null) { Debug.LogErrorFormat("<RoleGenerator> 图集:{0}中没有切片{1}", atlasName, regionStr); return; } Attachment originalAttachment = slot.Attachment; if (originalAttachment != null) { slot.Attachment = originalAttachment.GetRemappedClone(atlasRegion); } else { slot.Attachment = atlasRegion.ToRegionAttachment(atlasRegion.name); } } // if (slot!=null) // { // customSkin = customSkin ?? new Skin("custom skin"); // This requires that all customizations are done with skin placeholders defined in Spine. // int slotIndex = skeletonrenderer.skeleton.FindSlotIndex(slotStr); // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster. // Skin templateSkin = skeletonrenderer.skeleton.Data.DefaultSkin; // Attachment templateAttachment = templateSkin.GetAttachment(slotIndex, attachName); // Attachment newAttachment = templateAttachment.GetRemappedClone(sprite, sourceMaterial); // customSkin.SetAttachment(slotIndex, attachName, newAttachment); // } }