Files
XCEngine/docs/api/resources/iresource/iresource.md

56 lines
2.0 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.
# IResource
**命名空间**: `XCEngine::Resources`
**类型**: `class` (abstract)
**头文件**: `XCEngine/Resources/IResource.h`
**描述**: 资源基类接口所有具体资源类型Texture、Mesh、Material 等)都必须继承自此类。
## 概述
`IResource` 是 XCEngine 资源管理系统的核心抽象基类。它定义了所有资源共有的基本属性和行为包括资源类型、名称、路径、GUID、内存大小和有效性状态。
## 公共方法
| 方法 | 描述 |
|------|------|
| [`GetType()`](gettype.md) | 获取资源类型 |
| [`GetName()`](getname.md) | 获取资源名称 |
| [`GetPath()`](getpath.md) | 获取资源路径 |
| [`GetGUID()`](getguid.md) | 获取全局唯一标识符 |
| [`IsValid()`](isvalid.md) | 检查资源是否有效 |
| [`GetMemorySize()`](getmemorysize.md) | 获取资源占用的内存大小(字节) |
| [`Release()`](release.md) | 释放资源引用 |
| [`Initialize()`](initialize.md) | 使用构造参数初始化资源 |
| [`SetInvalid()`](setinvalid.md) | 将资源标记为无效 |
### 构造参数结构体 `ConstructParams`
| 成员 | 类型 | 描述 |
|------|------|------|
| `name` | `Containers::String` | 资源名称 |
| `path` | `Containers::String` | 资源路径 |
| `guid` | `ResourceGUID` | 全局唯一标识符 |
| `memorySize` | `size_t` | 内存占用大小(字节),默认 0 |
## 使用示例
```cpp
class MyResource : public IResource {
public:
ResourceType GetType() const override { return ResourceType::Custom; }
const Containers::String& GetName() const override { return m_name; }
const Containers::String& GetPath() const override { return m_path; }
ResourceGUID GetGUID() const override { return m_guid; }
bool IsValid() const override { return m_isValid; }
size_t GetMemorySize() const override { return m_memorySize; }
void Release() override { /* 释放逻辑 */ }
};
```
## 相关文档
- [Resources 总览](../resources.md) - 返回模块总览