예제 #1
0
    public static void CreateDebugObject(object obj)
    {
        if (!Logger.IsEditor || !Application.isPlaying || IsApplicationQuited)
        {
            return;
        }

        KAsync.AddMainThreadCall(() =>
        {
            try
            {
                var newDebugger =
                    new GameObject(string.Format("{0}-{1}", obj.ToString(), obj.GetType()))
                    .AddComponent <KObjectDebugger>();
                newDebugger.WatchObject = obj;

                KDebuggerObjectTool.SetParent(ContainerName, obj.GetType().Name, newDebugger.gameObject);

                Cache[obj] = newDebugger;
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
            }
        });
    }
예제 #2
0
 public void RelaseAtlasLoader()
 {
     KAsync.Start().WaitForSeconds(5).Then(() =>
     {
         atlasLoader.Release(true);
         Destroy(targetImage);
         KResourceModule.Collect();
     });
 }
예제 #3
0
    public void RelaseSpriteLoader()
    {
        KAsync.Start().WaitForSeconds(5).Then(() =>
        {
            foreach (KeyValuePair <string, AssetBundleLoader> keyValuePair in spriteLoaders)
            {
                keyValuePair.Value.Release(true);
            }

            Destroy(targetImage);
            KResourceModule.Collect();
        });
    }
예제 #4
0
    public static void RemoveDebugObject(object obj)
    {
        if (!Logger.IsEditor || !Application.isPlaying || IsApplicationQuited)
        {
            return;
        }

        KAsync.AddMainThreadCall(() =>
        {
            try
            {
                KObjectDebugger debuger;
                if (KObjectDebugger.Cache.TryGetValue(obj, out debuger))
                {
                    GameObject.Destroy(debuger.gameObject);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
            }
        });
    }
예제 #5
0
    IEnumerator StartUpdate()
    {
        //更新下载进度
        var loadingPanel = UIModule.Instance.GetOrCreateUI <LoadingPanel>();

        loadingPanel.DisPlay(true);

        var appDataPath = KResourceModule.AppDataPath;
        //TODO 是否所有资源都下载成功
        var total = downloadFiles.Count;

        for (int i = 0; i < total; i++)
        {
            yield return(Game.Instance.StartCoroutine(DownloadItem(downloadFiles[i], appDataPath)));
        }

        Log.LogToFile(total > 0 ? "下载更新资源完成" : "本次无需下载新资源");
        try
        {
            //更新filelist
            if (filelistBuilder.Length > 0)
            {
                var dirName = Path.GetDirectoryName(appDataPath + AppConfig.FilelistPath);
                if (Directory.Exists(dirName) == false)
                {
                    Directory.CreateDirectory(dirName);
                }
                File.WriteAllText(appDataPath + AppConfig.FilelistPath, filelistBuilder.ToString());
                Log.LogToFile("filelist更新完成");
            }
            else
            {
                Log.LogToFile("本次filelist无需更新");
            }

            //更新version
            if (versionBuilder.Length > 0)
            {
                if (filelistVersion == null)
                {
                    Log.LogError("更新version.txt中的filelist.txt version 失败,data is null");
                }
                if (filelistVersion != null)
                {
                    versionBuilder.AppendLine(filelistVersion.ToFilelistFormat());
                }
                var dirName = Path.GetDirectoryName(appDataPath + AppConfig.VersionTxtName);
                if (Directory.Exists(dirName) == false)
                {
                    Directory.CreateDirectory(dirName);
                }
                File.WriteAllText(appDataPath + AppConfig.VersionTxtName, versionBuilder.ToString());
                Log.LogToFile("version更新完成");
            }
            else
            {
                Log.LogToFile("本次version无需更新");
            }
        }
        catch (Exception e)
        {
            Log.LogError($"保存filelist出错,{e.Message}");
            ErrorType = UpdateErrorType.DownloadError;
        }

        //解压可以放在多线程中
        loadingPanel.SetProgress(I18N.Get("download_unpackzip"));
        bool waitLua = true, waitSetting = true;

        if (needUnpackLua)
        {
            KAsync.Start().Thread(() => UnpackZip(appDataPath + "/lua.zip", appDataPath + "/Lua/", () => waitLua = false));
        }
        else
        {
            waitLua = false;
        }

        if (needUnpackSetting)
        {
            KAsync.Start().Thread(() => UnpackZip(appDataPath + "/setting.zip", appDataPath + "/Setting/", () => waitSetting = false));
        }
        else
        {
            waitSetting = false;
        }

        loadingPanel = UIModule.Instance.GetExistUI <LoadingPanel>();
        loadingPanel?.SetFixProgress(1 - zipPercent, 1.0f);
        WaitForSeconds wait = new WaitForSeconds(0.05f);

        while (waitLua || waitSetting)
        {
            loadingPanel?.UpdateFixedProgress();
            yield return(wait);
        }

        DownloadFinish = true;
        if (needUnpackLua || needUnpackSetting)
        {
            Log.LogToFile("解压更新资源完成");
        }
        ClearData();
    }