mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-06 10:46:53 +08:00
[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.
This commit is contained in:
parent
2fdd820da0
commit
5e08751fb8
@ -107,6 +107,12 @@ namespace Spine.Unity {
|
|||||||
foreach (var attachmentName in attachmentNames) {
|
foreach (var attachmentName in attachmentNames) {
|
||||||
var attachment = skin.GetAttachment(slotIndex, attachmentName);
|
var attachment = skin.GetAttachment(slotIndex, attachmentName);
|
||||||
var boundingBoxAttachment = attachment as BoundingBoxAttachment;
|
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) {
|
if (boundingBoxAttachment != null) {
|
||||||
var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, gameObject, true);
|
var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, gameObject, true);
|
||||||
bbCollider.enabled = false;
|
bbCollider.enabled = false;
|
||||||
@ -127,7 +133,6 @@ namespace Spine.Unity {
|
|||||||
Debug.LogWarning("Bounding Box Follower tried to rebuild as a prefab.");
|
Debug.LogWarning("Bounding Box Follower tried to rebuild as a prefab.");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearColliders () {
|
void ClearColliders () {
|
||||||
@ -159,22 +164,31 @@ namespace Spine.Unity {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (slot != null && slot.Attachment != currentAttachment)
|
if (slot != null && slot.Attachment != currentAttachment)
|
||||||
SetCurrent((BoundingBoxAttachment)slot.Attachment);
|
MatchAttachment(slot.Attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetCurrent (BoundingBoxAttachment attachment) {
|
/// <summary>Sets the current collider to match attachment.</summary>
|
||||||
|
/// <param name="attachment">If the attachment is not a bounding box, it will be treated as null.</param>
|
||||||
|
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)
|
if (currentCollider != null)
|
||||||
currentCollider.enabled = false;
|
currentCollider.enabled = false;
|
||||||
|
|
||||||
if (attachment == null) {
|
if (bbAttachment == null) {
|
||||||
currentCollider = null;
|
currentCollider = null;
|
||||||
} else {
|
} else {
|
||||||
currentCollider = colliderTable[attachment];
|
currentCollider = colliderTable[bbAttachment];
|
||||||
currentCollider.enabled = true;
|
currentCollider.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentAttachment = attachment;
|
currentAttachment = bbAttachment;
|
||||||
currentAttachmentName = currentAttachment == null ? null : attachmentNameTable[attachment];
|
currentAttachmentName = currentAttachment == null ? null : attachmentNameTable[bbAttachment];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user