コード例 #1
0
    private WWW OnDownloadText(string resource, Action <string> downloadedAction, Action <string> errorAction = null)
    {
        if (!Environment.UseAB)
        {
            return(null);
        }
        var url = Utils.BaseURL + resource + ".txt";
        var www = new WWW(url);

        addUpdateAction(() =>
        {
            if (www.isDone)
            {
                if (string.IsNullOrEmpty(www.error))
                {
                    lDownloaded.Add(resource);
                    downloadedAction?.Invoke(www.text);
                }
                else
                {
                    UHotLog.Log($"{www.url} error {www.error}");
                    errorAction?.Invoke(www.error);
                }
                return(true);
            }
            return(false);
        });
        return(www);
    }
コード例 #2
0
    private void DoCheckVersions(List <string> lResources, Action downloaded, Action <float> progress)
    {
        var lNeedDownload = new List <string>();

        foreach (var r in lResources)
        {
            var res = r;
            if (!res.StartsWith("/"))
            {
                res = $"/{r}";
            }
            if (!dRemoteVersions.ContainsKey(res))
            {
                continue;
            }
            var file = ULocalFileManager.Instance.OnGetFile(res);
            if (file == null || file.version != dRemoteVersions[res])
            {
                lNeedDownload.Add(res);
            }
            if (res.EndsWith(AssetBundleSuffix))
            {
                var deps = OnGetAssetBundleDependeces(res);
                UHotLog.Log($"{res} has {deps.Length} deps");
                foreach (var dep in deps)
                {
                    if (!lNeedDownload.Contains(dep))
                    {
                        var rdep = dep;
                        if (!dep.StartsWith("/"))
                        {
                            rdep = $"/{dep}";
                        }
                        if (!dRemoteVersions.ContainsKey(rdep))
                        {
                            UHotLog.Log($"Cannot find {rdep} remote version");
                            continue;
                        }
                        file = ULocalFileManager.Instance.OnGetFile(rdep);
                        if (file == null || file.version != dRemoteVersions[rdep])
                        {
                            lNeedDownload.Add(rdep);
                        }
                    }
                }
            }
        }
        DoDownloadResources(lNeedDownload, downloaded, progress);
    }
コード例 #3
0
    private WWW OnDownloadBytes(string resource
                                , string version
                                , Action <string> downloadedAction
                                , Action <string> errorAction   = null
                                , Action <float> progressAction = null
                                )
    {
        if (!Environment.UseAB)
        {
            return(null);
        }
        var url = Utils.BaseURL + Utils.GetPlatformFolder(Application.platform) + resource;
        var www = new WWW(url);

        addUpdateAction(() =>
        {
            if (www.isDone)
            {
                progressAction?.Invoke(1);
                if (string.IsNullOrEmpty(www.error))
                {
                    var filepath = Utils.ConfigSaveDir + resource;
                    var fi       = new FileInfo(filepath);
                    if (!fi.Directory.Exists)
                    {
                        fi.Directory.Create();
                    }
                    File.WriteAllBytes(filepath, www.bytes);
                    ULocalFileManager.Instance.OnAddFile(resource, version);
                    downloadedAction?.Invoke(resource);
                }
                else
                {
                    UHotLog.Log($"{url} error {www.error}");
                    errorAction?.Invoke(www.error);
                }
                return(true);
            }
            else
            {
                progressAction?.Invoke(www.progress);
            }
            return(false);
        });
        return(www);
    }