64 lines
1.2 KiB
Markdown
64 lines
1.2 KiB
Markdown
|
|
# ResourceFileSystem::Exists
|
||
|
|
|
||
|
|
## 方法签名
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
bool Exists(const Containers::String& relativePath) const;
|
||
|
|
```
|
||
|
|
|
||
|
|
## 所属类
|
||
|
|
|
||
|
|
`XCEngine::Resources::ResourceFileSystem`
|
||
|
|
|
||
|
|
## 描述
|
||
|
|
|
||
|
|
检查指定相对路径的资源是否存在。该方法会搜索所有已注册的目录和档案。
|
||
|
|
|
||
|
|
此方法线程安全。
|
||
|
|
|
||
|
|
## 参数
|
||
|
|
|
||
|
|
| 参数名 | 类型 | 描述 |
|
||
|
|
|--------|------|------|
|
||
|
|
| `relativePath` | `const Containers::String&` | 资源的相对路径 |
|
||
|
|
|
||
|
|
## 返回值
|
||
|
|
|
||
|
|
- `bool` - 资源存在返回 `true`,不存在返回 `false`
|
||
|
|
|
||
|
|
## 示例
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
#include "Resources/ResourceFileSystem.h"
|
||
|
|
|
||
|
|
using namespace XCEngine::Resources;
|
||
|
|
|
||
|
|
ResourceFileSystem& fs = ResourceFileSystem::Get();
|
||
|
|
fs.Initialize("C:/Game/Resources");
|
||
|
|
fs.AddDirectory("C:/Game/Assets");
|
||
|
|
fs.AddArchive("C:/Game/Paks/Textures.pak");
|
||
|
|
|
||
|
|
// 检查各种资源是否存在
|
||
|
|
if (fs.Exists("textures/player/diffuse.png")) {
|
||
|
|
// 加载纹理
|
||
|
|
}
|
||
|
|
|
||
|
|
if (fs.Exists("shaders/forward.glsl")) {
|
||
|
|
// 加载着色器
|
||
|
|
}
|
||
|
|
|
||
|
|
if (fs.Exists("audio/bgm/main_theme.ogg")) {
|
||
|
|
// 加载音频
|
||
|
|
}
|
||
|
|
|
||
|
|
// 检查可能不存在的资源
|
||
|
|
if (!fs.Exists("textures/legacy/old_texture.png")) {
|
||
|
|
printf("Using default texture\n");
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
## 注意事项
|
||
|
|
|
||
|
|
- 内部调用 `FindResource` 实现
|
||
|
|
- 档案中的资源同样可以被检查
|