/// <summary>
    /// 存储热更资源并记录热更资源信息
    /// </summary>
    /// <param name="resname">资源名</param>
    /// <param name="resversion">资源版本号</param>
    /// <param name="data">资源二进制数据</param>
    private void saveHotResourceUpdate(string resname, int resversion, byte[] data)
    {
        //检查包外是否存在同名资源,存在的话需要先删除再存储最新到包外
        var resfullpath = AssetBundlePath.ABHotUpdatePath + resname;

        if (AssetBundlePath.IsABExitInOutterPath(resname))
        {
            Debug.Log(string.Format("删除包外资源 : {0}", resname));
            File.Delete(resfullpath);
        }
        File.WriteAllBytes(resfullpath, data);

        if (!File.Exists(LocalResourceUpdateListFilePath))
        {
            Debug.Log(string.Format("创建文件 : {0}", LocalResourceUpdateListFilePath));
            using (var fs = File.Create(LocalResourceUpdateListFilePath))
            {
                fs.Close();
            }
        }
        using (var sw = File.AppendText(LocalResourceUpdateListFilePath))
        {
            sw.WriteLine(resversion + ":" + resname);
            sw.Close();
        }
        Debug.Log(string.Format("写入已更资源 : {0}", resfullpath));
    }
Esempio n. 2
0
    /// <summary>
    /// 资源请求携程
    /// </summary>
    /// <returns></returns>
    private IEnumerator resourcesRequest()
    {
        foreach (var hotupdateres in mTestHotUpdateResourceList)
        {
            var resurl = TestResourceURL + hotupdateres;
            ResourceLogger.log(string.Format("下载资源 : {0}", resurl));
            var webrequest = UnityWebRequest.Get(resurl);
            yield return(webrequest.SendWebRequest());

            if (webrequest.isNetworkError)
            {
                ResourceLogger.logErr(string.Format("{0}资源下载出错!", hotupdateres));
                ResourceLogger.logErr(webrequest.error);
            }
            else
            {
                if (webrequest.isDone)
                {
                    ResourceLogger.log(string.Format("{0}资源下载完成!", hotupdateres));
                    var data = webrequest.downloadHandler.data;
                    //检查包外是否存在同名资源,存在的话需要先删除再存储最新到包外
                    var outterabfullpath = AssetBundlePath.ABHotUpdatePath + hotupdateres;
                    if (AssetBundlePath.IsABExitInOutterPath(hotupdateres))
                    {
                        ResourceLogger.log(string.Format("删除包外资源 : {0}", hotupdateres));
                        File.Delete(outterabfullpath);
                    }
                    using (var fs = File.Create(outterabfullpath))
                    {
                        fs.Write(data, 0, data.Length);
                        fs.Flush();
                        fs.Close();
                        ResourceLogger.log(string.Format("包外资源 : {0}写入完成!", hotupdateres));
                    }
                }
            }
        }
    }