Files
XCEngine/docs/api/resources/resourcemanager/loadasync.md

45 lines
1.2 KiB
Markdown
Raw Normal View History

# ResourceManager::LoadAsync
```cpp
void LoadAsync(const Containers::String& path, ResourceType type,
std::function<void(LoadResult)> callback)
void LoadAsync(const Containers::String& path, ResourceType type,
ImportSettings* settings, std::function<void(LoadResult)> callback)
```
异步加载资源。将加载请求提交到 `AsyncLoader`,在后台工作线程执行加载,完成后在主线程通过回调通知。
**参数:**
- `path` - 资源路径
- `type` - 资源类型
- `settings` - 导入设置(可为 nullptr
- `callback` - 加载完成回调
**返回:** 无
**复杂度:** 提交 O(1),实际加载 O(n)
**示例:**
```cpp
ResourceManager::Get().LoadAsync("textures/terrain.png", ResourceType::Texture,
[](LoadResult result) {
if (result.success) {
ResourceHandle<Texture> tex(result.resource);
printf("Loaded: %s\n", tex->GetPath().CStr());
}
});
ResourceManager::Get().LoadAsync("models/player.fbx", ResourceType::Mesh,
nullptr,
[](LoadResult result) {
if (result.success) {
ResourceHandle<Mesh> mesh(result.resource);
}
});
```
## 相关文档
- [ResourceManager 总览](resourcemanager.md) - 返回类总览