diff --git a/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs b/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs index 7a4e17fc2..8a697aab2 100644 --- a/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs +++ b/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs @@ -654,6 +654,8 @@ namespace Spine.Unity.Modules.AttachmentTools { } public static class SkinExtensions { + + #region Skeleton Skin Extensions /// /// Convenience method for duplicating a skeleton's current active skin so changes to it will not affect other skeleton instances. . public static Skin UnshareSkin (this Skeleton skeleton, bool includeDefaultSkin, bool unshareAttachments, AnimationState state = null) { @@ -684,6 +686,7 @@ namespace Spine.Unity.Modules.AttachmentTools { return newSkin; } + #endregion /// /// Gets a shallow copy of the skin. The cloned skin's attachments are shared with the original skin. @@ -697,6 +700,36 @@ namespace Spine.Unity.Modules.AttachmentTools { return newSkin; } + /// Adds an attachment to the skin for the specified slot index and name. If the name already exists for the slot, the previous value is replaced. + public static void SetAttachment (this Skin skin, string slotName, string keyName, Attachment attachment, Skeleton skeleton) { + int slotIndex = skeleton.FindSlotIndex(slotName); + if (skeleton == null) throw new System.ArgumentNullException("skeleton", "skeleton cannot be null."); + if (slotIndex == -1) throw new System.ArgumentException(string.Format("Slot '{0}' does not exist in skeleton.", slotName), "slotName"); + skin.AddAttachment(slotIndex, keyName, attachment); + } + + /// Adds an attachment to the skin for the specified slot index and name. If the name already exists for the slot, the previous value is replaced. + public static void SetAttachment (this Skin skin, int slotIndex, string keyName, Attachment attachment) { + skin.AddAttachment(slotIndex, keyName, attachment); + } + + /// Removes the attachment. Returns true if the element is successfully found and removed; otherwise, false. + public static bool RemoveAttachment (this Skin skin, string slotName, string keyName, Skeleton skeleton) { + int slotIndex = skeleton.FindSlotIndex(slotName); + if (skeleton == null) throw new System.ArgumentNullException("skeleton", "skeleton cannot be null."); + if (slotIndex == -1) throw new System.ArgumentException(string.Format("Slot '{0}' does not exist in skeleton.", slotName), "slotName"); + return skin.RemoveAttachment(slotIndex, keyName); + } + + /// Removes the attachment. Returns true if the element is successfully found and removed; otherwise, false. + public static bool RemoveAttachment (this Skin skin, int slotIndex, string keyName) { + return skin.Attachments.Remove(new Skin.AttachmentKeyTuple(slotIndex, keyName)); + } + + public static void Append (this Skin destination, Skin source, bool overwrite, bool cloneAttachments, bool cloneMeshesAsLinked = true) { + source.CopyTo(destination, overwrite, cloneAttachments, cloneMeshesAsLinked); + } + public static void CopyTo (this Skin source, Skin destination, bool overwrite, bool cloneAttachments, bool cloneMeshesAsLinked = true) { var sourceAttachments = source.Attachments; var destinationAttachments = destination.Attachments;