33 lines
958 B
Markdown
33 lines
958 B
Markdown
|
|
# ResourceManager::Load
|
|||
|
|
|
|||
|
|
```cpp
|
|||
|
|
template<typename T>
|
|||
|
|
ResourceHandle<T> Load(const Containers::String& path, ImportSettings* settings = nullptr)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
同步加载资源。模板方法,根据路径生成 GUID,先在缓存中查找是否已加载;若未加载则查找对应类型的加载器并同步加载,然后将结果加入缓存。
|
|||
|
|
|
|||
|
|
**参数:**
|
|||
|
|
- `path` - 资源路径
|
|||
|
|
- `settings` - 导入设置(可选)
|
|||
|
|
|
|||
|
|
**返回:** `ResourceHandle<T>`,持有加载的资源
|
|||
|
|
|
|||
|
|
**复杂度:** O(n),取决于加载器实现
|
|||
|
|
|
|||
|
|
**示例:**
|
|||
|
|
|
|||
|
|
```cpp
|
|||
|
|
ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("textures/player.png");
|
|||
|
|
ResourceHandle<Mesh> mesh = ResourceManager::Get().Load<Mesh>("models/player.fbx");
|
|||
|
|
ResourceHandle<Material> mat = ResourceManager::Get().Load<Material>("materials/player.mat");
|
|||
|
|
|
|||
|
|
if (tex.IsValid()) {
|
|||
|
|
// 使用纹理...
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 相关文档
|
|||
|
|
|
|||
|
|
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|