Files
oops-plugin-framework/assets/libs/gui/language/LanguageSpine.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

97 lines
2.7 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.
/*
* @Author: dgflash
* @Date: 2023-07-25 10:44:38
* @LastEditors: dgflash
* @LastEditTime: 2023-07-25 11:48:52
*/
import { CCString, Component, _decorator, sp } from 'cc';
import { EDITOR } from 'cc/env';
import { resLoader } from '../../../core/common/loader/ResLoader';
import { LanguageData } from './LanguageData';
const { ccclass, property, menu } = _decorator;
/** Spine 动画多语言 */
@ccclass('LanguageSpine')
@menu('OopsFramework/Language/LanguageSpine Spine 动画多语言)')
export class LanguageSpine extends Component {
@property({ serializable: true })
private _dataID = '';
@property({ type: CCString, serializable: true })
get dataID(): string {
return this._dataID || '';
}
set dataID(value: string) {
this._dataID = value;
if (!EDITOR) {
this.updateSpine();
}
}
/** 默认动画名 */
private _defaultAnimation = '';
/** 缓存的Spine组件引用 */
private _spineCache: sp.Skeleton | null = null;
/** 是否已初始化组件缓存 */
private _componentInitialized = false;
onLoad() {
this._initComponents();
}
/** 初始化并缓存组件引用 */
private _initComponents() {
if (this._componentInitialized) return;
this._spineCache = this.getComponent(sp.Skeleton);
if (!this._spineCache) {
console.error('[LanguageSpine] 该节点没有sp.Skeleton组件');
this._componentInitialized = true;
return;
}
this._defaultAnimation = this._spineCache.animation;
this._componentInitialized = true;
}
start() {
this.updateSpine();
}
/** 更新语言 */
language() {
this.updateSpine();
}
private updateSpine() {
// 确保组件已初始化
if (!this._componentInitialized) {
this._initComponents();
}
if (!this._spineCache) {
return;
}
// 获取语言标记
const path = `language/spine/${LanguageData.current}/${this.dataID}`;
const res: sp.SkeletonData | null = resLoader.get(path, sp.SkeletonData);
if (res) {
this._spineCache.skeletonData = res;
// 检查动画名是否有效
if (this._defaultAnimation) {
this._spineCache.setAnimation(0, this._defaultAnimation, true);
}
}
else {
console.error('[LanguageSpine] 资源不存在 ' + path);
}
}
onDestroy() {
// 清理缓存引用,帮助垃圾回收
this._spineCache = null;
this._defaultAnimation = '';
}
}