@xiacg/exia-assets 1.0.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xiachenggang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # exia-assets
2
+
3
+ 基于 Cocos Creator 的资源加载管理库,提供简单易用的资源加载和批量管理功能。
4
+
5
+ ## 简介
6
+
7
+ `exia-assets` 是一个专为 Cocos Creator 设计的资源管理库,支持通过路径或 UUID 加载资源,提供批量加载、并行控制、失败重试等功能。资源加载采用手动管理模式,支持按批次卸载资源,适合需要精细控制资源生命周期的场景(如战斗场景切换)。
8
+
9
+ **核心特性**:
10
+
11
+ - 📦 支持路径和 UUID 两种方式获取资源
12
+ - 🔄 资源加载多次等同于加载一次,避免重复加载
13
+ - 🎯 按批次管理资源,支持批量卸载
14
+ - ⚡ 支持并行加载控制和失败重试
15
+ - 📊 提供加载进度、完成、失败回调
16
+
17
+ ## 安装
18
+
19
+ ```bash
20
+ npm install @xiacg/exia-assets
21
+ ```
22
+
23
+ ## 使用说明
24
+
25
+ ### 资源加载器 (AssetLoader)
26
+
27
+ 用于加载资源,支持配置加载参数和回调:
28
+
29
+ - `start(configs)` - 开始加载资源列表
30
+ - `retryDownLoadFailedAssets()` - 重试加载失败的资源
31
+ - `parallel` - 设置最大并行加载数量(默认:10)
32
+ - `retry` - 设置失败重试次数(默认:0)
33
+ - `setCallbacks()` - 设置加载进度、完成、失败回调
34
+
35
+ **资源配置 (IAssetConfig)**:
36
+
37
+ - `path` - 资源路径(必填)
38
+ - `type` - 资源类型(可选,默认 `cc.Asset`)
39
+ - `isFile` - 是否为单个文件(可选,默认 `false`)
40
+ - `bundle` - 资源 bundle 名称(可选,默认 `"resources"`)
41
+
42
+ ### 资源池 (AssetPool)
43
+
44
+ 全局资源管理,提供资源获取和释放功能:
45
+
46
+ **资源获取**:
47
+
48
+ - `has(path, bundlename?)` - 检查资源是否已加载
49
+ - `get<T>(path, bundlename?)` - 按路径获取资源
50
+ - `hasUUID(uuid)` - 按 UUID 检查资源
51
+ - `getByUUID<T>(uuid)` - 按 UUID 获取资源
52
+
53
+ **资源释放**:
54
+
55
+ - `releasePath(path, bundlename?)` - 按路径释放资源
56
+ - `releaseDir(dir, bundlename?, asset?)` - 按文件夹释放资源
57
+ - `releaseUUID(uuid)` - 按 UUID 释放资源
58
+ - `releaseBatchAssets(batchName)` - 按批次释放资源
59
+ - `releaseAll()` - 释放所有加载的资源
60
+
61
+ ### 典型使用场景
62
+
63
+ **场景切换时批量加载和卸载**:
64
+
65
+ 1. 进入战斗场景时,使用 `new AssetLoader("battle")` 加载所有战斗资源
66
+ 2. 退出战斗场景时,调用 `AssetPool.releaseBatchAssets("battle")` 一键释放所有资源
67
+
68
+ 详细 API 请查看 `exia-assets.d.ts` 类型定义文件。
69
+
70
+ ## 许可证
71
+
72
+ MIT License
73
+
74
+ ## 作者
75
+
76
+ **exia** (xiacg)
77
+ **邮箱**: <xiacg@163.com>
78
+
79
+ ## 源码仓库
80
+
81
+ - [GitHub](https://github.com/xiachenggang/exia-framework.git)
82
+ - [npm](https://www.npmjs.com/package/@xiacg/exia-assets)