TimerManager.stop方法添加重置计时状态功能

This commit is contained in:
dgflash
2023-01-10 10:08:30 +08:00
parent ab3c4cbb2e
commit be40dbb838
2 changed files with 26 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
import { Asset, AssetManager, assetManager, Constructor, error, js, Prefab, resources, __private } from "cc";
import { Asset, AssetManager, Constructor, Prefab, __private, assetManager, error, js, resources } from "cc";
type ProgressCallback = __private._cocos_core_asset_manager_shared__ProgressCallback;
type CompleteCallback<T = any> = __private._cocos_core_asset_manager_shared__CompleteCallbackWithData;
@@ -177,13 +177,31 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback);
*/
releaseDir(path: string, bundleName: string = "resources") {
var bundle: AssetManager.Bundle | null = assetManager.getBundle(bundleName);
var infos = bundle?.getDirWithPath(path);
infos?.map((info) => {
this.releasePrefabtDepsRecursively(info.uuid);
});
if (bundle) {
var infos = bundle.getDirWithPath(path);
if (infos) {
infos.map((info) => {
this.releasePrefabtDepsRecursively(info.uuid);
});
}
if (path == "" && bundleName != "resources" && bundle) {
assetManager.removeBundle(bundle);
if (path == "" && bundleName != "resources") {
assetManager.removeBundle(bundle);
}
}
}
/** 释放预制依赖资源 */
private releasePrefabtDepsRecursively(uuid: string) {
var asset = assetManager.assets.get(uuid)!;
assetManager.releaseAsset(asset);
if (asset instanceof Prefab) {
var uuids: string[] = assetManager.dependUtil.getDepsRecursively(uuid)!;
uuids.forEach(uuid => {
var asset = assetManager.assets.get(uuid)!;
asset.decRef();
});
}
}
@@ -270,18 +288,4 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback);
this.loadByBundleAndArgs(resources, args);
}
}
/** 释放预制依赖资源 */
private releasePrefabtDepsRecursively(uuid: string) {
var asset = assetManager.assets.get(uuid)!;
assetManager.releaseAsset(asset);
if (asset instanceof Prefab) {
var uuids: string[] = assetManager.dependUtil.getDepsRecursively(uuid)!;
uuids.forEach(uuid => {
var asset = assetManager.assets.get(uuid)!;
asset.decRef();
});
}
}
}

View File

@@ -307,6 +307,7 @@ export class Timer {
}
stop() {
this._elapsedTime = 0;
this.step = -1;
}
}