[csharp] Ported skin API changes, see #841.

This commit is contained in:
Harald Csaszar 2019-05-16 18:52:20 +02:00
parent a19331f843
commit a009c35b82
26 changed files with 278 additions and 95 deletions

View File

@ -41,6 +41,9 @@ namespace Spine {
override public string ToString () { override public string ToString () {
return Name; return Name;
} }
///<summary>Returns a copy of the attachment.</summary>
public abstract Attachment Copy ();
} }
public interface IHasRendererObject { public interface IHasRendererObject {

View File

@ -35,5 +35,11 @@ namespace Spine {
public BoundingBoxAttachment (string name) public BoundingBoxAttachment (string name)
: base(name) { : base(name) {
} }
public override Attachment Copy () {
BoundingBoxAttachment copy = new BoundingBoxAttachment(this.Name);
CopyTo(copy);
return copy;
}
} }
} }

View File

@ -37,5 +37,12 @@ namespace Spine {
public ClippingAttachment(string name) : base(name) { public ClippingAttachment(string name) : base(name) {
} }
public override Attachment Copy () {
ClippingAttachment copy = new ClippingAttachment(this.Name);
CopyTo(copy);
copy.endSlot = endSlot;
return copy;
}
} }
} }

View File

@ -155,5 +155,42 @@ namespace Spine {
override public bool ApplyDeform (VertexAttachment sourceAttachment) { override public bool ApplyDeform (VertexAttachment sourceAttachment) {
return this == sourceAttachment || (inheritDeform && parentMesh == sourceAttachment); return this == sourceAttachment || (inheritDeform && parentMesh == sourceAttachment);
} }
public override Attachment Copy () {
MeshAttachment copy = new MeshAttachment(this.Name);
copy.regionOffsetX = regionOffsetX;
copy.regionOffsetY = regionOffsetY;
copy.regionWidth = regionWidth;
copy.regionHeight = regionHeight;
copy.regionOriginalWidth = regionOriginalWidth;
copy.regionOriginalHeight = regionOriginalHeight;
copy.Path = Path;
if (parentMesh == null) {
CopyTo(copy);
copy.regionUVs = new float[regionUVs.Length];
Array.Copy(regionUVs, 0, copy.regionUVs, 0, regionUVs.Length);
copy.uvs = new float[uvs.Length];
Array.Copy(uvs, 0, copy.uvs, 0, uvs.Length);
copy.triangles = new int[triangles.Length];
Array.Copy(triangles, 0, copy.triangles, 0, triangles.Length);
copy.HullLength = HullLength;
copy.inheritDeform = inheritDeform;
// Nonessential.
if (Edges != null) {
copy.Edges = new int[Edges.Length];
Array.Copy(Edges, 0, copy.Edges, 0, Edges.Length);
}
copy.Width = Width;
copy.Height = Height;
}
else
copy.ParentMesh = parentMesh;
return copy;
}
} }
} }

View File

@ -43,5 +43,15 @@ namespace Spine {
public PathAttachment (String name) public PathAttachment (String name)
: base(name) { : base(name) {
} }
public override Attachment Copy () {
PathAttachment copy = new PathAttachment(this.Name);
CopyTo(copy);
copy.lengths = new float[lengths.Length];
Array.Copy(lengths, 0, copy.lengths, 0, lengths.Length);
copy.closed = closed;
copy.constantSpeed = constantSpeed;
return copy;
}
} }
} }

View File

@ -55,5 +55,13 @@ namespace Spine {
float iy = cos * bone.c + sin * bone.d; float iy = cos * bone.c + sin * bone.d;
return MathUtils.Atan2(iy, ix) * MathUtils.RadDeg; return MathUtils.Atan2(iy, ix) * MathUtils.RadDeg;
} }
public override Attachment Copy () {
PointAttachment copy = new PointAttachment(this.Name);
copy.x = x;
copy.y = y;
copy.rotation = rotation;
return copy;
}
} }
} }

View File

