ball 项目提交
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine.Events;
|
||||
using System.Text.RegularExpressions;
|
||||
using Application = UnityEngine.Application;
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#endif
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class LegendFileKit
|
||||
{
|
||||
private static bool isLog = true;
|
||||
|
||||
private static string AssetBundleRootUrl = Application.streamingAssetsPath + "/LoveLegendAssets/AssetBundles/";
|
||||
private static string mFileUrl = Application.streamingAssetsPath + "/LoveLegendAssets/LoveLegendFile.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()}/LoveLegendAssets/";
|
||||
}
|
||||
|
||||
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(LegendConstant.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()
|
||||
{
|
||||
LoveLegendKit.Instance.InitManifest(LegendConstant.lesest,
|
||||
manifestInfo =>
|
||||
{
|
||||
AppDispatcher.Instance.Dispatch(AppMsg.UI_LoadingInitAsset);
|
||||
});
|
||||
}
|
||||
|
||||
public static void GetAssetFile(UnityAction<string> action)
|
||||
{
|
||||
|
||||
CrazyAsyKit.StartCoroutine(DownloadKit.GetTextFromUrl(mFileUrl, "LoveLegendFile",
|
||||
content => { action?.Invoke(content); }));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user