[unity] Fixed null reference exceptions after changes from compile-error bugfix commit 8770e319, see #1951.

This commit is contained in:
Harald Csaszar 2021-09-15 18:25:12 +02:00
parent cd8064774f
commit 4785dcc212
4 changed files with 11 additions and 8 deletions

View File

@ -361,7 +361,8 @@ namespace Spine.Unity.Editor {
if (skeleton != null) {
for (int i = 0, n = separatorSlotNames.arraySize; i < n; i++) {
string slotName = separatorSlotNames.GetArrayElementAtIndex(i).stringValue;
int index = skeleton.Data.FindSlot(slotName).Index;
SlotData slot = skeleton.Data.FindSlot(slotName);
int index = slot != null ? slot.Index : -1;
if (index == 0 || index == lastSlot) {
hasTerminalSlot = true;
break;

View File

@ -483,7 +483,8 @@ namespace Spine.Unity.Editor {
if (skeleton != null) {
for (int i = 0, n = separatorSlotNames.arraySize; i < n; i++) {
string slotName = separatorSlotNames.GetArrayElementAtIndex(i).stringValue;
int index = skeleton.Data.FindSlot(slotName).Index;
SlotData slot = skeleton.Data.FindSlot(slotName);
int index = slot != null ? slot.Index : -1;
if (index == 0 || index == lastSlot) {
hasTerminalSlot = true;
break;

View File

@ -53,7 +53,8 @@ namespace Spine.Unity {
return null;
}
var attachment = skin.GetAttachment(skeleton.Data.FindSlot(slotName).Index, attachmentName);
Slot slot = skeleton.FindSlot(slotName);
var attachment = slot != null ? skin.GetAttachment(slot.Data.Index, attachmentName) : null;
if (attachment == null) {
Debug.LogFormat("Attachment in slot '{0}' named '{1}' not found in skin '{2}'.", slotName, attachmentName, skin.Name);
return null;
@ -61,7 +62,6 @@ namespace Spine.Unity {
var box = attachment as BoundingBoxAttachment;
if (box != null) {
var slot = skeleton.FindSlot(slotName);
return AddBoundingBoxGameObject(box.Name, box, slot, parent, isTrigger);
} else {
Debug.LogFormat("Attachment '{0}' was not a Bounding Box.", attachmentName);

View File

@ -252,10 +252,11 @@ namespace Spine.Unity {
public static Spine.Attachment GetAttachment (string attachmentPath, Spine.SkeletonData skeletonData) {
var hierarchy = SpineAttachment.GetHierarchy(attachmentPath);
return string.IsNullOrEmpty(hierarchy.name) ?
null :
skeletonData.FindSkin(hierarchy.skin).GetAttachment(
skeletonData.FindSlot(hierarchy.slot).Index, hierarchy.name);
if (string.IsNullOrEmpty(hierarchy.name)) return null;
SlotData slot = skeletonData.FindSlot(hierarchy.slot);
if (slot == null) return null;
return skeletonData.FindSkin(hierarchy.skin).GetAttachment(slot.Index, hierarchy.name);
}
public static Spine.Attachment GetAttachment (string attachmentPath, SkeletonDataAsset skeletonDataAsset) {