mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
@@ -1,45 +1,22 @@
|
||||
import { Asset } from "cc";
|
||||
import { app } from "../App";
|
||||
import { Sprite } from "cc";
|
||||
import { SpriteFrame } from "cc";
|
||||
import { Node } from "cc";
|
||||
import { Component } from "cc";
|
||||
|
||||
export enum IconTypeEnum{
|
||||
品质 = "品质",
|
||||
宠物装备 = "宠物装备",
|
||||
}
|
||||
|
||||
export default class TbResource {
|
||||
|
||||
static load<T extends Asset>(res:string,onComplete?:((err: Error | null, data: T) => void)){
|
||||
app.tbRes.get().load<T>(res,onComplete)
|
||||
}
|
||||
|
||||
static loadSpriteFrame(res:string,sprite:Sprite,comp:Component){
|
||||
|
||||
this.load<SpriteFrame>(res,(err,data:SpriteFrame) => {
|
||||
|
||||
if(!data) return;
|
||||
|
||||
if(!sprite.isValid || !comp.isValid) {
|
||||
//提前销毁
|
||||
data.addRef();
|
||||
data.decRef();
|
||||
}
|
||||
|
||||
sprite.spriteFrame = data;
|
||||
//添加引用标记
|
||||
data.addRef();
|
||||
|
||||
//添加销毁资源引用
|
||||
let onDestroy = comp["onDestroy"];
|
||||
|
||||
comp["onDestroy"] = () => {
|
||||
if(onDestroy)
|
||||
onDestroy.bind(comp)();
|
||||
//销毁引用
|
||||
if(sprite.isValid && sprite.spriteFrame == data) sprite.spriteFrame = null;
|
||||
data.decRef();
|
||||
}
|
||||
|
||||
})
|
||||
app.tbRes.loadSpriteFrame(res,sprite,comp)
|
||||
}
|
||||
|
||||
//加载资源ICON
|
||||
static loadSpriteIcon(type:IconTypeEnum,id:string | number,sprite:Sprite,comp:Component){
|
||||
app.tbRes.loadSpriteFrame(`icon/${type}/${id}/spriteFrame`,sprite,comp)
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user