1234567891011121314151617181920212223242526272829 |
- export class ResMgr {
- private static _inst: ResMgr;
- public static get inst(): ResMgr {
- if (this._inst == null) {
- this._inst = new ResMgr();
- }
- return this._inst;
- }
- // 跟随节点释放
- loadPrefab(name: string, parent: cc.Node): Promise<void>{
- return new Promise((resolve)=>{
- cc.resources.load(name, cc.Prefab, (err, res) => {
- if (res) {
- let node = cc.instantiate(res);
- parent.addChild(node);
- res.addRef();
- parent.on(cc.Node.EventType.CHILD_REMOVED, (child: cc.Node)=>{
- if(child.uuid == node.uuid) {
- res.decRef();
- }
- });
- }
- resolve();
- });
- });
- }
- }
|