使用HttpRequse 网络下载资源

  public Slider sli;
    public Text text;

    void Start()
    {
        DownHttpAsset("https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup.exe?_ga=2.83766486.1322120331.1539929050-293855835.1523070836&tdsourcetag=s_pcqq_aiomsg");
    }

    /// 
    /// 下载 进度条
    /// 
    /// 下载的路径
    void DownHttpAsset(string str)
    {
        HTTPRequest httpRequest = new HTTPRequest(new Uri(str), (req, rop) => { });
        httpRequest.OnProgress += Down_Http;
        //关闭缓存
        httpRequest.DisableCache = true;
        //控制等待客户端和服务端建立连接的时间,默认20s
        httpRequest.ConnectTimeout = TimeSpan.FromSeconds(2);
        //设置等待请求处理的时间
        httpRequest.Timeout = TimeSpan.FromSeconds(10);
        httpRequest.Send();
    }
    void Down_Http(HTTPRequest originalRequest, int downloaded, int downloadLength)
    {
        float downFloat = (downloaded / (float)downloadLength) * 100.0f;
        sli.value = downFloat / 100.0f;
        text.text = "已下载:" + downFloat.ToString("F1") + "%";

        #region   
       //当Slider.value 等于1 的时候
        if (sli.value == 1)
        {
            //打开指定的网址
            Application.OpenURL("https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup.exe?_ga=2.83766486.1322120331.1539929050-293855835.1523070836&tdsourcetag=s_pcqq_aiomsg");
            text.text = "加载完成";
        }
        #endregion
    }

 

 

 

 

 

 

你可能感兴趣的:(HttpRequse,HttpRequse,c#,网络,下载)