Giter VIP home page Giter VIP logo

com.alianblank.gameframex.unity.download's Introduction

HOMEPAGE

GameFrameX 的 Download 下载任务组件

Download 下载任务组件 (Download Component) - 提供管理下载队列、处理下载任务,并提供下载状态的实时更新。相关的接口。

使用文档(文档编写于GPT4)

DownloadComponent 是一个用于处理下载任务的游戏框架组件。它负责管理下载队列、处理下载任务,并提供下载状态的实时更新。

功能概述

  • 管理多个下载任务
  • 支持断点续传功能
  • 提供下载任务的优先级设置
  • 实时更新下载进度和下载速度
  • 可以通过事件接收下载的各个阶段状态

基础用法

要开始使用 DownloadComponent,需要在游戏对象上添加此组件。以下是一些核心属性的解释:

  • Paused: 获取或设置下载是否被暂停。
  • TotalAgentCount: 获取下载代理总数量。
  • FreeAgentCount: 获取可用下载代理数量。
  • WorkingAgentCount: 获取工作中下载代理数量。
  • WaitingTaskCount: 获取等待下载任务数量。
  • Timeout: 获取或设置下载超时时长。
  • FlushSize: 获取或设置写入磁盘的临界大小。
  • CurrentSpeed: 获取当前下载速度。

如何增加下载任务

以下是添加下载任务的几种方法:

// 根据指定的下载路径和URI增加下载任务
public int AddDownload(string downloadPath, string downloadUri);

// 根据指定的下载路径、URI和任务标签增加下载任务
public int AddDownload(string downloadPath, string downloadUri, string tag);

// 根据指定的下载路径、URI和优先级增加下载任务
public int AddDownload(string downloadPath, string downloadUri, int priority);

// 根据指定的下载路径、URI和用户自定义数据增加下载任务
public int AddDownload(string downloadPath, string downloadUri, object userData);

如何移除下载任务

可以通过任务的序列编号或者标签来移除下载任务:

// 根据序列编号移除下载任务
public bool RemoveDownload(int serialId);

// 根据标签移除下载任务
public int RemoveDownloads(string tag);

// 移除所有下载任务
public int RemoveAllDownloads();

事件通知

DownloadComponent 提供事件,以便于当下载任务开始、更新、成功、失败时接收通知。

  • DownloadStart: 当下载开始时触发。
  • DownloadUpdate: 当下载更新时触发。
  • DownloadSuccess: 当下载成功时触发。
  • DownloadFailure: 当下载失败时触发。

初始化

组件初始化时,它会设置其内部管理器,并为每个下载代理辅助器注册相应的事件。

protected override void Awake()
{
    base.Awake();
    // ...初始化代码...
}

示例

要添加一个新的下载任务并接收其进度:

// 假设已经存在 downloadComponent 实例
int serialId = downloadComponent.AddDownload("本地存储路径", "下载链接");

// 通过事件组件订阅下载成功事件
eventComponent.Subscribe(DownloadSuccessEventArgs.EventId, OnDownloadSuccess);

// 下载成功回调
void OnDownloadSuccess(object sender, GameEventArgs e)
{
    DownloadSuccessEventArgs ne = (DownloadSuccessEventArgs)e;
    if (ne.SerialId == serialId)
    {
        // 处理下载成功
    }
}

注意:此组件依赖于Event 组件:https://github.com/AlianBlank/com.alianblank.gameframex.unity.event

使用方式(任选其一)

  1. 直接在 manifest.json 的文件中的 dependencies 节点下添加以下内容

    {
       "com.alianblank.gameframex.unity.event": "https://github.com/AlianBlank/com.alianblank.gameframex.unity.event.git",
       "com.alianblank.gameframex.unity.download": "https://github.com/AlianBlank/com.alianblank.gameframex.unity.download.git"
    }
  2. 在Unity 的Packages Manager 中使用Git URL 的方式添加库,地址为:https://github.com/AlianBlank/com.alianblank.gameframex.unity.download.git,

  3. 直接下载仓库放置到Unity 项目的Packages 目录下。会自动加载识别

com.alianblank.gameframex.unity.download's People

Contributors

alianblank avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.