dzkcc-mflow 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,6 +6,6 @@ export interface ICocosResManager extends IResManager {
|
|
|
6
6
|
loadPrefab(path: string, nameOrUrl?: string): Promise<Prefab>;
|
|
7
7
|
loadSpriteFrame(ref: Sprite, path: string, nameOrUrl?: string): Promise<SpriteFrame>;
|
|
8
8
|
loadSpine(ref: sp.Skeleton, path: string, nameOrUrl?: string): Promise<sp.SkeletonData>;
|
|
9
|
-
release(asset: Asset): void;
|
|
10
|
-
release(path: string, type?: AssetType<Asset>, nameOrUrl?: string): void;
|
|
9
|
+
release(asset: Asset, force?: boolean): void;
|
|
10
|
+
release(path: string, type?: AssetType<Asset>, nameOrUrl?: string, force?: boolean): void;
|
|
11
11
|
}
|
package/dist/libs/BaseView.js
CHANGED
|
@@ -65,8 +65,7 @@ class BaseView extends Component {
|
|
|
65
65
|
onDestroy() {
|
|
66
66
|
// 自动清理加载的资源
|
|
67
67
|
this._loaderHandlers.forEach(({ path, asset }) => {
|
|
68
|
-
mf.res.release(
|
|
69
|
-
// mf.res.release(asset);
|
|
68
|
+
mf.res.release(asset);
|
|
70
69
|
});
|
|
71
70
|
this._loaderHandlers = [];
|
|
72
71
|
}
|
package/dist/libs/ResLoader.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export declare class ResLoader implements ICocosResManager {
|
|
|
5
5
|
loadPrefab(path: string, nameOrUrl?: string): Promise<Prefab>;
|
|
6
6
|
loadSpriteFrame(ref: Sprite, path: string, nameOrUrl?: string): Promise<SpriteFrame>;
|
|
7
7
|
loadSpine(ref: sp.Skeleton, path: string, nameOrUrl?: string): Promise<sp.SkeletonData>;
|
|
8
|
-
release(asset: Asset): void;
|
|
9
|
-
release(path: string, type?: AssetType<Asset>, nameOrUrl?: string): void;
|
|
8
|
+
release(asset: Asset, force?: boolean): void;
|
|
9
|
+
release(path: string, type?: AssetType<Asset>, nameOrUrl?: string, force?: boolean): void;
|
|
10
10
|
}
|
package/dist/libs/ResLoader.js
CHANGED
|
@@ -4,8 +4,6 @@ import { assetManager, Prefab, Asset, SpriteFrame, sp } from 'cc';
|
|
|
4
4
|
const DefaultBundle = "resources";
|
|
5
5
|
class ResLoader {
|
|
6
6
|
loadAsset(path, type, nameOrUrl = DefaultBundle) {
|
|
7
|
-
//TODO: bundle.release和assetManager.releaseAsset的区别?
|
|
8
|
-
//TODO: prefab是否需要addRef,prefab被克隆出来的节点被销毁时,对应的prefab如何处理?
|
|
9
7
|
if (assetManager.assets.has(path)) {
|
|
10
8
|
const asset = assetManager.assets.get(path);
|
|
11
9
|
asset.addRef();
|
|
@@ -31,6 +29,7 @@ class ResLoader {
|
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
31
|
loadPrefab(path, nameOrUrl = DefaultBundle) {
|
|
32
|
+
//refCount 记录的是持有者数量,不是资源份数,所以prefab也需要addRef
|
|
34
33
|
return this.loadAsset(path, Prefab, nameOrUrl);
|
|
35
34
|
}
|
|
36
35
|
loadSpriteFrame(ref, path, nameOrUrl = DefaultBundle) {
|
|
@@ -41,7 +40,7 @@ class ResLoader {
|
|
|
41
40
|
return Promise.resolve(sf);
|
|
42
41
|
}
|
|
43
42
|
else {
|
|
44
|
-
//
|
|
43
|
+
// 没有引用对象,释放掉资源
|
|
45
44
|
this.release(path, SpriteFrame, nameOrUrl);
|
|
46
45
|
return Promise.reject(new Error("Sprite is not valid"));
|
|
47
46
|
}
|
|
@@ -55,26 +54,37 @@ class ResLoader {
|
|
|
55
54
|
return Promise.resolve(spine);
|
|
56
55
|
}
|
|
57
56
|
else {
|
|
58
|
-
//
|
|
57
|
+
// 没有引用对象,释放掉资源
|
|
59
58
|
this.release(path, sp.SkeletonData, nameOrUrl);
|
|
60
59
|
return Promise.reject(new Error("Spine is not valid"));
|
|
61
60
|
}
|
|
62
61
|
});
|
|
63
62
|
}
|
|
64
|
-
release(pathOrAsset,
|
|
63
|
+
release(pathOrAsset, typeOrForce, nameOrUrl = DefaultBundle, forceParam = false) {
|
|
64
|
+
var _a;
|
|
65
|
+
let asset;
|
|
66
|
+
let force = false;
|
|
65
67
|
if (typeof pathOrAsset === "string") {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
asset === null || asset === void 0 ? void 0 : asset.decRef();
|
|
69
|
-
if ((asset === null || asset === void 0 ? void 0 : asset.refCount) === 0) {
|
|
70
|
-
bundle === null || bundle === void 0 ? void 0 : bundle.release(pathOrAsset, type);
|
|
68
|
+
if (!typeOrForce || typeof typeOrForce === "boolean") {
|
|
69
|
+
throw new Error('typeOrForce is undefined, or typeOrForce is boolean! typeOrForce must be AssetType<Asset>!');
|
|
71
70
|
}
|
|
71
|
+
force = forceParam;
|
|
72
|
+
asset = (_a = assetManager.getBundle(nameOrUrl)) === null || _a === void 0 ? void 0 : _a.get(pathOrAsset, typeOrForce);
|
|
72
73
|
}
|
|
73
74
|
else if (pathOrAsset instanceof Asset) {
|
|
74
|
-
pathOrAsset
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
asset = pathOrAsset;
|
|
76
|
+
force = typeof typeOrForce === 'boolean' ? typeOrForce : forceParam;
|
|
77
|
+
}
|
|
78
|
+
if (!asset) {
|
|
79
|
+
console.warn(`${pathOrAsset} Release asset failed, asset is null or undefined`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (force) {
|
|
83
|
+
assetManager.releaseAsset(asset);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// decRef原型:decRef (autoRelease = true),所以引用数量为 0,则将自动释放该资源。
|
|
87
|
+
asset.decRef();
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
}
|
package/dist/libs/UIManager.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
-
import { director, Node, Sprite, Widget, Input, input, instantiate } from 'cc';
|
|
2
|
+
import { director, Node, Sprite, Widget, Input, input, Prefab, instantiate } from 'cc';
|
|
3
3
|
import { ServiceLocator } from '../core/ServiceLocator.js';
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
|
|
@@ -144,6 +144,7 @@ class UIManager extends CcocosUIManager {
|
|
|
144
144
|
target = instantiate(prefab);
|
|
145
145
|
this._cache.set(viewType.name, target);
|
|
146
146
|
}
|
|
147
|
+
target.active = true;
|
|
147
148
|
return target.getComponent(viewType);
|
|
148
149
|
});
|
|
149
150
|
}
|
|
@@ -163,10 +164,21 @@ class UIManager extends CcocosUIManager {
|
|
|
163
164
|
}
|
|
164
165
|
viewortype.onExit();
|
|
165
166
|
viewortype.node.removeFromParent();
|
|
167
|
+
viewortype.node.active = false;
|
|
166
168
|
if (destroy) {
|
|
167
169
|
let cacheKey = viewortype.constructor.name;
|
|
168
170
|
(_a = this._cache.get(cacheKey)) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
169
171
|
this._cache.delete(cacheKey);
|
|
172
|
+
// 销毁被克隆出的UI后Node后,尝试释放 Prefab 资源
|
|
173
|
+
try {
|
|
174
|
+
const viewType = viewortype.constructor;
|
|
175
|
+
const prefabPath = this._getPrefabPath(viewType);
|
|
176
|
+
const ResMgr = ServiceLocator.getService('ResLoader');
|
|
177
|
+
ResMgr.release(prefabPath, Prefab);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error(`Failed to release prefab for ${cacheKey}:`, error);
|
|
181
|
+
}
|
|
170
182
|
}
|
|
171
183
|
}
|
|
172
184
|
internalGetTopView() {
|
package/dist/mflow-tools.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED