2021-01-19 14:30:12 +00:00
|
|
|
|
import AnimatorBase, { AnimationPlayer } from "./core/AnimatorBase";
|
|
|
|
|
import AnimatorStateLogic from "./core/AnimatorStateLogic";
|
|
|
|
|
|
2021-01-24 11:29:37 +00:00
|
|
|
|
const { ccclass, property, requireComponent, disallowMultiple } = cc._decorator;
|
2021-01-19 14:30:12 +00:00
|
|
|
|
|
2021-01-24 11:29:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* DragonBones状态机组件
|
|
|
|
|
*/
|
2021-01-19 14:30:12 +00:00
|
|
|
|
@ccclass
|
2021-01-24 11:29:37 +00:00
|
|
|
|
@disallowMultiple
|
|
|
|
|
@requireComponent(dragonBones.ArmatureDisplay)
|
|
|
|
|
export default class AnimatorDragonBones extends AnimatorBase {
|
|
|
|
|
/** DragonBones组件 */
|
|
|
|
|
private _dragonBones: dragonBones.ArmatureDisplay = null;
|
2021-01-19 14:30:12 +00:00
|
|
|
|
|
2021-01-24 11:29:37 +00:00
|
|
|
|
protected start() {
|
|
|
|
|
if (!this.PlayOnStart || this._hasInit) {
|
2021-01-19 14:30:12 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this._hasInit = true;
|
|
|
|
|
|
2021-01-24 11:29:37 +00:00
|
|
|
|
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>) {
|
2021-01-24 11:29:37 +00:00
|
|
|
|
if (this.PlayOnStart || this._hasInit) {
|
2021-01-19 14:30:12 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this._hasInit = true;
|
|
|
|
|
|
|
|
|
|
this.initArgs(...args);
|
|
|
|
|
|
2021-01-24 11:29:37 +00:00
|
|
|
|
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) {
|
2021-01-24 11:29:37 +00:00
|
|
|
|
animName && this._dragonBones.playAnimation(animName, loop ? 0 : -1);
|
2021-01-19 14:30:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 缩放动画播放速率
|
|
|
|
|
* @override
|
|
|
|
|
* @param scale 缩放倍率
|
|
|
|
|
*/
|
|
|
|
|
protected scaleTime(scale: number) {
|
2021-01-24 11:29:37 +00:00
|
|
|
|
this._dragonBones.timeScale = scale;
|
2021-01-19 14:30:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|