Skip to content

Commit

Permalink
fix 3.7 error
Browse files Browse the repository at this point in the history
  • Loading branch information
wyb10a10 committed Jul 31, 2023
1 parent 91e26a6 commit e19cacc
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions assets/Script/example/ResExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { sp } from "cc";
import { SpriteFrame } from "cc";
import { Component, Node, Label, Asset, Prefab, _decorator, instantiate, resources } from "cc";
import { resLoader } from "../res/ResLoader";
import { Texture2D } from "cc";

const { ccclass, property } = _decorator;

Expand Down Expand Up @@ -32,24 +33,24 @@ export default class NetExample extends Component {

onUnloadRes() {
// 释放动态加载的资源
this.attachNode.destroyAllChildren();
cc.loader.releaseRes("prefabDir/HelloWorld");
this.attachNode?.destroyAllChildren();
resources.release("prefabDir/HelloWorld", Prefab);
}

onMyLoadRes() {
if (this.ress.length > 0) {
console.log(`this.ress.length is ${this.ress.length}`);
return;
}
resLoader.loadDir("prefabDir", Prefab, (error, prefabs) => {
resLoader.loadDir("prefabDir", Prefab, (error: any, prefabs: string | any[]) => {
if (!error) {
this.ress.push(...prefabs);
for (let i = 0; i < prefabs.length; ++i) {
instantiate(prefabs[i]).parent = this.attachNode;
}
}
});
resLoader.load("alien/alien-pro", sp.SkeletonData, (err, spineAsset)=> {
resLoader.load("alien/alien-pro", sp.SkeletonData, (err: any, spineAsset: sp.SkeletonData)=> {
if (!err) {
let node = new Node();
node.parent = this.attachNode;
Expand All @@ -62,17 +63,17 @@ export default class NetExample extends Component {
}

onMyUnloadRes() {
this.attachNode.destroyAllChildren();
this.attachNode?.destroyAllChildren();
if (this.ress) {
for(let item of this.ress) {
ResLoader.release(item);
assetManager.releaseAsset(item);
}
this.ress = [];
}
}

onLoadRemote() {
resLoader.load("http://tools.itharbors.com/christmas/res/tree.png", (err, res) => {
resLoader.load("http://tools.itharbors.com/christmas/res/tree.png", (err: any, res: Texture2D | null) => {
if (err || !res) return;
this.remoteRes = res;
let spriteFrame = new SpriteFrame();
Expand All @@ -85,8 +86,8 @@ export default class NetExample extends Component {
}

onUnloadRemote() {
this.attachNode.destroyAllChildren();
this.remoteRes.decRef();
this.attachNode?.destroyAllChildren();
this.remoteRes?.decRef();
}

onDump() {
Expand Down

0 comments on commit e19cacc

Please sign in to comment.