Files
oops-plugin-framework/assets/libs/animator/AnimatorSpineSecondary.ts
dgflash f2fe9d47b6 1. 存储模块全面优化,修复跨平台兼容性问题,完美支持所有Unicode字符
2. 存储模块性能提升,添加LRU缓存、批量操作支持,优化内存使用
3. 多语言模块性能与内存管理优化,组件查询性能提升
4. 时间模块类型安全与性能优化,使用泛型替代any,对象池机制减少内存分配
5. 事件系统修复双重注册、重复注册等严重问题,实现EventData对象池减少GC压力
6. RandomManager修复4个逻辑BUG,包括边界问题和越界问题
7. 音频模块内存与性能优化,避免重复加载,优化数据结构,添加完整清理机制
8. CCView与CCViewVM合并,支持按需启用MVVM
9. Collection模块优化,AsyncQueue添加队列容量限制,Collection查询性能提升
10. ECS系统全面优化,对象池复用减少内存分配,循环性能提升
11. 优化MVVM组件性能
2026-01-09 21:54:05 +08:00

88 lines
2.8 KiB
TypeScript
Raw Permalink 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.
import { _decorator, sp } from 'cc';
import AnimatorSpine from './AnimatorSpine';
import type { AnimationPlayer } from './core/AnimatorBase';
import AnimatorBase from './core/AnimatorBase';
import type { AnimatorStateLogic } from './core/AnimatorStateLogic';
const { ccclass, property, requireComponent, menu, help } = _decorator;
/**
* Spine状态机组件次状态机同一节点可添加多个用于在不同track中播放动画trackIndex必须大于0
*/
@ccclass
@requireComponent(sp.Skeleton)
@menu('OopsFramework/Animator/AnimatorSpine Spine 次状态机)')
@help('https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12036279&doc_id=2873565')
export default class AnimatorSpineSecondary extends AnimatorBase {
@property({ tooltip: '动画播放的trackIndex必须大于0' }) TrackIndex = 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
*/
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);
}
}
/**
* 组件销毁时清理资源
*/
protected onDestroy() {
// 从主状态机移除次状态机监听器
if (this._main) {
this._main.removeSecondaryListener(this.onAnimFinished);
}
}
}