From 5e08751fb8a412f1b483350e116e030335c0758a Mon Sep 17 00:00:00 2001 From: John Date: Mon, 11 Jul 2016 10:13:57 +0800 Subject: [PATCH] [spine-unity] Fix BoundingBoxFollower type check. Slots that are set to an `Attachment` that is not a `BoundingBoxAttachment` will treat it as null instead of ignoring it or throwing an exception. --- .../BoundingBoxFollower.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Modules/BoundingBoxFollower/BoundingBoxFollower.cs b/spine-unity/Assets/spine-unity/Modules/BoundingBoxFollower/BoundingBoxFollower.cs index e089470b2..27933c34d 100644 --- a/spine-unity/Assets/spine-unity/Modules/BoundingBoxFollower/BoundingBoxFollower.cs +++ b/spine-unity/Assets/spine-unity/Modules/BoundingBoxFollower/BoundingBoxFollower.cs @@ -107,6 +107,12 @@ namespace Spine.Unity { foreach (var attachmentName in attachmentNames) { var attachment = skin.GetAttachment(slotIndex, attachmentName); var boundingBoxAttachment = attachment as BoundingBoxAttachment; + +#if UNITY_EDITOR + if (attachment != null && boundingBoxAttachment == null) + Debug.Log("BoundingBoxFollower tried to follow a slot that contains non-boundingbox attachments."); +#endif + if (boundingBoxAttachment != null) { var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, gameObject, true); bbCollider.enabled = false; @@ -127,7 +133,6 @@ namespace Spine.Unity { Debug.LogWarning("Bounding Box Follower tried to rebuild as a prefab."); } #endif - } void ClearColliders () { @@ -159,22 +164,31 @@ namespace Spine.Unity { return; if (slot != null && slot.Attachment != currentAttachment) - SetCurrent((BoundingBoxAttachment)slot.Attachment); + MatchAttachment(slot.Attachment); } - void SetCurrent (BoundingBoxAttachment attachment) { + /// Sets the current collider to match attachment. + /// If the attachment is not a bounding box, it will be treated as null. + void MatchAttachment (Attachment attachment) { + var bbAttachment = attachment as BoundingBoxAttachment; + +#if UNITY_EDITOR + if (attachment != null && bbAttachment == null) + Debug.LogWarning("BoundingBoxFollower tried to match a non-boundingbox attachment. It will treat it as null."); +#endif + if (currentCollider != null) currentCollider.enabled = false; - if (attachment == null) { + if (bbAttachment == null) { currentCollider = null; } else { - currentCollider = colliderTable[attachment]; + currentCollider = colliderTable[bbAttachment]; currentCollider.enabled = true; } - currentAttachment = attachment; - currentAttachmentName = currentAttachment == null ? null : attachmentNameTable[attachment]; + currentAttachment = bbAttachment; + currentAttachmentName = currentAttachment == null ? null : attachmentNameTable[bbAttachment]; } }