Files
UnityAI/modules/frameworks/资源管理/README.md
lms db0143be83 Merge remote changes: integrate MCP tools and resource refactor docs into framework
- Resolve directory rename conflict from old 03/06 dirs
- Move remote-added 资源加载重构方案.md into modules/frameworks/资源管理/
- Move remote-added 06_工具脚本/MCP工具 into modules/frameworks/编辑器工具/MCP工具/
- Keep Tools/CodexUnityMcp/ as MCP Server implementation
- Update README.md, modules/模块索引.md, and parent READMEs
- Add 文档关联 sections to new docs and fix old absolute paths

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-07 19:07:27 +08:00

143 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 资源管理
## 分类
- 核心框架
## 目的
管理 AssetBundle、语言资源、图集、prefab、DllBytes 等资源的加载、缓存和释放。
---
## 核心路径
- AssetBundle`Assets/Game/GameHFScripte/CopyToHF/AssetBundle/`
- 图集:`Assets/Game/GameHFScripte/CopyToHF/SpriteAtlas/`
- 资源目录:`Assets/Game/GameHFResource/CN/``EN/``DllBytes/`
---
## 核心类
| 类 | 职责 |
|---|---|
| `HFABMgr` | AssetBundle 资源管理器单例 |
| `HFAssetLoader` | 具体资源加载器 |
| `HFAssetRequest` | 资源加载请求 |
| `HFAssetBundlePathAttribute` | 资源路径属性,标记资源根目录、相对路径、语言包规则等 |
| `HFGlobal_SpriteAtlas` | 图集全局管理 |
---
## 资源路径规则
`HFAssetBundlePathAttribute` 记录:
- 资源根目录
- 相对路径
- 是否忽略语言包
- 是否场景
- 线程优先级
`ChangeLanguage` 生成:
- `editorPath`
- `assetBundlePath`
- `assetBundleKey`
- `assetName`
`HFABMgr.OnCheckAssetBundlePathAttributeLanguage` 在当前语言无资源时回退默认语言。
---
## 加载流程
```text
HFABMgr.LoadInMemory(pathAttr)
-> OnReadAssetBundleManifest()
-> OnCheckAssetBundlePathAttributeLanguage()
-> new HFAssetRequest(...)
-> OnStartLoad()
-> 获取或创建 HFAssetLoader
-> HFAssetLoader.LoadAsset()
```
---
## 加载模式
### Editor 模式
```text
enHFAbLoadModel.Editor
-> SFAssetUtility_Unity.LoadFromFile(editorPath)
-> 直接读取编辑器资源
```
### 非 Editor 模式
```text
读取 AssetBundleManifest
-> 解析依赖
-> AssetBundle.LoadFromMemoryAsync 读取主资源
```
### CDN / 边玩边下
```text
缺失资源进入 WaitDownload
-> HFAssetsDownLoadManager 下载
-> HFABMgr.SaveFile 保存到本地
-> 加载完成
```
---
## 图集加载
```text
SpriteAtlasManager.atlasRequested
-> HFGlobal_SpriteAtlas.Instance.GetSpriteAtlasPath(spriteAtlasName)
-> HFABMgr.OnLoadInMemory(spriteAtlasAttribute)
-> callback(SpriteAtlas)
```
---
## 使用规则
- 资源路径统一通过 `HFAssetBundlePathAttribute` 配置。
- 加载资源统一走 `HFFunCatalogue.Asset.LoadAsset()``HFABMgr.LoadInMemory()`
- 语言资源按 `GameHFResource/<lang>/` 分目录存放。
- 图集按业务或 UI 模块划分。
---
## 相关模块
- [UI 窗口系统](../UI窗口系统/README.md)
- [实体系统](../实体系统/README.md)
- [场景系统](../场景系统.md)
## 子文档
- [资源管理使用指南](使用指南.md)
- [资源加载重构方案](资源加载重构方案.md)
---
## 文档关联
> 当本文档发生变更时,应同步检查以下关联文档,避免信息不一致。
| 文档 | 关联原因 |
|---|---|
| [modules/模块索引.md](../../模块索引.md) | 模块索引是项目知识总入口 |
| [modules/frameworks/UI窗口系统/README.md](../UI窗口系统/README.md) | UI 资源加载依赖资源管理 |
| [modules/frameworks/实体系统/README.md](../实体系统/README.md) | 实体资源加载依赖资源管理 |
| [modules/frameworks/场景系统.md](../场景系统.md) | 场景资源加载依赖资源管理 |
| [modules/frameworks/资源管理/资源加载重构方案.md](资源加载重构方案.md) | AssetBundle 加载链路重构方案 |
| [rules/10-架构说明.md](../../../rules/10-架构说明.md) | 架构说明定义总体分层和依赖方向 |
| [rules/30-模块登记规则.md](../../../rules/30-模块登记规则.md) | 模块登记规则定义分类和状态口径 |