docs: update resources API docs
This commit is contained in:
59
docs/api/resources/resource-file-system/get.md
Normal file
59
docs/api/resources/resource-file-system/get.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# ResourceFileSystem::Get
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
static ResourceFileSystem& Get();
|
||||
```
|
||||
|
||||
## 所属类
|
||||
|
||||
`XCEngine::Resources::ResourceFileSystem`
|
||||
|
||||
## 描述
|
||||
|
||||
获取 `ResourceFileSystem` 的单例实例。该方法是获取全局资源文件系统的唯一入口。
|
||||
|
||||
## 参数
|
||||
|
||||
无
|
||||
|
||||
## 返回值
|
||||
|
||||
- `ResourceFileSystem&` - 单例实例的引用
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
#include "Resources/ResourceFileSystem.h"
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
|
||||
// 推荐用法:通过引用访问
|
||||
ResourceFileSystem& fs = ResourceFileSystem::Get();
|
||||
fs.Initialize("C:/Game/Resources");
|
||||
|
||||
// 多次调用返回相同实例
|
||||
ResourceFileSystem& fs2 = ResourceFileSystem::Get();
|
||||
assert(&fs == &fs2); // 相同地址
|
||||
|
||||
// 完整使用流程
|
||||
ResourceFileSystem& fs3 = ResourceFileSystem::Get();
|
||||
fs3.Initialize("C:/Game/Resources");
|
||||
fs3.AddDirectory("C:/Game/Assets");
|
||||
fs3.AddArchive("C:/Game/Paks/Common.pak");
|
||||
|
||||
if (fs3.Exists("textures/player/diffuse.png")) {
|
||||
auto data = fs3.ReadResource("textures/player/diffuse.png");
|
||||
// 处理数据
|
||||
}
|
||||
|
||||
// 程序结束时清理
|
||||
fs3.Shutdown();
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 内部使用局部静态变量实现单例
|
||||
- 第一次调用时自动构造实例
|
||||
- 线程安全(局部静态变量初始化线程安全)
|
||||
Reference in New Issue
Block a user