mirror of
https://github.com/wyb10a10/cocos_creator_framework.git
synced 2026-05-16 02:37:01 +08:00
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { resLoader } from "../res/ResLoader";
|
|
import { ResUtil } from "../res/ResUtil";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class NetExample extends cc.Component {
|
|
@property(cc.Boolean)
|
|
resUtilMode = true;
|
|
@property(cc.Node)
|
|
attachNode: cc.Node = null;
|
|
@property(cc.Label)
|
|
dumpLabel: cc.Label = null;
|
|
|
|
onAdd() {
|
|
resLoader.loadRes("prefabDir/HelloWorld", cc.Prefab, (error: Error, prefab: cc.Prefab) => {
|
|
if (!error) {
|
|
let myNode = ResUtil.instantiate(prefab);
|
|
myNode.parent = this.attachNode;
|
|
myNode.setPosition((Math.random() * 500) - 250, myNode.position.y);
|
|
console.log(myNode.position);
|
|
}
|
|
});
|
|
}
|
|
|
|
onSub() {
|
|
if (this.attachNode.childrenCount > 0) {
|
|
this.attachNode.children[this.attachNode.childrenCount - 1].destroy();
|
|
}
|
|
}
|
|
|
|
onAssign() {
|
|
resLoader.releaseRes("prefabDir/HelloWorld", cc.Prefab);
|
|
}
|
|
|
|
onClean() {
|
|
this.attachNode.destroyAllChildren();
|
|
}
|
|
|
|
onDump() {
|
|
let Loader: any = cc.loader;
|
|
this.dumpLabel.string = `当前资源总数:${Object.keys(Loader._cache).length}`;
|
|
}
|
|
}
|