Files
oops-plugin-framework/assets/libs/animator/AnimatorSkeletal.ts
dgflash ee47857f2b 1. 整理框架中所有组件在属性检查器中显示路径
2. 框架部分源码关联在线文档
2024-10-13 12:55:33 +08:00

62 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @Author: dgflash
* @Date: 2021-06-30 13:56:26
* @LastEditors: dgflash
* @LastEditTime: 2021-11-04 10:46:00
*/
import { CCFloat, game, SkeletalAnimation, _decorator } from 'cc';
import AnimatorAnimation from './AnimatorAnimation';
const { ccclass, property, requireComponent, disallowMultiple, menu, help } = _decorator;
@ccclass
@disallowMultiple
@requireComponent(SkeletalAnimation)
@menu('OopsFramework/Animator/AnimatorSkeletal (骨骼动画状态机)')
@help('https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12036279&doc_id=2873565')
export class AnimatorSkeletal extends AnimatorAnimation {
@property({
type: CCFloat,
tooltip: "动画切换过度时间"
})
private duration: number = 0.3;
private cross_duration: number = 0; // 防止切换动画时间少于间隔时间导致动画状态错乱的问题
private current_time: number = 0; // 上一次切换状态时间
onLoad() {
this.cross_duration = this.duration * 1000;
}
/**
* 播放动画
* @override
* @param animName 动画名
* @param loop 是否循环播放
*/
protected playAnimation(animName: string, loop: boolean) {
if (!animName) {
return;
}
if (game.totalTime - this.current_time > this.cross_duration) {
this._animation.crossFade(animName, this.duration);
}
else {
this._animation.play(animName);
}
this.current_time = game.totalTime;
this._animState = this._animation.getState(animName);
if (!this._animState) {
return;
}
if (!this._wrapModeMap.has(this._animState)) {
this._wrapModeMap.set(this._animState, this._animState.wrapMode);
}
// this._animState.wrapMode = loop ? 2 : this._wrapModeMap.get(this._animState)!;
this._animState.wrapMode = loop ? 2 : 1; // 2为循环播放1为单次播放
}
}