From 7580db5701a2dbff727e6d046b9f07b49c5640a3 Mon Sep 17 00:00:00 2001 From: pharan Date: Fri, 10 Aug 2018 23:51:46 +0800 Subject: [PATCH] [unity] SetSlotAttachmentsToSetupPose extension. --- .../Spine/Runtime/spine-unity/SkeletonExtensions.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonExtensions.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonExtensions.cs index 6044c6d55..63c1a52b7 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonExtensions.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonExtensions.cs @@ -543,6 +543,16 @@ namespace Spine { System.Array.Copy(slotsItems, drawOrder.Items, n); } + /// Resets all the slots on the skeleton to their Setup Pose attachments but does not reset slot colors. + public static void SetSlotAttachmentsToSetupPose (this Skeleton skeleton) { + var slotsItems = skeleton.slots.Items; + for (int i = 0; i < skeleton.slots.Count; i++) { + Slot slot = slotsItems[i]; + string attachmentName = slot.data.attachmentName; + slot.Attachment = string.IsNullOrEmpty(attachmentName) ? null : skeleton.GetAttachment(i, attachmentName); + } + } + /// Resets the color of a slot to Setup Pose value. public static void SetColorToSetupPose (this Slot slot) { slot.r = slot.data.r; @@ -563,7 +573,7 @@ namespace Spine { /// Resets the attachment of slot at a given slotIndex to setup pose. This is faster than Slot.SetAttachmentToSetupPose. public static void SetSlotAttachmentToSetupPose (this Skeleton skeleton, int slotIndex) { var slot = skeleton.slots.Items[slotIndex]; - var attachmentName = slot.data.attachmentName; + string attachmentName = slot.data.attachmentName; if (string.IsNullOrEmpty(attachmentName)) { slot.Attachment = null; } else {