public void OnDownloadResources(List <string> lResources, Action downloaded, Action <float> progress = null)
 {
     UDebugHotLog.Log($"OnDownloadResources {string.Join(",", lResources)}");
     if (!Environment.UseAB)
     {
         downloaded?.Invoke();
         return;
     }
     if (dRemoteVersions.Count == 0)
     {
         OnDownloadText(Utils.GetPlatformFolder(Application.platform) + "/versions", (content) =>
         {
             var acontent = content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
             foreach (var c in acontent)
             {
                 var ac = c.Split('|');
                 if (ac.Length < 2)
                 {
                     continue;
                 }
                 if (!dRemoteVersions.ContainsKey(ac[0]))
                 {
                     dRemoteVersions.Add(ac[0], ac[1]);
                 }
             }
             DoCheckVersions(lResources, downloaded, progress);
         });
     }
     else
     {
         DoCheckVersions(lResources, downloaded, progress);
     }
 }
示例#2
0
    public WWW OnDownloadText(string resource, Action <string> downloadedAction, Action <string> errorAction = null)
    {
        if (!Environment.UseAB)
        {
            return(null);
        }
        var url = Utils.BaseURL_Res + resource + $".txt?{ApiDateTime.SecondsFromBegin()}";
        var www = new WWW(url);

        addUpdateAction(() =>
        {
            if (www.isDone)
            {
                if (string.IsNullOrEmpty(www.error))
                {
                    lDownloaded.Add(resource);
                    downloadedAction?.Invoke(www.text);
                }
                else
                {
                    UDebugHotLog.Log($"OnDownloadText {www.url} error {www.error}");
                    errorAction?.Invoke(www.error);
                }
                return(true);
            }
            return(false);
        });
        return(www);
    }
示例#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_Res + Utils.GetPlatformFolder(Application.platform) + resource;
        var www = new WWW(url);

        AOutput.Log($"Downloading {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
                {
                    UDebugHotLog.Log($"{url} error {www.error}");
                    errorAction?.Invoke(www.error);
                }
                return(true);
            }
            else
            {
                if (progressAction != null)
                {
                    progressAction(www.progress);
                }
                else
                {
                    UDebugHotLog.Log($"OnDownloadBytes process {www.progress}");
                    UILoading.Instance?.OnSetProgress(www.progress);
                }
            }
            return(false);
        });
        return(www);
    }
    private void DoCheckVersions(List <string> lResources, Action downloaded, Action <float> progress)
    {
        var lNeedDownload = new List <string>();

        foreach (var r in lResources)
        {
            var res = r.ToLower();
            if (!res.StartsWith("/"))
            {
                res = $"/{res}";
            }
            if (!res.EndsWith(UHotAssetBundleLoader.AssetBundleSuffix))
            {
                res = $"{res}{UHotAssetBundleLoader.AssetBundleSuffix}";
            }
            UDebugHotLog.Log($"check version res {res}");
            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);
                foreach (var dep in deps)
                {
                    var rdep = dep;
                    if (!dep.StartsWith("/"))
                    {
                        rdep = $"/{dep}";
                    }
                    if (!lNeedDownload.Contains(rdep))
                    {
                        if (!dRemoteVersions.ContainsKey(rdep))
                        {
                            continue;
                        }
                        file = ULocalFileManager.Instance.OnGetFile(rdep);
                        if (file == null || file.version != dRemoteVersions[rdep])
                        {
                            lNeedDownload.Add(rdep);
                        }
                    }
                }
            }
        }
        totalCount = lNeedDownload.Count;
        UDebugHotLog.Log($"totalCount {totalCount}");
        DoDownloadResources(lNeedDownload, downloaded, progress);
    }
