Files
XCEngine/docs/api/resources/iresource/iresource.md
ssdfasd dc850d7739 docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
  - math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
  - containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
  - core: 修复 types 链接错误
  - debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
  - memory: 修复头文件路径, malloc vs operator new, 新增方法文档
  - resources: 修复 Shader/Texture 链接错误
  - threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00

81 lines
2.6 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)
**描述**: 资源基类接口所有具体资源类型Texture、Mesh、Material 等)都必须继承自此类。
## 概述
`IResource` 是 XCEngine 资源管理系统的核心抽象基类。它定义了所有资源共有的基本属性和行为包括资源类型、名称、路径、GUID、内存大小和有效性状态。
## 公共方法
### 基础属性
| 方法 | 描述 |
|------|------|
| `ResourceType GetType() const` | 获取资源类型 |
| `const Containers::String& GetName() const` | 获取资源名称 |
| `const Containers::String& GetPath() const` | 获取资源路径 |
| `ResourceGUID GetGUID() const` | 获取全局唯一标识符 |
| `bool IsValid() const` | 检查资源是否有效 |
| `size_t GetMemorySize() const` | 获取资源占用的内存大小(字节) |
### 生命周期
| 方法 | 描述 |
|------|------|
| `void Release()` | 释放资源引用 |
### 构造参数
```cpp
struct ConstructParams {
Containers::String name; // 资源名称
Containers::String path; // 资源路径
ResourceGUID guid; // 全局唯一标识符
size_t memorySize = 0; // 内存大小
};
```
### 初始化方法
| 方法 | 描述 |
|------|------|
| `void Initialize(const ConstructParams& params)` | 使用构造参数初始化资源 |
| `void SetInvalid()` | 将资源标记为无效 |
## 公共成员
| 成员 | 类型 | 描述 |
|------|------|------|
| `m_name` | `Containers::String` | 资源名称 |
| `m_path` | `Containers::String` | 资源路径 |
| `m_guid` | `ResourceGUID` | 全局唯一标识符 |
| `m_isValid` | `bool` | 资源是否有效 |
| `m_memorySize` | `size_t` | 内存占用大小 |
## 使用示例
```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 { /* 释放逻辑 */ }
};
```
## 相关文档
- [ResourceHandle](../resourcehandle/resourcehandle.md) - 资源句柄
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
- [ResourceTypes](../resourcetypes/resourcetypes.md) - 资源类型定义
- [Resources 总览](../resources.md) - 返回模块总览