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

61 lines
1.8 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: 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: string = "";
@property({ type: CCString, serializable: true })
get dataID(): string {
return this._dataID || "";
}
set dataID(value: string) {
this._dataID = value;
if (!EDITOR) {
this.updateSpine();
}
}
/** 默认动画名 */
private _defaultAnimation: string = "";
onLoad() {
let spine: sp.Skeleton = this.getComponent(sp.Skeleton)!;
this._defaultAnimation = spine.animation;
}
start() {
this.updateSpine();
}
/** 更新语言 */
language() {
this.updateSpine();
}
private updateSpine() {
// 获取语言标记
let path = `language/spine/${LanguageData.current}/${this.dataID}`;
let res: sp.SkeletonData | null = resLoader.get(path, sp.SkeletonData);
if (res) {
let spine: sp.Skeleton = this.getComponent(sp.Skeleton)!;
spine.skeletonData = res;
spine.setAnimation(0, this._defaultAnimation, true);
}
else {
console.error("[LanguageSpine] 资源不存在 " + path);
}
}
}