using System.IO; using System.Linq; using UnityEngine.Events; using System.Text.RegularExpressions; using Application = UnityEngine.Application; #if UNITY_EDITOR #endif namespace ZooMatch { public class ZooMatchFileKit { private static bool isLog = true; private static string AssetBundleRootUrl = Application.streamingAssetsPath + "/ZooMatchAssets/AssetBundles/"; private static string mFileUrl = Application.streamingAssetsPath + "/ZooMatchAssets/ZooMatchFile.txt"; public static string ConfigFileUrl = Application.streamingAssetsPath + "/Config/JarvisConfigFile.txt"; public static string GetSavePath() { return Application.persistentDataPath; } public static string GetLocalSavePath() { return Application.streamingAssetsPath; } public static string GetFilePath() { return $"{GetSavePath()}/ZooMatchAssets/"; } public static void GetLocalAssetBundle(UnityAction onPreloadCompleted, UnityAction loadCompleted) { GetAssetFile(s => { GetMAssetBundle(s, onPreloadCompleted, loadCompleted); }); } public static void GetMAssetBundle(string content, UnityAction onPreloadCompleted, UnityAction onLoadCompleted) { if (content.IsNullOrWhiteSpace()) { return; } var mFile = Regex.Split(content, "\r\n", RegexOptions.IgnoreCase).ToList(); for (var i = mFile.Count - 1; i >= 0; i--) { var aotMetaAssemblyFile = mFile[i]; if (string.IsNullOrEmpty(aotMetaAssemblyFile) || string.IsNullOrWhiteSpace(aotMetaAssemblyFile)) { mFile.RemoveAt(i); } } var completedCount = mFile.Count; onPreloadCompleted?.Invoke(completedCount); foreach (var m in mFile) { if (m.IsNullOrWhiteSpace()) { onLoadCompleted?.Invoke(); completedCount--; if (completedCount <= 0) { OnGetAssetBundleCompleted(); } continue; } var assetBundleNameInfoArray = m.Split(ZooMatchConstant.fgklpk.ToCharArray()); var fileName = assetBundleNameInfoArray[0]; var mUrl = $"{AssetBundleRootUrl}{fileName}"; var mFilePath = $"{GetFilePath()}{fileName}"; if (File.Exists(mFilePath)) { var fileMD5 = MD5Kit.GetFileMD5(mFilePath); var fileMD5New = assetBundleNameInfoArray[1]; if (fileMD5.Equals(fileMD5New)) { if (isLog) { } onLoadCompleted?.Invoke(); completedCount--; if (completedCount <= 0) { OnGetAssetBundleCompleted(); } continue; } if (isLog) { } } CrazyAsyKit.StartCoroutine(DownloadKit.GetFileFromUrl(mUrl, fileName, isSuccess => { if (isLog) { } onLoadCompleted?.Invoke(); completedCount--; if (completedCount <= 0) { OnGetAssetBundleCompleted(); } })); } } private static void OnGetAssetBundleCompleted() { ZooMatchKit.Instance.InitManifest(ZooMatchConstant.lesest, manifestInfo => { AppDispatcher.Instance.Dispatch(AppMsg.UI_LoadingInitAsset); }); } public static void GetAssetFile(UnityAction action) { CrazyAsyKit.StartCoroutine(DownloadKit.GetTextFromUrl(mFileUrl, "ZooMatchFile", content => { action?.Invoke(content); })); } } }