mirror of
https://github.com/wyb10a10/cocos_creator_framework.git
synced 2026-05-15 10:17:58 +08:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { resLoader } from "../res/ResLoader";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class NetExample extends cc.Component {
|
|
@property(cc.Node)
|
|
attachNode: cc.Node = null;
|
|
@property(cc.Label)
|
|
dumpLabel: cc.Label = null;
|
|
|
|
onLoadRes() {
|
|
cc.loader.loadRes("Prefab/HelloWorld", cc.Prefab, (error: Error, prefab: cc.Prefab) => {
|
|
if (!error) {
|
|
cc.instantiate(prefab).parent = this.attachNode;
|
|
}
|
|
});
|
|
}
|
|
|
|
onUnloadRes() {
|
|
this.attachNode.removeAllChildren(true);
|
|
resLoader.releaseRes("Prefab/HelloWorld");
|
|
}
|
|
|
|
onMyLoadRes() {
|
|
resLoader.loadRes("Prefab/HelloWorld", cc.Prefab, (error: Error, prefab: cc.Prefab) => {
|
|
if (!error) {
|
|
cc.instantiate(prefab).parent = this.attachNode;
|
|
}
|
|
});
|
|
}
|
|
|
|
onMyUnloadRes() {
|
|
this.attachNode.removeAllChildren(true);
|
|
resLoader.releaseRes("Prefab/HelloWorld");
|
|
}
|
|
|
|
onDump() {
|
|
let Loader:any = cc.loader;
|
|
this.dumpLabel.string = `当前资源总数:${Object.keys(Loader._cache).length}`;
|
|
}
|
|
}
|