41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { _decorator, Component, sp } from 'cc';
|
|
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { HeroAnimState } from "./HeroAnimState";
|
|
|
|
@ecs.register('SpineComp')
|
|
export class SpineComp extends ecs.Comp {
|
|
private _skeleton: sp.Skeleton = null!;
|
|
|
|
/** 设置动画过渡混合时间 */
|
|
setMix(from: string, to: string, duration: number) {
|
|
this._skeleton.setMix(from, to, duration);
|
|
}
|
|
|
|
/** 初始化Spine组件 */
|
|
init(node: sp.Skeleton): this {
|
|
this._skeleton = node;
|
|
// 根据实际动画配置过渡
|
|
this.setMix("Walking", "Attacking", 0.2);
|
|
this.setMix("Attacking", "Walking", 0.3);
|
|
this.setMix("Attacking", "Idle", 0.1);
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* 播放动画
|
|
* @param animationName 动画名称
|
|
* @param loop 是否循环
|
|
*/
|
|
play(animationName: string, loop: boolean = true) {
|
|
this._skeleton.setAnimation(0, animationName, loop);
|
|
}
|
|
|
|
/** 设置皮肤 */
|
|
setSkin(skinName: string) {
|
|
this._skeleton.setSkin(skinName);
|
|
}
|
|
|
|
reset() {
|
|
this._skeleton = null!;
|
|
}
|
|
}
|