[csharp] Port of commits 8d5f6c5 and 2059c86: AnimationState setAnimation only discards if the former entry was never applied AND is the same animation. Fixed AnimationStateTests for discarding a never applied entry.

This commit is contained in:
Harald Csaszar 2026-03-16 20:58:20 +01:00
parent 0801a4913b
commit 964da9b849
4 changed files with 30 additions and 20 deletions

View File

@ -694,8 +694,12 @@ namespace Spine {
return SetAnimation(trackIndex, animation, loop);
}
/// <summary>Sets the current animation for a track, discarding any queued animations. If the formerly current track entry was never
/// applied to a skeleton, it is replaced (not mixed from).</summary>
/// <summary><para>
/// Sets the current animation for a track, discarding any queued animations.</para>
/// <para>
/// If the formerly current track entry is for the same animation and was never applied to a skeleton, it is replaced (not mixed
/// from).
/// </para></summary>
/// <param name="loop">If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its
/// duration. In either case<see cref="TrackEntry.TrackEnd"/> determines when the track is cleared.</param>
/// <returns> A track entry to allow further customization of animation playback. References to the track entry must not be kept
@ -705,7 +709,7 @@ namespace Spine {
bool interrupt = true;
TrackEntry current = ExpandToIndex(trackIndex);
if (current != null) {
if (current.nextTrackLast == -1) {
if (current.nextTrackLast == -1 && current.animation == animation) {
// Don't mix from an entry that was never applied.
tracks.Items[trackIndex] = current.mixingFrom;
queue.Interrupt(current);

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-csharp",
"displayName": "spine-csharp Runtime",
"description": "This plugin provides the spine-csharp core runtime. Compatible with skeleton exports from Spine Editor version 4.3.40-beta or later.",
"version": "4.3.16",
"version": "4.3.17",
"unity": "2018.3",
"author": {
"name": "Esoteric Software",

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-csharp-tests",
"displayName": "spine-csharp Runtime Tests",
"description": "This plugin provides tests for the spine-csharp core runtime.",
"version": "4.3.0",
"version": "4.3.1",
"unity": "2018.3",
"author": {
"name": "Esoteric Software",

View File

@ -602,11 +602,13 @@ namespace Spine {
Setup("setAnimation twice", // 21
Expect(0, "start", 0, 0), //
Expect(0, "interrupt", 0, 0), //
Expect(0, "end", 0, 0), //
Expect(0, "dispose", 0, 0), //
Expect(1, "start", 0, 0), //
Expect(1, "event 0", 0, 0), //
Expect(0, "end", 0, 0.1f), //
Expect(0, "dispose", 0, 0.1f), //
Expect(1, "event 14", 0.5f, 0.5f), //
Note("First 2 setAnimation calls are done."),
@ -615,8 +617,6 @@ namespace Spine {
Expect(0, "start", 0, 0.8f), //
Expect(0, "interrupt", 0, 0.8f), //
Expect(0, "end", 0, 0.8f), //
Expect(0, "dispose", 0, 0.8f), //
Expect(2, "start", 0, 0.8f), //
Expect(2, "event 0", 0.1f, 0.9f), //
@ -624,18 +624,21 @@ namespace Spine {
Expect(1, "end", 0.9f, 1), //
Expect(1, "dispose", 0.9f, 1), //
Expect(0, "end", 0.1f, 1), //
Expect(0, "dispose", 0.1f, 1), //
Expect(2, "event 14", 0.5f, 1.3f), //
Expect(2, "event 30", 1, 1.8f), //
Expect(2, "complete", 1, 1.8f), //
Expect(2, "end", 1, 1.9f), //
Expect(2, "dispose", 1, 1.9f) //
);
state.SetAnimation(0, "events0", false); // First should be ignored.
state.SetAnimation(0, "events0", false); // Kept as mixingFrom (not discarded, different animation).
state.SetAnimation(0, "events1", false);
Run(0.1f, 1000, new TestListener(
(time) => {
if (IsEqual(time, 0.8f)) {
state.SetAnimation(0, "events0", false); // First should be ignored.
state.SetAnimation(0, "events0", false); // Kept as mixingFrom (not discarded, different animation).
state.SetAnimation(0, "events2", false).TrackEnd = 1;
}
}));
@ -643,8 +646,6 @@ namespace Spine {
Setup("setAnimation twice with multiple mixing", // 22
Expect(0, "start", 0, 0), //
Expect(0, "interrupt", 0, 0), //
Expect(0, "end", 0, 0), //
Expect(0, "dispose", 0, 0), //
Expect(1, "start", 0, 0), //
Expect(1, "event 0", 0, 0), //
@ -655,8 +656,6 @@ namespace Spine {
Expect(0, "start", 0, 0.2f), //
Expect(0, "interrupt", 0, 0.2f), //
Expect(0, "end", 0, 0.2f), //
Expect(0, "dispose", 0, 0.2f), //
Expect(2, "start", 0, 0.2f), //
Expect(2, "event 0", 0.1f, 0.3f), //
@ -667,36 +666,43 @@ namespace Spine {
Expect(1, "start", 0, 0.4f), //
Expect(1, "interrupt", 0, 0.4f), //
Expect(1, "end", 0, 0.4f), //
Expect(1, "dispose", 0, 0.4f), //
Expect(0, "start", 0, 0.4f), //
Expect(0, "event 0", 0.1f, 0.5f), //
Expect(0, "end", 0.6f, 0.7f), //
Expect(0, "dispose", 0.6f, 0.7f), //
Expect(1, "end", 0.8f, 0.9f), //
Expect(1, "dispose", 0.8f, 0.9f), //
Expect(0, "end", 0.6f, 0.9f), //
Expect(0, "dispose", 0.6f, 0.9f), //
Expect(0, "event 14", 0.5f, 0.9f), //
Expect(2, "end", 0.8f, 1.1f), //
Expect(2, "dispose", 0.8f, 1.1f), //
Expect(1, "end", 0.6f, 1.1f), //
Expect(1, "dispose", 0.6f, 1.1f), //
Expect(0, "event 30", 1, 1.4f), //
Expect(0, "complete", 1, 1.4f), //
Expect(0, "end", 1, 1.5f), //
Expect(0, "dispose", 1, 1.5f) //
);
stateData.DefaultMix = 0.6f;
state.SetAnimation(0, "events0", false); // First should be ignored.
state.SetAnimation(0, "events0", false); // Kept as mixingFrom (not discarded, different animation).
state.SetAnimation(0, "events1", false);
Run(0.1f, 1000, new TestListener(
(time) => {
if (IsEqual(time, 0.2f)) {
state.SetAnimation(0, "events0", false); // First should be ignored.
state.SetAnimation(0, "events0", false); // Kept as mixingFrom (not discarded, different animation).
state.SetAnimation(0, "events2", false);
}
if (IsEqual(time, 0.4f)) {
state.SetAnimation(0, "events1", false); // First should be ignored.
state.SetAnimation(0, "events1", false); // Kept as mixingFrom (not discarded, different animation).
state.SetAnimation(0, "events0", false).TrackEnd = 1;
}
}));