32 Star 227 Fork 40

GVPI++俱乐部/Dora-SSR

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Cache.mdx 4.57 KB
一键复制 编辑 原始数据 按行查看 历史
Li Jin 提交于 2025-01-06 16:24 +08:00 . Fixed doc site prismjs language adding. [skip CI]
# Cache
**Description:**
  A singleton cache instance for various game resources.
## Cache.ResourceType
**Type:** Enumeration.
**Description:**
  An enum that defines the various types of resources that can be loaded into the cache.
**Signature:**
```tl
enum ResourceType
"Bone"
"Spine"
"Texture"
"SVG"
"Clip"
"Frame"
"Model"
"Particle"
"Shader"
"Font"
"Sound"
end
```
## Cache.ResourceTypeSafeUnload
**Type:** Enumeration.
**Description:**
  An enum that defines the various types of resources that can be safely unloaded from the cache.
**Signature:**
```tl
enum ResourceTypeSafeUnload
"Texture"
"SVG"
"Clip"
"Frame"
"Model"
"Particle"
"Shader"
"Font"
"Sound"
"Spine"
end
```
## load
**Type:** Function.
**Description:**
  Loads a file into the cache with a blocking operation.
**Signature:**
```tl
load: function(self: Cache, filename: string): boolean
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| filename | string | The name of the file to load. |
**Returns:**
| Return Type | Description |
| --- | --- |
| boolean | True if the file was loaded successfully, false otherwise. |
## loadAsync
**Type:** Function.
**Description:**
  Loads a file into the cache asynchronously.
**Signature:**
```tl
loadAsync: function(self: Cache, filename: string | {string}, handler?: function(progress: number)): boolean
```
**Usage:**
```tl
thread(function()
local success = Cache:loadAsync("file.png")
if success then
print("Game resource is loaded into memory")
end
end)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| filenames | string | \{string} | The name of the file(s) to load. |
| handler | function | [optional] A callback function that is invoked when the file is loaded. The progress parameter is a number between 0 and 1. |
**Returns:**
| Return Type | Description |
| --- | --- |
| boolean | True if the files were loaded successfully, false otherwise. |
## update
**Type:** Function.
**Description:**
  Updates the content of a file loaded in the cache.
If the item of filename does not exist in the cache, a new file content will be added into the cache.
**Signature:**
```tl
update: function(self: Cache, filename: string, content: string)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| filename | string | The name of the file to update. |
| content | string | The new content for the file. |
## update
**Type:** Function.
**Description:**
  Updates the texture object of the specific filename loaded in the cache.
If the texture object of filename does not exist in the cache, it will be added into the cache.
**Signature:**
```tl
update: function(self: Cache, filename: string, texture: Texture2D)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| filename | string | The name of the texture to update. |
| texture | Texture2D | The new texture object for the file. |
## unload
**Type:** Function.
**Description:**
  Unloads a resource from the cache.
**Signature:**
```tl
unload: function(self: Cache, type: ResourceTypeSafeUnload): boolean
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| type | ResourceTypeSafeUnload | The type of resource to unload. |
**Returns:**
| Return Type | Description |
| --- | --- |
| boolean | True if the resource was unloaded successfully, false otherwise. |
## unload
**Type:** Function.
**Description:**
  Unloads a resource from the cache.
**Signature:**
```tl
unload: function(self: Cache, filename: string): boolean
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| filename | string | The name of the file to unload. |
**Returns:**
| Return Type | Description |
| --- | --- |
| boolean | True if the resource was unloaded successfully, false otherwise. |
## unload
**Type:** Function.
**Description:**
  Unloads all resources from the cache.
**Signature:**
```tl
unload: function(self: Cache)
```
## removeUnused
**Type:** Function.
**Description:**
  Removes all unused resources (not being referenced) of the given type from the cache.
**Signature:**
```tl
removeUnused: function(self: Cache, type: ResourceType)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| type | ResourceType | The type of resource to remove. |
## removeUnused
**Type:** Function.
**Description:**
  Removes all unused resources (not being referenced) from the cache.
**Signature:**
```tl
removeUnused: function(self: Cache)
```
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/ippclub/Dora-SSR.git
git@gitee.com:ippclub/Dora-SSR.git
ippclub
Dora-SSR
Dora-SSR
main

搜索帮助