Files
RedHotRoast-ios/Assets/GemCrush/Helper/CrazyZooFileKit.cs
T
2026-04-22 09:52:55 +08:00

152 lines
4.3 KiB
C#

using System.IO;
using System.Linq;
using UnityEngine.Events;
using System.Text.RegularExpressions;
using Application = UnityEngine.Application;
#if UNITY_EDITOR
#endif
namespace FlowerPower
{
public class GemCrushFileKit
{
private static bool isLog = true;
private static string AssetBundleRootUrl = Application.streamingAssetsPath + "/GemCrushAssets/AssetBundles/";
private static string mFileUrl = Application.streamingAssetsPath + "/GemCrushAssets/GemCrushFile.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()}/GemCrushAssets/";
}
public static void GetLocalAssetBundle(UnityAction<int> onPreloadCompleted, UnityAction loadCompleted)
{
GetAssetFile(s => { GetMAssetBundle(s, onPreloadCompleted, loadCompleted); });
}
public static void GetMAssetBundle(string content, UnityAction<int> 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(GemCrushConstant.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()
{
GemCrushKit.Instance.InitManifest(GemCrushConstant.lesest,
manifestInfo =>
{
AppDispatcher.Instance.Dispatch(AppMsg.UI_LoadingInitAsset);
});
}
public static void GetAssetFile(UnityAction<string> action)
{
CrazyAsyKit.StartCoroutine(DownloadKit.GetTextFromUrl(mFileUrl, "GemCrushFile",
content => { action?.Invoke(content); }));
}
}
}