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

72 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2021-01-19 14:30:12 +00:00
import AnimatorBase, { AnimationPlayer } from "./core/AnimatorBase";
import AnimatorStateLogic from "./core/AnimatorStateLogic";
const { ccclass, property, requireComponent, disallowMultiple } = cc._decorator;
2021-01-19 14:30:12 +00:00
/**
* DragonBones状态机组件
*/
2021-01-19 14:30:12 +00:00
@ccclass
@disallowMultiple
@requireComponent(dragonBones.ArmatureDisplay)
export default class AnimatorDragonBones extends AnimatorBase {
/** DragonBones组件 */
private _dragonBones: dragonBones.ArmatureDisplay = null;
2021-01-19 14:30:12 +00:00
protected start() {
if (!this.PlayOnStart || this._hasInit) {
2021-01-19 14:30:12 +00:00
return;
}
this._hasInit = true;
this._dragonBones = this.getComponent(dragonBones.ArmatureDisplay);
this._dragonBones.addEventListener(dragonBones.EventObject.COMPLETE, this.onAnimFinished, this);
2021-01-19 14:30:12 +00:00
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) {
2021-01-19 14:30:12 +00:00
return;
}
this._hasInit = true;
this.initArgs(...args);
this._dragonBones = this.getComponent(dragonBones.ArmatureDisplay);
this._dragonBones.addEventListener(dragonBones.EventObject.COMPLETE, this.onAnimFinished, this);
2021-01-19 14:30:12 +00:00
if (this.AssetRawUrl !== null) {
this.initJson(this.AssetRawUrl.json);
}
}
/**
*
* @override
* @param animName
* @param loop
*/
protected playAnimation(animName: string, loop: boolean) {
animName && this._dragonBones.playAnimation(animName, loop ? 0 : -1);
2021-01-19 14:30:12 +00:00
}
/**
*
* @override
* @param scale
*/
protected scaleTime(scale: number) {
this._dragonBones.timeScale = scale;
2021-01-19 14:30:12 +00:00
}
}