cocos-animator/animator-runtime/animator2.x/AnimatorSpineSecondary.ts

73 lines
2.4 KiB
TypeScript
Raw Normal View History

import AnimatorSpine from "./AnimatorSpine";
import AnimatorBase, { AnimationPlayer } from "./core/AnimatorBase";
import AnimatorStateLogic from "./core/AnimatorStateLogic";
const { ccclass, property, requireComponent } = cc._decorator;
/**
* Spine状态机组件track中播放动画trackIndex必须大于0
*/
@ccclass
@requireComponent(sp.Skeleton)
export default class AnimatorSpineSecondary extends AnimatorBase {
@property({ tooltip: CC_DEV && '动画播放的trackIndex必须大于0' }) TrackIndex: number = 1;
/** 主状态机 */
private _main: AnimatorSpine = null;
/** spine组件 */
private _spine: sp.Skeleton = null;
protected start() {
if (!this.PlayOnStart || this._hasInit) {
return;
}
this._hasInit = true;
this._spine = this.getComponent(sp.Skeleton);
this._main = this.getComponent(AnimatorSpine);
this._main.addSecondaryListener(this.onAnimFinished, this);
if (this.AssetRawUrl !== null) {
this.initJson(this.AssetRawUrl.json);
}
}
/**
* 0-3
* - onStateChangeCall
* - stateLogicMap
* - animationPlayer
* @override
*/
public onInit(...args: Array<Map<string, AnimatorStateLogic> | ((fromState: string, toState: string) => void) | AnimationPlayer>) {
if (this.PlayOnStart || this._hasInit) {
return;
}
this._hasInit = true;
this.initArgs(...args);
this._spine = this.getComponent(sp.Skeleton);
this._main = this.getComponent(AnimatorSpine);
this._main.addSecondaryListener(this.onAnimFinished, this);
if (this.AssetRawUrl !== null) {
this.initJson(this.AssetRawUrl.json);
}
}
/**
*
* @override
* @param animName
* @param loop
*/
protected playAnimation(animName: string, loop: boolean) {
if (animName) {
this._spine.setAnimation(this.TrackIndex, animName, loop);
} else {
this._spine.clearTrack(this.TrackIndex);
}
}
}