@ -178,5 +178,26 @@ namespace Spine {
worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy;
//offset += stride; //offset += stride;
} }
public override Attachment Copy () {
RegionAttachment copy = new RegionAttachment(this.Name);
copy.regionOffsetX = regionOffsetX;
copy.regionOffsetY = regionOffsetY;
copy.regionWidth = regionWidth;
copy.regionHeight = regionHeight;
copy.regionOriginalWidth = regionOriginalWidth;
copy.regionOriginalHeight = regionOriginalHeight;
copy.Path = Path;
copy.x = x;
copy.y = y;
copy.scaleX = scaleX;
copy.scaleY = scaleY;
copy.rotation = rotation;
copy.width = width;
copy.height = height;
Array.Copy(uvs, 0, copy.uvs, 0, uvs.Length);
Array.Copy(offset, 0, copy.offset, 0, offset.Length);
return copy;
}
} }
} }

View File

@ -32,7 +32,7 @@ using System;
namespace Spine { namespace Spine {
/// <summary>>An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's /// <summary>>An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's
/// <see cref="Slot.Deform"/>.</summary> /// <see cref="Slot.Deform"/>.</summary>
public class VertexAttachment : Attachment { public abstract class VertexAttachment : Attachment {
static int nextID = 0; static int nextID = 0;
static readonly Object nextIdLock = new Object(); static readonly Object nextIdLock = new Object();
@ -132,5 +132,25 @@ namespace Spine {
virtual public bool ApplyDeform (VertexAttachment sourceAttachment) { virtual public bool ApplyDeform (VertexAttachment sourceAttachment) {
return this == sourceAttachment; return this == sourceAttachment;
} }
///<summary>Internal method used by VertexAttachment subclasses to copy basic data. Does not copy id (generated) and name (set on
/// construction).</summary>
internal void CopyTo (VertexAttachment attachment) {
if (bones != null) {
attachment.bones = new int[bones.Length];
Array.Copy(bones, 0, attachment.bones, 0, bones.Length);
}
else
attachment.bones = null;
if (vertices != null) {
attachment.vertices = new float[vertices.Length];
Array.Copy(vertices, 0, attachment.vertices, 0, vertices.Length);
}
else
attachment.vertices = null;
attachment.worldVerticesLength = worldVerticesLength;
}
} }
} }

View File

@ -235,8 +235,8 @@ namespace Spine {
} }
private void SortPathConstraintAttachment (Skin skin, int slotIndex, Bone slotBone) { private void SortPathConstraintAttachment (Skin skin, int slotIndex, Bone slotBone) {
foreach (var entry in skin.Attachments) foreach (var entry in skin.Attachments.Keys)
if (entry.Key.slotIndex == slotIndex) SortPathConstraintAttachment(entry.Value, slotBone); if (entry.SlotIndex == slotIndex) SortPathConstraintAttachment(entry.Attachment, slotBone);
} }
private void SortPathConstraintAttachment (Attachment attachment, Bone slotBone) { private void SortPathConstraintAttachment (Attachment attachment, Bone slotBone) {

View File

@ -321,7 +321,7 @@ namespace Spine {
for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++) { for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++) {
String name = ReadString(input); String name = ReadString(input);
Attachment attachment = ReadAttachment(input, skeletonData, skin, slotIndex, name, nonessential); Attachment attachment = ReadAttachment(input, skeletonData, skin, slotIndex, name, nonessential);
if (attachment != null) skin.AddAttachment(slotIndex, name, attachment); if (attachment != null) skin.SetAttachment(slotIndex, name, attachment);
} }
} }
return skin; return skin;

View File

