diff --git a/spine-ts/spine-construct3/src/aces.json b/spine-ts/spine-construct3/src/aces.json index 74cd70f8c..35f2208dc 100644 --- a/spine-ts/spine-construct3/src/aces.json +++ b/spine-ts/spine-construct3/src/aces.json @@ -63,6 +63,23 @@ "type": "string" } ] + }, + { + "id": "is-animation-playing", + "scriptName": "IsAnimationPlaying", + "isTrigger": false, + "params": [ + { + "id": "animation-name", + "type": "string", + "initial-value": "" + }, + { + "id": "track-index", + "type": "number", + "initial-value": -1 + } + ] } ], "actions": [ diff --git a/spine-ts/spine-construct3/src/c3runtime/conditions.ts b/spine-ts/spine-construct3/src/c3runtime/conditions.ts index 20eb2ed74..db2410b24 100644 --- a/spine-ts/spine-construct3/src/c3runtime/conditions.ts +++ b/spine-ts/spine-construct3/src/c3runtime/conditions.ts @@ -26,4 +26,7 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Cnds = IsInsideSlot (this: SpineC3Instance, x: number, y: number, slotName: string) { return this.isInsideSlot(x, y, slotName); }, + IsAnimationPlaying (this: SpineC3Instance, animationName: string, trackIndex: number) { + return this.isAnimationPlaying(animationName, trackIndex); + }, }; diff --git a/spine-ts/spine-construct3/src/c3runtime/instance.ts b/spine-ts/spine-construct3/src/c3runtime/instance.ts index a9427f602..5a9e00c70 100644 --- a/spine-ts/spine-construct3/src/c3runtime/instance.ts +++ b/spine-ts/spine-construct3/src/c3runtime/instance.ts @@ -310,6 +310,25 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { return this.isPointInPolygon(vertices, hullLength, coords.x, coords.y); } + public isAnimationPlaying (animationName: string, trackIndex: number) { + if (!this.state) return false; + + if (trackIndex === -1) { + for (const track of this.state.tracks) { + if (!track) continue; + if (animationName === "" || track.animation?.name === animationName) return true; + } + return false; + } + + const track = this.state.tracks[trackIndex]; + if (!track) return false; + + if (animationName === "") return true; + + return track.animation?.name === animationName; + } + private isPointInPolygon (vertices: NumberArrayLike, hullLength: number, px: number, py: number) { if (hullLength < 6) { throw new Error("A polygon must have at least 3 vertices (6 numbers in the array). "); diff --git a/spine-ts/spine-construct3/src/lang/en-US.json b/spine-ts/spine-construct3/src/lang/en-US.json index 422d1f414..fee3f7328 100644 --- a/spine-ts/spine-construct3/src/lang/en-US.json +++ b/spine-ts/spine-construct3/src/lang/en-US.json @@ -137,6 +137,21 @@ "desc": "Name of the slot to check" } } + }, + "is-animation-playing": { + "list-name": "Is animation playing", + "display-text": "Is animation {0} playing on track {1}", + "description": "Check if animation is playing. Use empty string for animation or -1 for track to match any value.", + "params": { + "animation-name": { + "name": "Animation name", + "desc": "Animation name. Empty string matches any animation." + }, + "track-index": { + "name": "Track index", + "desc": "Track index. Use -1 to check all tracks." + } + } } }, "actions": { diff --git a/spine-ts/spine-construct3/src/lang/zh-CN.json b/spine-ts/spine-construct3/src/lang/zh-CN.json index c36fd00db..50b3d1fb1 100644 --- a/spine-ts/spine-construct3/src/lang/zh-CN.json +++ b/spine-ts/spine-construct3/src/lang/zh-CN.json @@ -137,6 +137,21 @@ "desc": "要检查的插槽名称" } } + }, + "is-animation-playing": { + "list-name": "动画是否正在播放", + "display-text": "动画{0}是否在轨道{1}上播放", + "description": "检查动画是否正在播放。使用空字符串匹配任何动画,使用-1匹配所有轨道。", + "params": { + "animation-name": { + "name": "动画名称", + "desc": "动画名称。空字符串匹配任何动画。" + }, + "track-index": { + "name": "轨道索引", + "desc": "轨道索引。使用-1检查所有轨道。" + } + } } }, "actions": {