[csharp] Port of commit 1cef139: Improved SequenceTimeline for RegionAttachment copies, moved timelineAttachment to Attachment. Revert of temp changes f3f557, see #3040.

This commit is contained in:
Harald Csaszar 2026-03-11 09:49:41 +01:00
parent 831cf1a488
commit 5620b65028
6 changed files with 17 additions and 25 deletions

View File

@ -1898,6 +1898,9 @@ namespace Spine {
return slotIndex; return slotIndex;
} }
} }
/// <summary>The attachment for which the <see cref="SlotPose.SequenceIndex"/> will be set.</summary>
/// <seealso cref="Attachment.TimelineAttachment"/>.
public Attachment Attachment { public Attachment Attachment {
get { get {
return (Attachment)attachment; return (Attachment)attachment;
@ -1922,11 +1925,8 @@ namespace Spine {
SlotPose pose = appliedPose ? slot.applied : slot.pose; SlotPose pose = appliedPose ? slot.applied : slot.pose;
Attachment slotAttachment = pose.attachment; Attachment slotAttachment = pose.attachment;
if (slotAttachment != attachment) { IHasSequence hasSequence = slotAttachment as IHasSequence;
IHasSequence sequenceAttachment = slotAttachment as IHasSequence; if ((hasSequence == null) || slotAttachment.TimelineAttachment != attachment) return;
if ((sequenceAttachment == null)
|| sequenceAttachment.TimelineAttachment != attachment) return;
}
if (direction == MixDirection.Out) { if (direction == MixDirection.Out) {
if (blend == MixBlend.Setup) pose.SequenceIndex = -1; if (blend == MixBlend.Setup) pose.SequenceIndex = -1;
@ -1944,7 +1944,7 @@ namespace Spine {
int modeAndIndex = (int)frames[i + MODE]; int modeAndIndex = (int)frames[i + MODE];
float delay = frames[i + DELAY]; float delay = frames[i + DELAY];
int index = modeAndIndex >> 4, count = (((IHasSequence)slotAttachment).Sequence).Regions.Length; int index = modeAndIndex >> 4, count = hasSequence.Sequence.Regions.Length;
SequenceMode mode = (SequenceMode)(modeAndIndex & 0xf); SequenceMode mode = (SequenceMode)(modeAndIndex & 0xf);
if (mode != SequenceMode.Hold) { if (mode != SequenceMode.Hold) {
index += (int)((time - before) / delay + 0.0001f); index += (int)((time - before) / delay + 0.0001f);

View File

@ -33,17 +33,25 @@ namespace Spine {
/// <summary>The base class for all attachments.</summary> /// <summary>The base class for all attachments.</summary>
abstract public class Attachment { abstract public class Attachment {
internal Attachment timelineAttachment;
/// <summary>The attachment's name.</summary> /// <summary>The attachment's name.</summary>
public string Name { get; } public string Name { get; }
/// <summary>Timelines for the timeline attachment are also applied to this attachment.
/// May be null if no attachment-specific timelines should be applied.</summary>
public Attachment TimelineAttachment { get { return timelineAttachment; } set { timelineAttachment = value; } }
protected Attachment (string name) { protected Attachment (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;
timelineAttachment = this;
} }
/// <summary>Copy constructor.</summary> /// <summary>Copy constructor.</summary>
protected Attachment (Attachment other) { protected Attachment (Attachment other) {
Name = other.Name; Name = other.Name;
timelineAttachment = other.timelineAttachment;
} }
override public string ToString () { override public string ToString () {

View File

@ -42,9 +42,6 @@ namespace Spine {
void SetColor (Color32F color); void SetColor (Color32F color);
void SetColor (float r, float g, float b, float a); void SetColor (float r, float g, float b, float a);
Sequence Sequence { get; } Sequence Sequence { get; }
/// <summary>Timelines for the timeline attachment are also applied to this attachment.
/// May be null if no attachment-specific timelines should be applied.</summary>
Attachment TimelineAttachment { get; set; }
void UpdateSequence (); void UpdateSequence ();
} }
} }

View File

@ -73,11 +73,7 @@ namespace Spine {
public string Path { get { return path; } set { path = value; } } public string Path { get { return path; } set { path = value; } }
public Sequence Sequence { get { return sequence; } } public Sequence Sequence { get { return sequence; } }
Attachment IHasSequence.TimelineAttachment {
get { return timelineAttachment; }
set { timelineAttachment = (VertexAttachment)value; }
}
public MeshAttachment ParentMesh { public MeshAttachment ParentMesh {
get { return parentMesh; } get { return parentMesh; }
set { set {

View File

@ -46,7 +46,6 @@ namespace Spine {
public const int BRX = 6, BRY = 7; public const int BRX = 6, BRY = 7;
internal readonly Sequence sequence; internal readonly Sequence sequence;
internal Attachment timelineAttachment;
internal float x, y, rotation, scaleX = 1, scaleY = 1, width, height; internal float x, y, rotation, scaleX = 1, scaleY = 1, width, height;
// Color is a struct, set to protected to prevent // Color is a struct, set to protected to prevent
// Color color = slot.color; color.a = 0.5; // Color color = slot.color; color.a = 0.5;
@ -76,13 +75,11 @@ namespace Spine {
public string Path { get; set; } public string Path { get; set; }
public Sequence Sequence { get { return sequence; } } public Sequence Sequence { get { return sequence; } }
public Attachment TimelineAttachment { get { return timelineAttachment; } set { timelineAttachment = value; } }
public RegionAttachment (string name, Sequence sequence) public RegionAttachment (string name, Sequence sequence)
: base(name) { : base(name) {
if (sequence == null) throw new ArgumentException("sequence cannot be null.", "sequence"); if (sequence == null) throw new ArgumentException("sequence cannot be null.", "sequence");
this.sequence = sequence; this.sequence = sequence;
timelineAttachment = this;
} }
/// <summary>Copy constructor.</summary> /// <summary>Copy constructor.</summary>
@ -98,7 +95,6 @@ namespace Spine {
height = other.height; height = other.height;
color = other.color; color = other.color;
sequence = new Sequence(other.sequence); sequence = new Sequence(other.sequence);
timelineAttachment = other.timelineAttachment;
} }
/// <summary><para> /// <summary><para>

View File

@ -37,7 +37,6 @@ namespace Spine {
static readonly Object nextIdLock = new Object(); static readonly Object nextIdLock = new Object();
internal readonly int id; internal readonly int id;
internal VertexAttachment timelineAttachment;
internal int[] bones; internal int[] bones;
internal float[] vertices; internal float[] vertices;
internal int worldVerticesLength; internal int worldVerticesLength;
@ -47,17 +46,13 @@ namespace Spine {
public int[] Bones { get { return bones; } set { bones = value; } } public int[] Bones { get { return bones; } set { bones = value; } }
public float[] Vertices { get { return vertices; } set { vertices = value; } } public float[] Vertices { get { return vertices; } set { vertices = value; } }
public int WorldVerticesLength { get { return worldVerticesLength; } set { worldVerticesLength = value; } } public int WorldVerticesLength { get { return worldVerticesLength; } set { worldVerticesLength = value; } }
/// <summary>Timelines for the timeline attachment are also applied to this attachment.
/// May be null if no attachment-specific timelines should be applied.</summary>
public VertexAttachment TimelineAttachment { get { return timelineAttachment; } set { timelineAttachment = value; } }
public VertexAttachment (string name) public VertexAttachment (string name)
: base(name) { : base(name) {
lock (VertexAttachment.nextIdLock) { lock (VertexAttachment.nextIdLock) {
id = VertexAttachment.nextID++; id = VertexAttachment.nextID++;
} }
timelineAttachment = this;
} }
/// <summary>Copy constructor.</summary> /// <summary>Copy constructor.</summary>