Add set-animation-time.

This commit is contained in:
Davide Tantillo 2025-11-06 10:48:25 +01:00
parent 10edf10dce
commit e90d5d5d82
5 changed files with 94 additions and 0 deletions

View File

@ -198,6 +198,29 @@
"type": "number"
}
]
},
{
"id": "set-animation-time",
"scriptName": "SetAnimationTime",
"highlight": false,
"params": [
{
"id": "units",
"type": "combo",
"items": [
"seconds",
"ratio"
]
},
{
"id": "time",
"type": "number"
},
{
"id": "track",
"type": "number"
}
]
}
],
"expressions": [

View File

@ -55,6 +55,10 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Acts =
SetAnimationSpeed (this: SDKInstanceClass, speed: number) {
this.setAnimationSpeed(speed);
},
SetAnimationTime (this: SDKInstanceClass, units: 0 | 1, time: number, track: number) {
this.setAnimationTime(units, time, track);
}
};

View File

@ -228,6 +228,27 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
this.animationSpeed = speed;
}
public setAnimationTime (units: 0 | 1, time: number, track: number) {
if (!this.state) return;
const trackEntry = this.state.tracks[track];
if (!trackEntry) return;
if (units === 0) {
if (time < trackEntry.animationStart || time > trackEntry.animationEnd) {
console.warn(`[Spine] Animation time ${time} is out of bounds [${trackEntry.animationStart}, ${trackEntry.animationEnd}]`);
return;
}
trackEntry.trackTime = time;
} else {
if (time < 0 || time > 1) {
console.warn(`[Spine] Animation time ratio ${time} is out of bounds [0, 1]`);
return;
}
trackEntry.trackTime = time * (trackEntry.animationEnd - trackEntry.animationStart);
}
}
private _setSkin () {
const { skeleton } = this;
if (!skeleton) return;

View File

@ -272,6 +272,29 @@
"desc": "Animation speed multiplier (1.0 is normal speed)"
}
}
},
"set-animation-time": {
"list-name": "Set animation time",
"display-text": "Set track {2} animation time to {1} ({0})",
"description": "Set the current time of an animation on a track",
"params": {
"units": {
"name": "Units",
"desc": "Time units",
"items": {
"seconds": "Seconds (absolute time)",
"ratio": "Ratio (0.0 to 1.0)"
}
},
"time": {
"name": "Time",
"desc": "Time value (in seconds or as a ratio 0.0-1.0)"
},
"track": {
"name": "Track",
"desc": "Track index"
}
}
}
},
"expressions": {

View File

@ -274,6 +274,29 @@
}
}
},
"set-animation-time": {
"list-name": "设置动画时间",
"display-text": "将轨道{2}的动画时间设置为{1}{0}",
"description": "设置轨道上动画的当前时间",
"params": {
"units": {
"name": "单位",
"desc": "时间单位",
"items": {
"seconds": "秒(绝对时间)",
"ratio": "比例0.0到1.0"
}
},
"time": {
"name": "时间",
"desc": "时间值秒或0.0-1.0的比例)"
},
"track": {
"name": "轨道",
"desc": "轨道索引"
}
}
},
"expressions": {
"double": {
"description": "将数字翻倍。",