示例#5
0
    public void SetGameObj(GameObject gameObj, string arg = "")
    {
        sinstance = this;

        if (arg.Equals("true", StringComparison.CurrentCultureIgnoreCase))
        {
            Environment.UseAB = true;
        }
        else if (arg.Equals("false", StringComparison.CurrentCultureIgnoreCase))
        {
            Environment.UseAB = false;
        }

        if (dGameObjects.ContainsKey(gameObj.name))
        {
            dGameObjects[gameObj.name] = gameObj;
        }
        else
        {
            dGameObjects.Add(gameObj.name, gameObj);
        }
        this.gameObj = gameObj;
        strArg       = arg;
        var r = this.gameObj.AddComponent <UEmitMessager>();

        curGame    = this;
        r.gameBase = this;
        r.OnRegistAction((msg) =>
        {
            onReceiveMsg?.Invoke(msg);

            var amsg = msg.Split(new char[] { ':' }, 2);
            switch (amsg[0])
            {
            case "op":
                receiveOpMsg(amsg[1] == "1");
                break;

            case "targetRuntime":
                Utils.TargetRuntimeInEditor = amsg[1];
                UDebugHotLog.Log($"Utils.TargetRuntimeInEditor {Utils.TargetRuntimeInEditor}");
                break;
            }
        });

        gameObj.AddComponent <UOnDestroy>().actionOnDestroy = () =>
        {
            OnDestroy();
        };

        InitComponents();
    }
示例#6
0
    public static T LoadClass <T>(string prefabPath) where T : AHotBase, new()
    {
        GameObject obj = UHotAssetBundleLoader.Instance.OnLoadAsset <GameObject>(prefabPath);

        if (obj == null)
        {
            UDebugHotLog.Log($"cannot find prefab {prefabPath}");
            return(null);
        }
        var t = new T();

        t.SetGameObj(GameObject.Instantiate(obj), "");
        return(t);
    }
示例#7
0
    public static T LoadUI <T>() where T : AHotBase, new()
    {
        var        path = "UI/" + typeof(T).Name;
        GameObject obj  = UHotAssetBundleLoader.Instance.OnLoadAsset <GameObject>(path);

        if (obj == null)
        {
            UDebugHotLog.Log($"cannot find prefab {path}");
            return(null);
        }
        var t = new T();

        t.SetGameObj(GameObject.Instantiate(obj), "");
        return(t);
    }
示例#8
0
    public static T LoadClass <T>(string prefabPath, Action <T> action = null, bool bCanNotAntoDestroy = false) where T : AHotBase, new()
    {
        GameObject obj = UHotAssetBundleLoader.Instance.OnLoadAsset <GameObject>(prefabPath);

        if (obj == null)
        {
            UDebugHotLog.Log($"cannot find prefab {prefabPath}");
            return(null);
        }
        var t = new T();

        t.SetGameObj(GameObject.Instantiate(obj), "");
        action?.Invoke(t);
        if (!bCanNotAntoDestroy)
        {
            loadedClasses.Add(t);
        }
        return(t);
    }
示例#9
0
    public void SetGameObj(GameObject gameObj, string arg = "")
    {
        sinstance = this;

        if (arg.Equals("true", StringComparison.CurrentCultureIgnoreCase))
        {
            Environment.UseAB = true;
        }
        else if (arg.Equals("false", StringComparison.CurrentCultureIgnoreCase))
        {
            Environment.UseAB = false;
        }
        UDebugHotLog.Log($"Environment.UseAB {Environment.UseAB} arg {arg}");

        if (dGameObjects.ContainsKey(gameObj.name))
        {
            dGameObjects[gameObj.name] = gameObj;
        }
        else
        {
            dGameObjects.Add(gameObj.name, gameObj);
        }
        this.gameObj = gameObj;
        strArg       = arg;
        var r = this.gameObj.AddComponent <UEmitMessager>();

        curGame    = this;
        r.gameBase = this;
        r.OnRegistAction((msg) =>
        {
            onReceiveMsg?.Invoke(msg);

            var amsg = msg.Split(':');
            switch (amsg[0])
            {
            case "op":
                receiveOpMsg(amsg[1] == "1");
                break;
            }
        });

        InitComponents();
    }
示例#10
0
    public static T LoadClass <T>(string prefabPath, Action <T> action = null) where T : AHotBase, new()
    {
        GameObject obj = UHotAssetBundleLoader.Instance.OnLoadAsset <GameObject>(prefabPath);

        if (obj == null)
        {
            UDebugHotLog.Log($"cannot find prefab {prefabPath}");
            return(null);
        }
        var t = new T();

        t.SetGameObj(GameObject.Instantiate(obj), "");
        action?.Invoke(t);
        if (t.bCanBeAutoClosed)
        {
            if (!loadedClasses.Contains(t))
            {
                loadedClasses.Add(t);
            }
        }
        return(t);
    }
示例#11
0
 public void OnSetJindu(string str)
 {
     UDebugHotLog.Log($"OnSetJindu [{str}]");
 }