- 移除 MGetsComp 中未使用的属性和方法,简化组件结构 - 在 MissionGetsComp 中实现动态加载奖励图标功能,支持从 gui/uicons 图集获取 - 调整 get.prefab 结构,分离图标和数字显示节点 - 解决资源加载机制限制,确保动态加载资源正常工作
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import { _decorator, Node, Label, PrefabLink, instantiate, Prefab, SpriteAtlas, Sprite, resources } from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { GameEvent } from "../common/config/GameEvent";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('MissionGetsCompComp')
|
|
@ecs.register('MissionGetsComp', false)
|
|
export class MissionGetsCompComp extends CCComp {
|
|
get_datas:any={};
|
|
get_nodes:Node[]=[];
|
|
// 图标图集缓存
|
|
private uiconsAtlas: SpriteAtlas | null = null;
|
|
start() {
|
|
|
|
}
|
|
|
|
onDestroy() {
|
|
|
|
}
|
|
load_hui(uuid:string){
|
|
var path = "game/gui/get";
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
var node = instantiate(prefab);
|
|
// 将节点添加到父节点下
|
|
this.node.addChild(node);
|
|
node.getChildByName("num").getComponent(Label).string = "1";
|
|
const sprite = node.getChildByName("icon").getComponent(Sprite);
|
|
if (!sprite) return;
|
|
|
|
if (this.uiconsAtlas) {
|
|
const frame = this.uiconsAtlas.getSpriteFrame(uuid);
|
|
if (frame) {
|
|
sprite.spriteFrame = frame;
|
|
}
|
|
} else {
|
|
// 加载图集
|
|
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
|
|
if (err) {
|
|
console.error("[MissionCardComp] Failed to load uicons atlas", err);
|
|
return;
|
|
}
|
|
this.uiconsAtlas = atlas;
|
|
const frame = atlas.getSpriteFrame(uuid);
|
|
if (frame) {
|
|
sprite.spriteFrame = frame;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private updateNodeNum(node: Node, num: number) {
|
|
|
|
}
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
}
|