{"id":21358871,"url":"https://github.com/gameframex/com.gameframex.unity.download","last_synced_at":"2025-09-10T14:41:17.247Z","repository":{"id":232506389,"uuid":"784515319","full_name":"GameFrameX/com.gameframex.unity.download","owner":"GameFrameX","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-21T15:35:36.000Z","size":56,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-22T18:51:07.493Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GameFrameX.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-10T02:03:15.000Z","updated_at":"2024-09-21T15:35:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"5b23b263-9b14-46f9-b12d-8d327f2ceeb5","html_url":"https://github.com/GameFrameX/com.gameframex.unity.download","commit_stats":null,"previous_names":["alianblank/com.alianblank.gameframex.unity.download","gameframex/com.gameframex.unity.download"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GameFrameX%2Fcom.gameframex.unity.download","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GameFrameX%2Fcom.gameframex.unity.download/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GameFrameX%2Fcom.gameframex.unity.download/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GameFrameX%2Fcom.gameframex.unity.download/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GameFrameX","download_url":"https://codeload.github.com/GameFrameX/com.gameframex.unity.download/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830950,"owners_count":20354856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T05:22:42.788Z","updated_at":"2025-03-16T06:17:59.242Z","avatar_url":"https://github.com/GameFrameX.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿## HOMEPAGE\n\nGameFrameX 的 Download 下载任务组件\n\n**Download 下载任务组件 (Download Component)** - 提供管理下载队列、处理下载任务，并提供下载状态的实时更新。相关的接口。\n\n# 使用文档(文档编写于GPT4)\n\n`DownloadComponent` 是一个用于处理下载任务的游戏框架组件。它负责管理下载队列、处理下载任务，并提供下载状态的实时更新。\n\n## 功能概述\n\n- 管理多个下载任务\n- 支持断点续传功能\n- 提供下载任务的优先级设置\n- 实时更新下载进度和下载速度\n- 可以通过事件接收下载的各个阶段状态\n\n## 基础用法\n\n要开始使用 `DownloadComponent`，需要在游戏对象上添加此组件。以下是一些核心属性的解释：\n\n- `Paused`: 获取或设置下载是否被暂停。\n- `TotalAgentCount`: 获取下载代理总数量。\n- `FreeAgentCount`: 获取可用下载代理数量。\n- `WorkingAgentCount`: 获取工作中下载代理数量。\n- `WaitingTaskCount`: 获取等待下载任务数量。\n- `Timeout`: 获取或设置下载超时时长。\n- `FlushSize`: 获取或设置写入磁盘的临界大小。\n- `CurrentSpeed`: 获取当前下载速度。\n\n## 如何增加下载任务\n\n以下是添加下载任务的几种方法：\n\n```csharp\n// 根据指定的下载路径和URI增加下载任务\npublic int AddDownload(string downloadPath, string downloadUri);\n\n// 根据指定的下载路径、URI和任务标签增加下载任务\npublic int AddDownload(string downloadPath, string downloadUri, string tag);\n\n// 根据指定的下载路径、URI和优先级增加下载任务\npublic int AddDownload(string downloadPath, string downloadUri, int priority);\n\n// 根据指定的下载路径、URI和用户自定义数据增加下载任务\npublic int AddDownload(string downloadPath, string downloadUri, object userData);\n```\n\n## 如何移除下载任务\n\n可以通过任务的序列编号或者标签来移除下载任务：\n\n```csharp\n// 根据序列编号移除下载任务\npublic bool RemoveDownload(int serialId);\n\n// 根据标签移除下载任务\npublic int RemoveDownloads(string tag);\n\n// 移除所有下载任务\npublic int RemoveAllDownloads();\n```\n\n## 事件通知\n\n`DownloadComponent` 提供事件，以便于当下载任务开始、更新、成功、失败时接收通知。\n\n- `DownloadStart`: 当下载开始时触发。\n- `DownloadUpdate`: 当下载更新时触发。\n- `DownloadSuccess`: 当下载成功时触发。\n- `DownloadFailure`: 当下载失败时触发。\n\n## 初始化\n\n组件初始化时，它会设置其内部管理器，并为每个下载代理辅助器注册相应的事件。\n\n```csharp\nprotected override void Awake()\n{\n    base.Awake();\n    // ...初始化代码...\n}\n```\n\n## 示例\n\n要添加一个新的下载任务并接收其进度：\n\n```csharp\n// 假设已经存在 downloadComponent 实例\nint serialId = downloadComponent.AddDownload(\"本地存储路径\", \"下载链接\");\n\n// 通过事件组件订阅下载成功事件\neventComponent.Subscribe(DownloadSuccessEventArgs.EventId, OnDownloadSuccess);\n\n// 下载成功回调\nvoid OnDownloadSuccess(object sender, GameEventArgs e)\n{\n    DownloadSuccessEventArgs ne = (DownloadSuccessEventArgs)e;\n    if (ne.SerialId == serialId)\n    {\n        // 处理下载成功\n    }\n}\n```\n\n注意：此组件依赖于Event 组件：https://github.com/AlianBlank/com.gameframex.unity.event\n\n# 使用方式(任选其一)\n\n1. 直接在 `manifest.json` 的文件中的 `dependencies` 节点下添加以下内容\n   ```json\n   {\n      \"com.gameframex.unity.event\": \"https://github.com/AlianBlank/com.gameframex.unity.event.git\",\n      \"com.gameframex.unity.download\": \"https://github.com/AlianBlank/com.gameframex.unity.download.git\"\n   }\n    ```\n2. 在Unity 的`Packages Manager` 中使用`Git URL` 的方式添加库,地址为：https://github.com/AlianBlank/com.gameframex.unity.download.git,\n\n3. 直接下载仓库放置到Unity 项目的`Packages` 目录下。会自动加载识别","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgameframex%2Fcom.gameframex.unity.download","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgameframex%2Fcom.gameframex.unity.download","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgameframex%2Fcom.gameframex.unity.download/lists"}