@ -266,7 +266,7 @@ namespace Spine {
foreach (KeyValuePair<string, Object> entry in ((Dictionary<string, Object>)slotEntry.Value)) { foreach (KeyValuePair<string, Object> entry in ((Dictionary<string, Object>)slotEntry.Value)) {
try { try {
Attachment attachment = ReadAttachment((Dictionary<string, Object>)entry.Value, skin, slotIndex, entry.Key, skeletonData); Attachment attachment = ReadAttachment((Dictionary<string, Object>)entry.Value, skin, slotIndex, entry.Key, skeletonData);
if (attachment != null) skin.AddAttachment(slotIndex, entry.Key, attachment); if (attachment != null) skin.SetAttachment(slotIndex, entry.Key, attachment);
} catch (Exception e) { } catch (Exception e) {
throw new Exception("Error reading attachment: " + entry.Key + ", skin: " + skin, e); throw new Exception("Error reading attachment: " + entry.Key + ", skin: " + skin, e);
} }

View File

@ -37,53 +37,62 @@ namespace Spine {
/// </summary> /// </summary>
public class Skin { public class Skin {
internal string name; internal string name;
private Dictionary<AttachmentKeyTuple, Attachment> attachments = private Dictionary<SkinEntry, Attachment> attachments =
new Dictionary<AttachmentKeyTuple, Attachment>(AttachmentKeyTupleComparer.Instance); new Dictionary<SkinEntry, Attachment>(SkinEntryComparer.Instance);
public string Name { get { return name; } } public string Name { get { return name; } }
public Dictionary<AttachmentKeyTuple, Attachment> Attachments { get { return attachments; } } public Dictionary<SkinEntry, Attachment> Attachments { get { return attachments; } }
public Skin (string name) { public Skin (string name) {
if (name == null) throw new ArgumentNullException("name", "name cannot be null."); if (name == null) throw new ArgumentNullException("name", "name cannot be null.");
this.name = name; this.name = name;
} }
/// <summary>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.</summary> /// <summary>Adds an attachment to the skin for the specified slot index and name.
public void AddAttachment (int slotIndex, string name, Attachment attachment) { /// If the name already exists for the slot, the previous value is replaced.</summary>
public void SetAttachment (int slotIndex, string name, Attachment attachment) {
if (attachment == null) throw new ArgumentNullException("attachment", "attachment cannot be null."); if (attachment == null) throw new ArgumentNullException("attachment", "attachment cannot be null.");
attachments[new AttachmentKeyTuple(slotIndex, name)] = attachment; if (slotIndex < 0) throw new ArgumentNullException("slotIndex", "slotIndex must be >= 0.");
attachments[new SkinEntry(slotIndex, name, attachment)] = attachment;
}
///<summary>Adds all attachments from the specified skin to this skin.</summary>
public void AddSkin (Skin skin) {
foreach (SkinEntry entry in skin.attachments.Keys)
SetAttachment(entry.SlotIndex, entry.Name, entry.Attachment);
} }
/// <summary>Returns the attachment for the specified slot index and name, or null.</summary> /// <summary>Returns the attachment for the specified slot index and name, or null.</summary>
/// <returns>May be null.</returns> /// <returns>May be null.</returns>
public Attachment GetAttachment (int slotIndex, string name) { public Attachment GetAttachment (int slotIndex, string name) {
Attachment attachment; Attachment attachment;
attachments.TryGetValue(new AttachmentKeyTuple(slotIndex, name), out attachment); var lookup = new SkinEntry(slotIndex, name, null);
attachments.TryGetValue(lookup, out attachment);
return attachment; return attachment;
} }
/// <summary> Removes the attachment in the skin for the specified slot index and name, if any.</summary> /// <summary> Removes the attachment in the skin for the specified slot index and name, if any.</summary>
public void RemoveAttachment (int slotIndex, string name) { public void RemoveAttachment (int slotIndex, string name) {
if (slotIndex < 0) throw new ArgumentOutOfRangeException("slotIndex", "slotIndex must be >= 0"); if (slotIndex < 0) throw new ArgumentOutOfRangeException("slotIndex", "slotIndex must be >= 0");
attachments.Remove(new AttachmentKeyTuple(slotIndex, name)); var lookup = new SkinEntry(slotIndex, name, null);
attachments.Remove(lookup);
} }
/// <summary>Finds the skin keys for a given slot. The results are added to the passed List(names).</summary> ///<summary>Returns all attachments contained in this skin.</summary>
/// <param name="slotIndex">The target slotIndex. To find the slot index, use <see cref="Spine.Skeleton.FindSlotIndex"/> or <see cref="Spine.SkeletonData.FindSlotIndex"/> public List<SkinEntry> GetAttachments () {
/// <param name="names">Found skin key names will be added to this list.</param> List<SkinEntry> entries = new List<SkinEntry>();
public void FindNamesForSlot (int slotIndex, List<string> names) { foreach (SkinEntry entry in this.attachments.Keys)
if (names == null) throw new ArgumentNullException("names", "names cannot be null."); entries.Add(entry);
foreach (AttachmentKeyTuple key in attachments.Keys) return entries;
if (key.slotIndex == slotIndex) names.Add(key.name);
} }
/// <summary>Finds the attachments for a given slot. The results are added to the passed List(Attachment).</summary> /// <summary>Returns all <see cref="SkinEntry"/> instances for the given slot contained in this skin.</summary>
/// <param name="slotIndex">The target slotIndex. To find the slot index, use <see cref="Spine.Skeleton.FindSlotIndex"/> or <see cref="Spine.SkeletonData.FindSlotIndex"/> /// <param name="slotIndex">The target slotIndex. To find the slot index, use <see cref="Spine.Skeleton.FindSlotIndex"/> or <see cref="Spine.SkeletonData.FindSlotIndex"/>
/// <param name="attachments">Found Attachments will be added to this list.</param> public List<SkinEntry> GetEntries (int slotIndex) {
public void FindAttachmentsForSlot (int slotIndex, List<Attachment> attachments) { List<SkinEntry> entries = new List<SkinEntry>();
if (attachments == null) throw new ArgumentNullException("attachments", "attachments cannot be null."); foreach (SkinEntry entry in this.attachments.Keys)
foreach (KeyValuePair<AttachmentKeyTuple, Attachment> entry in this.attachments) if (entry.SlotIndex == slotIndex) entries.Add(entry);
if (entry.Key.slotIndex == slotIndex) attachments.Add(entry.Value); return entries;
} }
override public string ToString () { override public string ToString () {
@ -92,38 +101,61 @@ namespace Spine {
/// <summary>Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached.</summary> /// <summary>Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached.</summary>
internal void AttachAll (Skeleton skeleton, Skin oldSkin) { internal void AttachAll (Skeleton skeleton, Skin oldSkin) {
foreach (KeyValuePair<AttachmentKeyTuple, Attachment> entry in oldSkin.attachments) { foreach (SkinEntry entry in oldSkin.attachments.Keys) {
int slotIndex = entry.Key.slotIndex; int slotIndex = entry.SlotIndex;
Slot slot = skeleton.slots.Items[slotIndex]; Slot slot = skeleton.slots.Items[slotIndex];
if (slot.Attachment == entry.Value) { if (slot.Attachment == entry.Attachment) {
Attachment attachment = GetAttachment(slotIndex, entry.Key.name); Attachment attachment = GetAttachment(slotIndex, entry.Name);
if (attachment != null) slot.Attachment = attachment; if (attachment != null) slot.Attachment = attachment;
} }
} }
} }
public struct AttachmentKeyTuple { /// <summary>Stores an entry in the skin consisting of the slot index, name, and attachment.</summary>
public readonly int slotIndex; public struct SkinEntry {
public readonly string name; private readonly int slotIndex;
internal readonly int nameHashCode; private readonly string name;
private readonly Attachment attachment;
internal readonly int hashCode;
public AttachmentKeyTuple (int slotIndex, string name) { public SkinEntry (int slotIndex, string name, Attachment attachment) {
this.slotIndex = slotIndex; this.slotIndex = slotIndex;
this.name = name; this.name = name;
nameHashCode = this.name.GetHashCode(); this.attachment = attachment;
this.hashCode = this.name.GetHashCode() + this.slotIndex * 37;
}
public int SlotIndex {
get {
return slotIndex;
}
}
public String Name {
get {
return name;
}
}
public Attachment Attachment {
get {
return attachment;
}
} }
} }
// Avoids boxing in the dictionary. // Avoids boxing in the dictionary.
class AttachmentKeyTupleComparer : IEqualityComparer<AttachmentKeyTuple> { class SkinEntryComparer : IEqualityComparer<SkinEntry> {
internal static readonly AttachmentKeyTupleComparer Instance = new AttachmentKeyTupleComparer(); internal static readonly SkinEntryComparer Instance = new SkinEntryComparer();
bool IEqualityComparer<AttachmentKeyTuple>.Equals (AttachmentKeyTuple o1, AttachmentKeyTuple o2) { bool IEqualityComparer<SkinEntry>.Equals (SkinEntry o1, SkinEntry o2) {
return o1.slotIndex == o2.slotIndex && o1.nameHashCode == o2.nameHashCode && string.Equals(o1.name, o2.name, StringComparison.Ordinal); if (o1.SlotIndex != o2.SlotIndex) return false;
if (!string.Equals(o1.Name, o2.Name, StringComparison.Ordinal)) return false;
return true;
} }
int IEqualityComparer<AttachmentKeyTuple>.GetHashCode (AttachmentKeyTuple o) { int IEqualityComparer<SkinEntry>.GetHashCode (SkinEntry o) {
return o.slotIndex; return o.Name.GetHashCode() + o.SlotIndex * 37;
} }
} }
} }

View File

@ -60,7 +60,7 @@ namespace Spine.Unity.Examples {
} }
public void Equip (int slotIndex, string attachmentName, Attachment attachment) { public void Equip (int slotIndex, string attachmentName, Attachment attachment) {
equipsSkin.AddAttachment(slotIndex, attachmentName, attachment); equipsSkin.SetAttachment(slotIndex, attachmentName, attachment);
skeletonAnimation.Skeleton.SetSkin(equipsSkin); skeletonAnimation.Skeleton.SetSkin(equipsSkin);
RefreshSkeletonAttachments(); RefreshSkeletonAttachments();
} }

View File

@ -170,7 +170,7 @@ namespace Spine.Unity.Examples {
if (skinName != "") if (skinName != "")
skin = skeletonData.FindSkin(skinName); skin = skeletonData.FindSkin(skinName);
skin.AddAttachment(slotIndex, att.Name, att); skin.SetAttachment(slotIndex, att.Name, att);
return att; return att;
} }

View File

@ -114,7 +114,7 @@ namespace Spine.Unity.Editor {
var attachment = skinEntry.Value as PointAttachment; var attachment = skinEntry.Value as PointAttachment;
if (attachment != null) { if (attachment != null) {
var skinKey = skinEntry.Key; var skinKey = skinEntry.Key;
var slot = skeleton.Slots.Items[skinKey.slotIndex]; var slot = skeleton.Slots.Items[skinKey.SlotIndex];
DrawPointAttachmentWithLabel(attachment, slot.Bone, transform); DrawPointAttachmentWithLabel(attachment, slot.Bone, transform);
} }
} }

View File

@ -229,7 +229,9 @@ namespace Spine.Unity.Editor {
for (int i = 0; i < skinCount; i++) { for (int i = 0; i < skinCount; i++) {
var skin = skins.Items[i]; var skin = skins.Items[i];
List<string> temp = new List<string>(); List<string> temp = new List<string>();
skin.FindNamesForSlot(s, temp); var entries = skin.GetEntries(s);
foreach (var entry in entries)
temp.Add(entry.Name);
foreach (string str in temp) { foreach (string str in temp) {
if (!attachmentNames.Contains(str)) if (!attachmentNames.Contains(str))
attachmentNames.Add(str); attachmentNames.Add(str);
@ -342,12 +344,18 @@ namespace Spine.Unity.Editor {
List<Attachment> attachments = new List<Attachment>(); List<Attachment> attachments = new List<Attachment>();
List<string> attachmentNames = new List<string>(); List<string> attachmentNames = new List<string>();
skin.FindAttachmentsForSlot(i, attachments); var entries = skin.GetEntries(i);
skin.FindNamesForSlot(i, attachmentNames); foreach (var entry in entries) {
attachments.Add(entry.Attachment);
attachmentNames.Add(entry.Name);
}
if (skin != skeletonData.DefaultSkin) { if (skin != skeletonData.DefaultSkin) {
skeletonData.DefaultSkin.FindAttachmentsForSlot(i, attachments); entries = skeletonData.DefaultSkin.GetEntries(i);
skeletonData.DefaultSkin.FindNamesForSlot(i, attachmentNames); foreach (var entry in entries) {
attachments.Add(entry.Attachment);
attachmentNames.Add(entry.Name);
}
} }
for (int a = 0; a < attachments.Count; a++) { for (int a = 0; a < attachments.Count; a++) {

View File

@ -498,15 +498,25 @@ namespace Spine.Unity.Editor {
using (new SpineInspectorUtility.IndentScope()) { using (new SpineInspectorUtility.IndentScope()) {
{ {
skin.FindNamesForSlot(i, slotAttachmentNames); var entries = skin.GetEntries(i);
skin.FindAttachmentsForSlot(i, slotAttachments); foreach (var entry in entries) {
slotAttachments.Add(entry.Attachment);
slotAttachmentNames.Add(entry.Name);
}
if (skin != defaultSkin) { if (skin != defaultSkin) {
defaultSkin.FindNamesForSlot(i, defaultSkinAttachmentNames); entries = defaultSkin.GetEntries(i);
defaultSkin.FindNamesForSlot(i, slotAttachmentNames); foreach (var entry in entries) {
defaultSkin.FindAttachmentsForSlot(i, slotAttachments); slotAttachments.Add(entry.Attachment);
slotAttachmentNames.Add(entry.Name);
defaultSkinAttachmentNames.Add(entry.Name);
}
} else { } else {
defaultSkin.FindNamesForSlot(i, defaultSkinAttachmentNames); entries = defaultSkin.GetEntries(i);
foreach (var entry in entries) {
defaultSkinAttachmentNames.Add(entry.Name);
}
} }
} }

View File

@ -574,8 +574,17 @@ namespace Spine.Unity.Editor {
for (int i = skeleton.Slots.Count - 1; i >= 0; i--) { for (int i = skeleton.Slots.Count - 1; i >= 0; i--) {
var attachments = new List<Attachment>(); var attachments = new List<Attachment>();
attachmentTable.Add(skeleton.Slots.Items[i], attachments); attachmentTable.Add(skeleton.Slots.Items[i], attachments);
skin.FindAttachmentsForSlot(i, attachments); // Add skin attachments. // Add skin attachments.
if (notDefaultSkin) defaultSkin.FindAttachmentsForSlot(i, attachments); // Add default skin attachments. var entries = skin.GetEntries(i);
foreach (var entry in entries) {
attachments.Add(entry.Attachment);
}
if (notDefaultSkin) { // Add default skin attachments.
entries = defaultSkin.GetEntries(i);
foreach (var entry in entries) {
attachments.Add(entry.Attachment);
}
}
} }
activeSkin = skeleton.Skin; activeSkin = skeleton.Skin;

View File

@ -184,8 +184,12 @@ namespace Spine.Unity.Editor {
if (targetAttribute.containsBoundingBoxes) { if (targetAttribute.containsBoundingBoxes) {
int slotIndex = i; int slotIndex = i;
var attachments = new List<Attachment>(); var attachments = new List<Attachment>();
foreach (var skin in data.Skins) foreach (var skin in data.Skins) {
skin.FindAttachmentsForSlot(slotIndex, attachments); var entries = skin.GetEntries(slotIndex);
foreach (var entry in entries) {
attachments.Add(entry.Attachment);
}
}
bool hasBoundingBox = false; bool hasBoundingBox = false;
foreach (var attachment in attachments) { foreach (var attachment in attachments) {
@ -470,10 +474,19 @@ namespace Spine.Unity.Editor {
attachmentNames.Clear(); attachmentNames.Clear();
placeholderNames.Clear(); placeholderNames.Clear();
skin.FindNamesForSlot(i, attachmentNames); var entries = skin.GetEntries(i);
foreach (var entry in entries) {
attachmentNames.Add(entry.Name);
}
if (skin != defaultSkin) { if (skin != defaultSkin) {
defaultSkin.FindNamesForSlot(i, attachmentNames); foreach (var entry in entries) {
skin.FindNamesForSlot(i, placeholderNames); placeholderNames.Add(entry.Name);
}
entries = defaultSkin.GetEntries(i);
foreach (var entry in entries) {
attachmentNames.Add(entry.Name);
}
} }
for (int a = 0; a < attachmentNames.Count; a++) { for (int a = 0; a < attachmentNames.Count; a++) {

View File

@ -81,7 +81,11 @@ namespace Spine.Unity.Editor {
Slot slot = skeletonUtility.skeletonRenderer.skeleton.Slots.Items[i]; Slot slot = skeletonUtility.skeletonRenderer.skeleton.Slots.Items[i];
if (slot.Bone == utilityBone.bone) { if (slot.Bone == utilityBone.bone) {
var slotAttachments = new List<Attachment>(); var slotAttachments = new List<Attachment>();
skin.FindAttachmentsForSlot(skeleton.FindSlotIndex(slot.Data.Name), slotAttachments); var entries = skin.GetEntries(skeleton.FindSlotIndex(slot.Data.Name));
foreach (var entry in entries) {
slotAttachments.Add(entry.Attachment);
}
var boundingBoxes = new List<BoundingBoxAttachment>(); var boundingBoxes = new List<BoundingBoxAttachment>();
foreach (var att in slotAttachments) { foreach (var att in slotAttachments) {
var boundingBoxAttachment = att as BoundingBoxAttachment; var boundingBoxAttachment = att as BoundingBoxAttachment;

View File

@ -54,14 +54,17 @@ namespace Spine.Unity {
using (var materialCache = new AtlasMaterialCache()) { using (var materialCache = new AtlasMaterialCache()) {
var attachmentBuffer = new List<Attachment>(); var attachmentBuffer = new List<Attachment>();
var slotsItems = skeletonData.Slots.Items; var slotsItems = skeletonData.Slots.Items;
for (int i = 0, slotCount = skeletonData.Slots.Count; i < slotCount; i++) { for (int slotIndex = 0, slotCount = skeletonData.Slots.Count; slotIndex < slotCount; slotIndex++) {
var slot = slotsItems[i]; var slot = slotsItems[slotIndex];
if (slot.blendMode == BlendMode.Normal) continue; if (slot.blendMode == BlendMode.Normal) continue;
if (!includeAdditiveSlots && slot.blendMode == BlendMode.Additive) continue; if (!includeAdditiveSlots && slot.blendMode == BlendMode.Additive) continue;
attachmentBuffer.Clear(); attachmentBuffer.Clear();
foreach (var skin in skeletonData.Skins) foreach (var skin in skeletonData.Skins) {
skin.FindAttachmentsForSlot(i, attachmentBuffer); var entries = skin.GetEntries(slotIndex);
foreach (var entry in entries)
attachmentBuffer.Add(entry.Attachment);
}
Material templateMaterial = null; Material templateMaterial = null;
switch (slot.blendMode) { switch (slot.blendMode) {

View File

@ -523,9 +523,9 @@ namespace Spine.Unity.Modules.AttachmentTools {
} }
repackedAttachments.Add(newAttachment); repackedAttachments.Add(newAttachment);
newSkin.AddAttachment(originalKey.slotIndex, originalKey.name, newAttachment); newSkin.SetAttachment(originalKey.SlotIndex, originalKey.Name, newAttachment);
} else { } else {
newSkin.AddAttachment(originalKey.slotIndex, originalKey.name, useOriginalNonrenderables ? originalAttachment : originalAttachment.GetClone(true)); newSkin.SetAttachment(originalKey.SlotIndex, originalKey.Name, useOriginalNonrenderables ? originalAttachment : originalAttachment.GetClone(true));
} }
} }
@ -804,7 +804,7 @@ namespace Spine.Unity.Modules.AttachmentTools {
int slotIndex = skeleton.FindSlotIndex(slotName); int slotIndex = skeleton.FindSlotIndex(slotName);
if (skeleton == null) throw new System.ArgumentNullException("skeleton", "skeleton cannot be null."); 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"); if (slotIndex == -1) throw new System.ArgumentException(string.Format("Slot '{0}' does not exist in skeleton.", slotName), "slotName");
skin.AddAttachment(slotIndex, keyName, attachment); skin.SetAttachment(slotIndex, keyName, attachment);
} }
/// <summary>Adds skin items from another skin. For items that already exist, the previous values are replaced.</summary> /// <summary>Adds skin items from another skin. For items that already exist, the previous values are replaced.</summary>
@ -823,7 +823,7 @@ namespace Spine.Unity.Modules.AttachmentTools {
/// <summary>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.</summary> /// <summary>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.</summary>
public static void SetAttachment (this Skin skin, int slotIndex, string keyName, Attachment attachment) { public static void SetAttachment (this Skin skin, int slotIndex, string keyName, Attachment attachment) {
skin.AddAttachment(slotIndex, keyName, attachment); skin.SetAttachment(slotIndex, keyName, attachment);
} }
public static void RemoveAttachment (this Skin skin, string slotName, string keyName, SkeletonData skeletonData) { public static void RemoveAttachment (this Skin skin, string slotName, string keyName, SkeletonData skeletonData) {

View File

@ -140,7 +140,9 @@ namespace Spine.Unity {
void AddSkin (Skin skin, int slotIndex) { void AddSkin (Skin skin, int slotIndex) {
if (skin == null) return; if (skin == null) return;
var attachmentNames = new List<string>(); var attachmentNames = new List<string>();
skin.FindNamesForSlot(slotIndex, attachmentNames); var entries = skin.GetEntries(slotIndex);
foreach (var entry in entries)
attachmentNames.Add(entry.Name);
foreach (var skinKey in attachmentNames) { foreach (var skinKey in attachmentNames) {
var attachment = skin.GetAttachment(slotIndex, skinKey); var attachment = skin.GetAttachment(slotIndex, skinKey);

View File

@ -368,7 +368,10 @@ namespace Spine.Unity.Modules {
var attachments = new List<Attachment>(); var attachments = new List<Attachment>();
foreach (Slot s in skeleton.Slots) { foreach (Slot s in skeleton.Slots) {
if (s.Bone == b) { if (s.Bone == b) {
skin.FindAttachmentsForSlot(skeleton.Slots.IndexOf(s), attachments); var entries = skin.GetEntries(skeleton.Slots.IndexOf(s));
foreach (var entry in entries)
attachments.Add(entry.Attachment);
foreach (var a in attachments) { foreach (var a in attachments) {
var bbAttachment = a as BoundingBoxAttachment; var bbAttachment = a as BoundingBoxAttachment;
if (bbAttachment != null) { if (bbAttachment != null) {

View File

@ -363,7 +363,9 @@ namespace Spine.Unity.Modules {
var attachments = new List<Attachment>(); var attachments = new List<Attachment>();
foreach (Slot slot in skeleton.Slots) { foreach (Slot slot in skeleton.Slots) {
if (slot.bone == b) { if (slot.bone == b) {
skin.FindAttachmentsForSlot(skeleton.Slots.IndexOf(slot), attachments); var entries = skin.GetEntries(skeleton.Slots.IndexOf(slot));
foreach (var entry in entries)
attachments.Add(entry.Attachment);
bool bbAttachmentAdded = false; bool bbAttachmentAdded = false;
foreach (var a in attachments) { foreach (var a in attachments) {

View File

@ -608,21 +608,6 @@ namespace Spine {
public static void AllowImmediateQueue (this TrackEntry trackEntry) { public static void AllowImmediateQueue (this TrackEntry trackEntry) {
if (trackEntry.nextTrackLast < 0) trackEntry.nextTrackLast = 0; if (trackEntry.nextTrackLast < 0) trackEntry.nextTrackLast = 0;
} }
#endregion
#region Skins
/// <summary><see cref="Spine.Skin.FindNamesForSlot(int,List)"/></summary>
public static void FindNamesForSlot (this Skin skin, string slotName, SkeletonData skeletonData, List<string> results) {
int slotIndex = skeletonData.FindSlotIndex(slotName);
skin.FindNamesForSlot(slotIndex, results);
}
/// <summary><see cref="Spine.Skin.FindAttachmentsForSlot(int,List)"/></summary>
public static void FindAttachmentsForSlot (this Skin skin, string slotName, SkeletonData skeletonData, List<Attachment> results) {
int slotIndex = skeletonData.FindSlotIndex(slotName);
skin.FindAttachmentsForSlot(slotIndex, results);
}
#endregion #endregion
} }
} }