From 0791df8c4c8dd799b06d23cfa9711a5069230a81 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 20 May 2019 11:43:00 +0200 Subject: [PATCH] [csharp] Ported skin API changes part2, see #841. Port of changes of commit ff5b854860f639af1c111596bc407cbe12124d1e. --- spine-csharp/src/Skeleton.cs | 4 +- spine-csharp/src/Skin.cs | 53 ++++++++++++------- .../spine-unity/Editor/PointFollowerEditor.cs | 5 +- .../spine-unity/Editor/SkeletonBaker.cs | 30 +++++------ .../Editor/SkeletonDataAssetInspector.cs | 15 +++--- .../spine-unity/Editor/SkeletonDebugWindow.cs | 10 ++-- .../Editor/SpineAttributeDrawers.cs | 28 +++++----- .../Editor/SkeletonUtilityBoneInspector.cs | 6 ++- .../Asset Types/BlendModeMaterialsAsset.cs | 15 +++--- .../AttachmentTools/AttachmentTools.cs | 26 ++++----- .../BoundingBoxFollower.cs | 14 +++-- .../Modules/Ragdoll/SkeletonRagdoll.cs | 14 +++-- .../Modules/Ragdoll/SkeletonRagdoll2D.cs | 12 ++--- 13 files changed, 123 insertions(+), 109 deletions(-) diff --git a/spine-csharp/src/Skeleton.cs b/spine-csharp/src/Skeleton.cs index cd6fedef4..6385fd64b 100644 --- a/spine-csharp/src/Skeleton.cs +++ b/spine-csharp/src/Skeleton.cs @@ -235,8 +235,10 @@ namespace Spine { } private void SortPathConstraintAttachment (Skin skin, int slotIndex, Bone slotBone) { - foreach (var entry in skin.Attachments.Keys) + foreach (var entryObj in skin.Attachments.Keys) { + var entry = (Skin.SkinEntry)entryObj; if (entry.SlotIndex == slotIndex) SortPathConstraintAttachment(entry.Attachment, slotBone); + } } private void SortPathConstraintAttachment (Attachment attachment, Bone slotBone) { diff --git a/spine-csharp/src/Skin.cs b/spine-csharp/src/Skin.cs index 2eb6fa149..4771061c1 100644 --- a/spine-csharp/src/Skin.cs +++ b/spine-csharp/src/Skin.cs @@ -28,7 +28,9 @@ *****************************************************************************/ using System; +using System.Collections; using System.Collections.Generic; +using System.Collections.Specialized; namespace Spine { /// Stores attachments by slot index and attachment name. @@ -37,12 +39,11 @@ namespace Spine { /// public class Skin { internal string name; - private Dictionary attachments = - new Dictionary(SkinEntryComparer.Instance); + private OrderedDictionary attachments = new OrderedDictionary(SkinEntryComparer.Instance); // contains public string Name { get { return name; } } - public Dictionary Attachments { get { return attachments; } } - + public OrderedDictionary Attachments { get { return attachments; } } + public Skin (string name) { if (name == null) throw new ArgumentNullException("name", "name cannot be null."); this.name = name; @@ -56,19 +57,30 @@ namespace Spine { attachments[new SkinEntry(slotIndex, name, attachment)] = attachment; } - ///Adds all attachments from the specified skin to this skin. + ///Adds all attachments, bones, and constraints from the specified skin to this skin. public void AddSkin (Skin skin) { foreach (SkinEntry entry in skin.attachments.Keys) SetAttachment(entry.SlotIndex, entry.Name, entry.Attachment); } + ///Adds all attachments from the specified skin to this skin. Attachments are deep copied. + public void CopySkin (Skin skin) { + // note: bones and constraints are added in a separate commit. + + foreach (SkinEntry entry in skin.attachments.Keys) { + Attachment attachment = entry.Attachment.Copy(); + if (attachment is MeshAttachment) { + } + SetAttachment(entry.SlotIndex, entry.Name, attachment); + } + } + /// Returns the attachment for the specified slot index and name, or null. /// May be null. public Attachment GetAttachment (int slotIndex, string name) { - Attachment attachment; var lookup = new SkinEntry(slotIndex, name, null); - attachments.TryGetValue(lookup, out attachment); - return attachment; + var obj = attachments[lookup]; + return (obj == null) ? null : (Attachment)obj; } /// Removes the attachment in the skin for the specified slot index and name, if any. @@ -86,13 +98,11 @@ namespace Spine { return entries; } - /// Returns all instances for the given slot contained in this skin. + /// Returns all attachments for the given slot in this skin. /// The target slotIndex. To find the slot index, use or - public List GetEntries (int slotIndex) { - List entries = new List(); + public void GetAttachments (int slotIndex, List attachments) { foreach (SkinEntry entry in this.attachments.Keys) - if (entry.SlotIndex == slotIndex) entries.Add(entry); - return entries; + if (entry.SlotIndex == slotIndex) attachments.Add(entry); } override public string ToString () { @@ -144,18 +154,21 @@ namespace Spine { } } - // Avoids boxing in the dictionary. - class SkinEntryComparer : IEqualityComparer { + // Avoids boxing in the dictionary and is necessary to omit entry.attachment in the comparison. + class SkinEntryComparer : IEqualityComparer { internal static readonly SkinEntryComparer Instance = new SkinEntryComparer(); - bool IEqualityComparer.Equals (SkinEntry o1, SkinEntry o2) { - if (o1.SlotIndex != o2.SlotIndex) return false; - if (!string.Equals(o1.Name, o2.Name, StringComparison.Ordinal)) return false; + bool IEqualityComparer.Equals (object o1, object o2) { + var e1 = (SkinEntry)o1; + var e2 = (SkinEntry)o2; + if (e1.SlotIndex != e2.SlotIndex) return false; + if (!string.Equals(e1.Name, e2.Name, StringComparison.Ordinal)) return false; return true; } - int IEqualityComparer.GetHashCode (SkinEntry o) { - return o.Name.GetHashCode() + o.SlotIndex * 37; + int IEqualityComparer.GetHashCode (object o) { + var e = (SkinEntry)o; + return e.Name.GetHashCode() + e.SlotIndex * 37; } } } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/PointFollowerEditor.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/PointFollowerEditor.cs index 8cde89ae2..6d08bf6d3 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/PointFollowerEditor.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/PointFollowerEditor.cs @@ -27,6 +27,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +using System.Collections; using UnityEditor; using UnityEngine; @@ -110,10 +111,10 @@ namespace Spine.Unity.Editor { } static void DrawPointsInSkin (Skin skin, Skeleton skeleton, Transform transform) { - foreach (var skinEntry in skin.Attachments) { + foreach (DictionaryEntry skinEntry in skin.Attachments) { var attachment = skinEntry.Value as PointAttachment; if (attachment != null) { - var skinKey = skinEntry.Key; + var skinKey = (Skin.SkinEntry)skinEntry.Key; var slot = skeleton.Slots.Items[skinKey.SlotIndex]; DrawPointAttachmentWithLabel(attachment, slot.Bone, transform); } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonBaker.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonBaker.cs index c33a065db..c20032981 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonBaker.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonBaker.cs @@ -228,13 +228,11 @@ namespace Spine.Unity.Editor { List attachmentNames = new List(); for (int i = 0; i < skinCount; i++) { var skin = skins.Items[i]; - List temp = new List(); - var entries = skin.GetEntries(s); - foreach (var entry in entries) - temp.Add(entry.Name); - foreach (string str in temp) { - if (!attachmentNames.Contains(str)) - attachmentNames.Add(str); + var skinEntries = new List(); + skin.GetAttachments(s, skinEntries); + foreach (var entry in skinEntries) { + if (!attachmentNames.Contains(entry.Name)) + attachmentNames.Add(entry.Name); } } slotLookup.Add(s, attachmentNames); @@ -335,8 +333,8 @@ namespace Spine.Unity.Editor { } //create slots and attachments - for (int i = 0; i < skeletonData.Slots.Count; i++) { - var slotData = skeletonData.Slots.Items[i]; + for (int slotIndex = 0; slotIndex < skeletonData.Slots.Count; slotIndex++) { + var slotData = skeletonData.Slots.Items[slotIndex]; Transform slotTransform = SpineEditorUtilities.EditorInstantiation.NewGameObject(slotData.Name).transform; slotTransform.parent = prefabRoot.transform; slotTable.Add(slotData.Name, slotTransform); @@ -344,15 +342,17 @@ namespace Spine.Unity.Editor { List attachments = new List(); List attachmentNames = new List(); - var entries = skin.GetEntries(i); - foreach (var entry in entries) { + var skinEntries = new List(); + skin.GetAttachments(slotIndex, skinEntries); + foreach (var entry in skinEntries) { attachments.Add(entry.Attachment); attachmentNames.Add(entry.Name); } if (skin != skeletonData.DefaultSkin) { - entries = skeletonData.DefaultSkin.GetEntries(i); - foreach (var entry in entries) { + skinEntries.Clear(); + skeletonData.DefaultSkin.GetAttachments(slotIndex, skinEntries); + foreach (var entry in skinEntries) { attachments.Add(entry.Attachment); attachmentNames.Add(entry.Name); } @@ -388,7 +388,7 @@ namespace Spine.Unity.Editor { rotation = 0; if (isWeightedMesh) - mesh = ExtractWeightedMeshAttachment(attachmentMeshName, meshAttachment, i, skeletonData, boneList, mesh); + mesh = ExtractWeightedMeshAttachment(attachmentMeshName, meshAttachment, slotIndex, skeletonData, boneList, mesh); else mesh = ExtractMeshAttachment(attachmentMeshName, meshAttachment, mesh); @@ -418,7 +418,7 @@ namespace Spine.Unity.Editor { } attachmentTransform.GetComponent().sharedMaterial = material; - attachmentTransform.GetComponent().sortingOrder = i; + attachmentTransform.GetComponent().sortingOrder = slotIndex; if (attachmentName != slotData.AttachmentName) attachmentTransform.gameObject.SetActive(false); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDataAssetInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDataAssetInspector.cs index ef26a2007..52f3cf611 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDataAssetInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDataAssetInspector.cs @@ -498,23 +498,26 @@ namespace Spine.Unity.Editor { using (new SpineInspectorUtility.IndentScope()) { { - var entries = skin.GetEntries(i); - foreach (var entry in entries) { + var skinEntries = new List(); + skin.GetAttachments(i, skinEntries); + foreach (var entry in skinEntries) { slotAttachments.Add(entry.Attachment); slotAttachmentNames.Add(entry.Name); } if (skin != defaultSkin) { - entries = defaultSkin.GetEntries(i); - foreach (var entry in entries) { + skinEntries.Clear(); + defaultSkin.GetAttachments(i, skinEntries); + foreach (var entry in skinEntries) { slotAttachments.Add(entry.Attachment); slotAttachmentNames.Add(entry.Name); defaultSkinAttachmentNames.Add(entry.Name); } } else { - entries = defaultSkin.GetEntries(i); - foreach (var entry in entries) { + skinEntries.Clear(); + defaultSkin.GetAttachments(i, skinEntries); + foreach (var entry in skinEntries) { defaultSkinAttachmentNames.Add(entry.Name); } } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDebugWindow.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDebugWindow.cs index 444c048b8..17bab0cd3 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDebugWindow.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDebugWindow.cs @@ -575,13 +575,15 @@ namespace Spine.Unity.Editor { var attachments = new List(); attachmentTable.Add(skeleton.Slots.Items[i], attachments); // Add skin attachments. - var entries = skin.GetEntries(i); - foreach (var entry in entries) { + var skinEntries = new List(); + skin.GetAttachments(i, skinEntries); + foreach (var entry in skinEntries) { attachments.Add(entry.Attachment); } if (notDefaultSkin) { // Add default skin attachments. - entries = defaultSkin.GetEntries(i); - foreach (var entry in entries) { + skinEntries.Clear(); + defaultSkin.GetAttachments(i, skinEntries); + foreach (var entry in skinEntries) { attachments.Add(entry.Attachment); } } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs index 5e331684d..73c5c830f 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs @@ -177,23 +177,19 @@ namespace Spine.Unity.Editor { if (TargetAttribute.includeNone) menu.AddItem(new GUIContent(NoneString), !property.hasMultipleDifferentValues && string.IsNullOrEmpty(property.stringValue), HandleSelect, new SpineDrawerValuePair(string.Empty, property)); - for (int i = 0; i < data.Slots.Count; i++) { - string name = data.Slots.Items[i].Name; + for (int slotIndex = 0; slotIndex < data.Slots.Count; slotIndex++) { + string name = data.Slots.Items[slotIndex].Name; if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal)) { if (targetAttribute.containsBoundingBoxes) { - int slotIndex = i; - var attachments = new List(); + var skinEntries = new List(); foreach (var skin in data.Skins) { - var entries = skin.GetEntries(slotIndex); - foreach (var entry in entries) { - attachments.Add(entry.Attachment); - } + skin.GetAttachments(slotIndex, skinEntries); } bool hasBoundingBox = false; - foreach (var attachment in attachments) { - var bbAttachment = attachment as BoundingBoxAttachment; + foreach (var entry in skinEntries) { + var bbAttachment = entry.Attachment as BoundingBoxAttachment; if (bbAttachment != null) { string menuLabel = bbAttachment.IsWeighted() ? name + " (!)" : name; menu.AddItem(new GUIContent(menuLabel), !property.hasMultipleDifferentValues && name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property)); @@ -474,17 +470,19 @@ namespace Spine.Unity.Editor { attachmentNames.Clear(); placeholderNames.Clear(); - var entries = skin.GetEntries(i); - foreach (var entry in entries) { + var skinEntries = new List(); + skin.GetAttachments(i, skinEntries); + foreach (var entry in skinEntries) { attachmentNames.Add(entry.Name); } if (skin != defaultSkin) { - foreach (var entry in entries) { + foreach (var entry in skinEntries) { placeholderNames.Add(entry.Name); } - entries = defaultSkin.GetEntries(i); - foreach (var entry in entries) { + skinEntries.Clear(); + defaultSkin.GetAttachments(i, skinEntries); + foreach (var entry in skinEntries) { attachmentNames.Add(entry.Name); } } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs index 1caccbb56..2a52f9e58 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs @@ -81,8 +81,10 @@ namespace Spine.Unity.Editor { Slot slot = skeletonUtility.skeletonRenderer.skeleton.Slots.Items[i]; if (slot.Bone == utilityBone.bone) { var slotAttachments = new List(); - var entries = skin.GetEntries(skeleton.FindSlotIndex(slot.Data.Name)); - foreach (var entry in entries) { + var skinEntries = new List(); + int slotIndex = skeleton.FindSlotIndex(slot.Data.Name); + skin.GetAttachments(slotIndex, skinEntries); + foreach (var entry in skinEntries) { slotAttachments.Add(entry.Attachment); } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/BlendModeMaterialsAsset.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/BlendModeMaterialsAsset.cs index ea79d9b6f..e3bdd9944 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/BlendModeMaterialsAsset.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/BlendModeMaterialsAsset.cs @@ -52,19 +52,16 @@ namespace Spine.Unity { if (skeletonData == null) throw new ArgumentNullException("skeletonData"); using (var materialCache = new AtlasMaterialCache()) { - var attachmentBuffer = new List(); + var entryBuffer = new List(); var slotsItems = skeletonData.Slots.Items; for (int slotIndex = 0, slotCount = skeletonData.Slots.Count; slotIndex < slotCount; slotIndex++) { var slot = slotsItems[slotIndex]; if (slot.blendMode == BlendMode.Normal) continue; if (!includeAdditiveSlots && slot.blendMode == BlendMode.Additive) continue; - attachmentBuffer.Clear(); - foreach (var skin in skeletonData.Skins) { - var entries = skin.GetEntries(slotIndex); - foreach (var entry in entries) - attachmentBuffer.Add(entry.Attachment); - } + entryBuffer.Clear(); + foreach (var skin in skeletonData.Skins) + skin.GetAttachments(slotIndex, entryBuffer); Material templateMaterial = null; switch (slot.blendMode) { @@ -80,8 +77,8 @@ namespace Spine.Unity { } if (templateMaterial == null) continue; - foreach (var attachment in attachmentBuffer) { - var renderableAttachment = attachment as IHasRendererObject; + foreach (var entry in entryBuffer) { + var renderableAttachment = entry.Attachment as IHasRendererObject; if (renderableAttachment != null) { renderableAttachment.RendererObject = materialCache.CloneAtlasRegionWithMaterial((AtlasRegion)renderableAttachment.RendererObject, templateMaterial); } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/AttachmentTools/AttachmentTools.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/AttachmentTools/AttachmentTools.cs index 5dedc2491..231a60817 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/AttachmentTools/AttachmentTools.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/AttachmentTools/AttachmentTools.cs @@ -29,6 +29,7 @@ using UnityEngine; using System.Collections.Generic; +using System.Collections; namespace Spine.Unity.Modules.AttachmentTools { public static class AttachmentRegionExtensions { @@ -503,9 +504,10 @@ namespace Spine.Unity.Modules.AttachmentTools { var texturesToPack = new List(); var originalRegions = new List(); int newRegionIndex = 0; - foreach (var skinEntry in skinAttachments) { - var originalKey = skinEntry.Key; - var originalAttachment = skinEntry.Value; + + foreach (DictionaryEntry skinEntry in skinAttachments) { + var originalKey = (Skin.SkinEntry)skinEntry.Key; + var originalAttachment = (Attachment)skinEntry.Value; Attachment newAttachment; if (IsRenderable(originalAttachment)) { @@ -793,7 +795,7 @@ namespace Spine.Unity.Modules.AttachmentTools { var newSkin = new Skin(original.name + " clone"); var newSkinAttachments = newSkin.Attachments; - foreach (var a in original.Attachments) + foreach (DictionaryEntry a in original.Attachments) newSkinAttachments[a.Key] = a.Value; return newSkin; @@ -848,21 +850,21 @@ namespace Spine.Unity.Modules.AttachmentTools { if (cloneAttachments) { if (overwrite) { - foreach (var e in sourceAttachments) - destinationAttachments[e.Key] = e.Value.GetClone(cloneMeshesAsLinked); + foreach (DictionaryEntry e in sourceAttachments) + destinationAttachments[e.Key] = ((Attachment)e.Value).GetClone(cloneMeshesAsLinked); } else { - foreach (var e in sourceAttachments) { - if (destinationAttachments.ContainsKey(e.Key)) continue; - destinationAttachments.Add(e.Key, e.Value.GetClone(cloneMeshesAsLinked)); + foreach (DictionaryEntry e in sourceAttachments) { + if (destinationAttachments.Contains(e.Key)) continue; + destinationAttachments.Add(e.Key, ((Attachment)e.Value).GetClone(cloneMeshesAsLinked)); } } } else { if (overwrite) { - foreach (var e in sourceAttachments) + foreach (DictionaryEntry e in sourceAttachments) destinationAttachments[e.Key] = e.Value; } else { - foreach (var e in sourceAttachments) { - if (destinationAttachments.ContainsKey(e.Key)) continue; + foreach (DictionaryEntry e in sourceAttachments) { + if (destinationAttachments.Contains(e.Key)) continue; destinationAttachments.Add(e.Key, e.Value); } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/BoundingBoxFollower/BoundingBoxFollower.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/BoundingBoxFollower/BoundingBoxFollower.cs index daaa4de1d..ffad1da27 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/BoundingBoxFollower/BoundingBoxFollower.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/BoundingBoxFollower/BoundingBoxFollower.cs @@ -139,13 +139,11 @@ namespace Spine.Unity { void AddSkin (Skin skin, int slotIndex) { if (skin == null) return; - var attachmentNames = new List(); - var entries = skin.GetEntries(slotIndex); - foreach (var entry in entries) - attachmentNames.Add(entry.Name); - - foreach (var skinKey in attachmentNames) { - var attachment = skin.GetAttachment(slotIndex, skinKey); + var skinEntries = new List(); + skin.GetAttachments(slotIndex, skinEntries); + + foreach (var entry in skinEntries) { + var attachment = skin.GetAttachment(slotIndex, entry.Name); var boundingBoxAttachment = attachment as BoundingBoxAttachment; if (BoundingBoxFollower.DebugMessages && attachment != null && boundingBoxAttachment == null) @@ -159,7 +157,7 @@ namespace Spine.Unity { bbCollider.hideFlags = HideFlags.NotEditable; bbCollider.isTrigger = IsTrigger; colliderTable.Add(boundingBoxAttachment, bbCollider); - nameTable.Add(boundingBoxAttachment, skinKey); + nameTable.Add(boundingBoxAttachment, entry.Name); } } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Ragdoll/SkeletonRagdoll.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Ragdoll/SkeletonRagdoll.cs index ed1676687..2336273f3 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Ragdoll/SkeletonRagdoll.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Ragdoll/SkeletonRagdoll.cs @@ -365,17 +365,15 @@ namespace Spine.Unity.Modules { GameObject go = t.gameObject; var skin = skeleton.Skin ?? skeleton.Data.DefaultSkin; - var attachments = new List(); + var skinEntries = new List(); foreach (Slot s in skeleton.Slots) { if (s.Bone == b) { - var entries = skin.GetEntries(skeleton.Slots.IndexOf(s)); - foreach (var entry in entries) - attachments.Add(entry.Attachment); - - foreach (var a in attachments) { - var bbAttachment = a as BoundingBoxAttachment; + skin.GetAttachments(skeleton.Slots.IndexOf(s), skinEntries); + + foreach (var entry in skinEntries) { + var bbAttachment = entry.Attachment as BoundingBoxAttachment; if (bbAttachment != null) { - if (!a.Name.ToLower().Contains(AttachmentNameMarker)) + if (!entry.Name.ToLower().Contains(AttachmentNameMarker)) continue; var bbCollider = go.AddComponent(); diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Ragdoll/SkeletonRagdoll2D.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Ragdoll/SkeletonRagdoll2D.cs index 35f067093..88949f7ed 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Ragdoll/SkeletonRagdoll2D.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/Ragdoll/SkeletonRagdoll2D.cs @@ -360,18 +360,16 @@ namespace Spine.Unity.Modules { var colliders = new List(); var skin = skeleton.Skin ?? skeleton.Data.DefaultSkin; - var attachments = new List(); + var skinEntries = new List(); foreach (Slot slot in skeleton.Slots) { if (slot.bone == b) { - var entries = skin.GetEntries(skeleton.Slots.IndexOf(slot)); - foreach (var entry in entries) - attachments.Add(entry.Attachment); + skin.GetAttachments(skeleton.Slots.IndexOf(slot), skinEntries); bool bbAttachmentAdded = false; - foreach (var a in attachments) { - var bbAttachment = a as BoundingBoxAttachment; + foreach (var entry in skinEntries) { + var bbAttachment = entry.Attachment as BoundingBoxAttachment; if (bbAttachment != null) { - if (!a.Name.ToLower().Contains(AttachmentNameMarker)) + if (!entry.Name.ToLower().Contains(AttachmentNameMarker)) continue; bbAttachmentAdded = true;