yeah2569 / UnityHttpService

基于Unity的Http服务,完全封装UnityWebRequest,可以快速便捷的Get,Post,下载文件,下载图片等功能

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HttpService

联系作者:419731519(QQ)

============HttpService介绍============

基于UnityWebRequest的基础上,封装了多个Http的异步接口

使得可以非常方便的使用Get,Post,DownloadFile,DownloadSprite

觉得我的插件能帮助到你,麻烦帮我点个Star支持一下❤️

=================使用方法=================

  • manifest.json中添加插件路径
{
  "dependencies": {
	"com.leeframework.httpservice":"https://e.coding.net/ggdevlee/leeframework/HttpService.git#1.0.4"
  }
}
  • 引入命名空间
using LeeFramework.Http;
  • Get
HttpSvc.instance.Get("http:", (cb) =>
 {
	 if (cb.isError)
	 {
		 Debug.Log(cb.errorMsg);
		 return;
	 }
	 Debug.Log(cb.json);
 });
  • Post
HttpSvc.instance.Post("http:", (cb) =>
{
	if (cb.isError)
	{
		Debug.Log(cb.errorMsg);
		return;
	}
	Debug.Log(cb.json);
}, "key", "json");
  • DownloadFile
HttpSvc.instance.DownloadFile("https:", (value) =>
{
    HttpFileCb fileCb = value;

    if (!fileCb.isError)
    {
        File.WriteAllBytes(Application.dataPath + "/../aaa.png", fileCb.data);
    }
    else
    {
        Debug.LogError(fileCb.errorMsg);
    }
});
  • DownloadSprite
HttpSvc.instance.DownloadSprite("https:", (value) =>
{
     HttpSpriteCb spriteCb = value;
    
     if (!spriteCb.isError)
     {
         img.sprite = spriteCb.sprite;
     }
     else
     {
         Debug.LogError(spriteCb.errorMsg);
     }
});
  • 创建文件下载任务
DownloadFileItem item = HttpSvc.instance.DownloadFailTask("https://", (value) =>
{
    HttpFileCb fileCb = value;
    
    if (!fileCb.isError)
    {
      File.WriteAllBytes(Application.dataPath + "/../aaa.png", fileCb.data);
    }
    else
    {
      Debug.LogError(fileCb.errorMsg);
    }
});

//item Todo

item.StartDownload();
  • 创建图片下载任务
DownloadSpriteItem sprite = HttpSvc.instance.DownloadSpriteTask("https://", (value) =>
{
    HttpSpriteCb spriteCb = value;

    if (!spriteCb.isError)
    {
        img.sprite = spriteCb.sprite;
    }
    else
    {
        Debug.LogError(spriteCb.errorMsg);
    }
});

//item Todo

sprite.StartDownload();

About

基于Unity的Http服务,完全封装UnityWebRequest,可以快速便捷的Get,Post,下载文件,下载图片等功能

License:MIT License


Languages

Language:C# 100.0%