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

75 lines
2.3 KiB
TypeScript
Raw Permalink Normal View History

import { dragonBones, _decorator } from "cc";
2021-01-19 14:30:12 +00:00
import AnimatorBase, { AnimationPlayer } from "./core/AnimatorBase";
import AnimatorStateLogic from "./core/AnimatorStateLogic";
const { ccclass, property, requireComponent, disallowMultiple } = _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('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('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) {
if (animName)
this._dragonBones.playAnimation(animName, loop ? 0 : -1);
2021-01-19 14:30:12 +00:00
}
/**
*
* @override
* @param scale
*/
protected scaleTime(scale: number) {
if (scale > 0)
this._dragonBones.timeScale = scale;
2021-01-19 14:30:12 +00:00
}
}