mirror of
https://gitee.com/dgflash/oops-framework.git
synced 2026-05-22 06:28:04 +08:00
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
/*
|
|
* @Author: dgflash
|
|
* @Date: 2021-11-18 17:42:59
|
|
* @LastEditors: dgflash
|
|
* @LastEditTime: 2022-03-14 16:40:32
|
|
*/
|
|
|
|
import { Component, sp, _decorator } from "cc";
|
|
import { resLoader } from "../../../core/common/loader/ResLoader";
|
|
import { config } from "../../common/config/Config";
|
|
import { Role } from "../Role";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 角色资源加载 */
|
|
@ccclass('RoleViewLoader')
|
|
export class RoleViewLoader extends Component {
|
|
spine: sp.Skeleton = null!;
|
|
|
|
onLoad() {
|
|
this.node.on("load", this.onEmitLoad, this);
|
|
}
|
|
|
|
private onEmitLoad(role: Role) {
|
|
this.spine = role.RoleView.spine;
|
|
this.load(role.RoleModel.anim);
|
|
}
|
|
|
|
private load(name: string) {
|
|
this.node.active = false;
|
|
|
|
var path = config.game.getRolePath(name);
|
|
resLoader.load(path, sp.SkeletonData, (err: Error | null, sd: sp.SkeletonData) => {
|
|
if (err) {
|
|
console.error(`动画名为【${path}】的角色资源不存在`);
|
|
return;
|
|
}
|
|
|
|
this.spine.skeletonData = sd;
|
|
this.spine.skeletonData.addRef();
|
|
this.node.active = true;
|
|
});
|
|
}
|
|
|
|
onDestroy() {
|
|
this.spine.skeletonData.decRef();
|
|
}
|
|
} |