mirror of https://github.com/tuyoogame/YooAsset
commit
d3567d8dd5
|
@ -12,6 +12,9 @@ namespace YooAsset
|
|||
private static GameObject _driver = null;
|
||||
private static readonly List<ResourcePackage> _packages = new List<ResourcePackage>();
|
||||
|
||||
public const string DefaultPackageVersion_Key = "DefaultPackageVersion_Key";
|
||||
public const string DefaultPcakageVersion = "100000";
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经初始化
|
||||
/// </summary>
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using System.Collections.Generic;
|
||||
using WeChatWASM;
|
||||
using YooAsset;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
internal class WXFSClearAllBundleFilesOperation : FSClearAllBundleFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetAllCacheFiles,
|
||||
ClearAllWXCacheBundleFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private List<string> _wxBundleFilePaths;
|
||||
private int _fileTotalCount = 0;
|
||||
private WechatFileSystem _fileSystem;
|
||||
private ESteps _steps = ESteps.None;
|
||||
internal WXFSClearAllBundleFilesOperation(WechatFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
var allCacheFilePathDic = _fileSystem.GetWXAllCacheFilePath();
|
||||
_wxBundleFilePaths = allCacheFilePathDic.Values.ToList();
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.GetAllCacheFiles;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetAllCacheFiles)
|
||||
{
|
||||
if (_wxBundleFilePaths == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.ClearAllWXCacheBundleFiles;
|
||||
_fileTotalCount = _wxBundleFilePaths.Count;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearAllWXCacheBundleFiles)
|
||||
{
|
||||
for (int i = _wxBundleFilePaths.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string bundlePath = _wxBundleFilePaths[i];
|
||||
if (_fileSystem.CheckWXFileIsExist(bundlePath))
|
||||
{
|
||||
WX.RemoveFile(bundlePath, (bool isOk) =>
|
||||
{
|
||||
Debug.Log($"{_wxBundleFilePaths.Count}---删除缓存文件路径成功====={bundlePath}==");
|
||||
_wxBundleFilePaths.Remove(bundlePath);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_wxBundleFilePaths.Remove(bundlePath);
|
||||
//Debug.LogWarning($"Not Exit Cache file:{bundlePath}");
|
||||
}
|
||||
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
if (_fileTotalCount == 0)
|
||||
Progress = 1.0f;
|
||||
else
|
||||
Progress = 1.0f - (_wxBundleFilePaths.Count / _fileTotalCount);
|
||||
|
||||
if (_wxBundleFilePaths.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d48600eb90915544586c0108b94cfd02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,210 @@
|
|||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using System.Collections.Generic;
|
||||
using WeChatWASM;
|
||||
using YooAsset;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
internal class WXFSClearUnusedBundleFilesAsync : FSClearUnusedBundleFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadCachePackageInfo,
|
||||
VerifyFileData,
|
||||
LoadManifest,
|
||||
GetUnusedCacheFiles,
|
||||
ClearUnusedCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private WechatFileSystem _fileSystem;
|
||||
private readonly PackageManifest _manifest;
|
||||
private PackageManifest _cacheManifest;
|
||||
private List<string> _unusedBundleGUIDs;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private DeserializeManifestOperation _deserializer;
|
||||
private byte[] _fileData;
|
||||
private string _packageHash;
|
||||
private int _unusedFileTotalCount = 0;
|
||||
private string _lastPackageVersion;
|
||||
private string _cacheManifestHashPath;
|
||||
private string _cacheManifestPath;
|
||||
|
||||
internal WXFSClearUnusedBundleFilesAsync(WechatFileSystem fileSystem, PackageManifest manifest)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_manifest = manifest;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.LoadCachePackageInfo;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadCachePackageInfo)
|
||||
{
|
||||
LoadManifestInfo();
|
||||
if(_fileData != null && _fileData.Length > 0 && !string.IsNullOrEmpty(_packageHash))
|
||||
{
|
||||
_steps = ESteps.VerifyFileData;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to load cache package manifest file!";
|
||||
}
|
||||
}
|
||||
|
||||
if(_steps == ESteps.VerifyFileData)
|
||||
{
|
||||
string fileHash = HashUtility.BytesMD5(_fileData);
|
||||
if (fileHash == _packageHash)
|
||||
{
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to verify cache package manifest file!";
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadManifest)
|
||||
{
|
||||
if (_deserializer == null)
|
||||
{
|
||||
_deserializer = new DeserializeManifestOperation(_fileData);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _deserializer);
|
||||
}
|
||||
|
||||
Progress = _deserializer.Progress;
|
||||
if (_deserializer.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_deserializer.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.GetUnusedCacheFiles;
|
||||
_cacheManifest = _deserializer.Manifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _deserializer.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if(_steps == ESteps.GetUnusedCacheFiles)
|
||||
{
|
||||
_unusedBundleGUIDs = GetUnusedBundleGUIDs();
|
||||
_unusedFileTotalCount = _unusedBundleGUIDs.Count;
|
||||
_steps = ESteps.ClearUnusedCacheFiles;
|
||||
YooLogger.Log($"Found unused cache files count : {_unusedFileTotalCount}");
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearUnusedCacheFiles)
|
||||
{
|
||||
for (int i = _unusedBundleGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string bundleGUID = _unusedBundleGUIDs[i];
|
||||
PackageBundle bundle = null;
|
||||
if(_cacheManifest.TryGetPackageBundleByBundleGUID(bundleGUID,out bundle))
|
||||
{
|
||||
if (bundle != null)
|
||||
{
|
||||
var cachePath = GetCachePathByFileName(bundle.FileName);
|
||||
WX.RemoveFile(cachePath, (bool isOk) =>
|
||||
{
|
||||
Debug.Log($"{_unusedBundleGUIDs.Count}---删除缓存文件路径成功====={cachePath}==");
|
||||
//_unusedBundleGUIDs.Remove(cachePath);
|
||||
});
|
||||
|
||||
//_fileSystem.DeleteCacheFile(bundleGUID);
|
||||
_unusedBundleGUIDs.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
if (_unusedFileTotalCount == 0)
|
||||
Progress = 1.0f;
|
||||
else
|
||||
Progress = 1.0f - (_unusedBundleGUIDs.Count / _unusedFileTotalCount);
|
||||
|
||||
if (_unusedBundleGUIDs.Count == 0)
|
||||
{
|
||||
CheckPackageVerion();
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> GetUnusedBundleGUIDs()
|
||||
{
|
||||
var allBundleGUIDs = _cacheManifest.BundleDic3.Keys.ToList();
|
||||
List<string> result = new List<string>(allBundleGUIDs.Count);
|
||||
foreach (var bundleGUID in allBundleGUIDs)
|
||||
{
|
||||
if (_manifest.IsIncludeBundleFile(bundleGUID) == false)
|
||||
{
|
||||
result.Add(bundleGUID);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void LoadManifestInfo()
|
||||
{
|
||||
var packageName = _fileSystem.PackageName;
|
||||
var packageVersion = _manifest.PackageVersion;
|
||||
if (WX.StorageHasKeySync(YooAssets.DefaultPackageVersion_Key))
|
||||
{
|
||||
_lastPackageVersion = WX.StorageGetStringSync(YooAssets.DefaultPackageVersion_Key, YooAssets.DefaultPcakageVersion);
|
||||
Debug.Log($"==========Get Storage PackageVerion Succ==={_lastPackageVersion}");
|
||||
if (!string.IsNullOrEmpty(_lastPackageVersion) && (_lastPackageVersion != packageVersion))
|
||||
{
|
||||
_cacheManifestHashPath = GetCachePathByFileName(YooAssetSettingsData.GetPackageHashFileName(packageName, _lastPackageVersion));
|
||||
_cacheManifestPath = GetCachePathByFileName(YooAssetSettingsData.GetManifestBinaryFileName(packageName, _lastPackageVersion));
|
||||
if(string.IsNullOrEmpty(_cacheManifestHashPath) || string.IsNullOrEmpty(_cacheManifestPath)) { return; }
|
||||
|
||||
_packageHash = _fileSystem.ReadFileText(_cacheManifestHashPath);
|
||||
_fileData = _fileSystem.ReadFileData(_cacheManifestPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WX.StorageSetStringSync(YooAssets.DefaultPackageVersion_Key, packageVersion);
|
||||
Debug.Log($"first Set Storage PackageVerion Succ==={packageVersion}");
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckPackageVerion()
|
||||
{
|
||||
var packageName = _fileSystem.PackageName;
|
||||
var packageVersion = _manifest.PackageVersion;
|
||||
if (_lastPackageVersion != packageVersion)
|
||||
{
|
||||
WX.StorageSetStringSync(YooAssets.DefaultPackageVersion_Key, packageVersion);
|
||||
//删除旧的资源清单文件和哈希文件
|
||||
WX.RemoveFile(_cacheManifestHashPath, (bool isOk) => { Debug.Log("====Delect manifestHashPath Succ"); });
|
||||
WX.RemoveFile(_cacheManifestPath, (bool isOk) => { Debug.Log("====Delect manifestPath Succ"); });
|
||||
Debug.Log($"==========Set Storage PackageVerion Succ==={packageVersion}");
|
||||
}
|
||||
}
|
||||
|
||||
private string GetUnuseCachePathByBundleName(string fileName)
|
||||
{
|
||||
var filePath = $"StreamingAssets/WebGL/{fileName}";
|
||||
return WX.GetCachePath(filePath);
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e4938d8a5a9d7f24db37f8df6b32501f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -11,14 +11,16 @@ internal class WXFSRequestPackageVersionOperation : FSRequestPackageVersionOpera
|
|||
}
|
||||
|
||||
private readonly WechatFileSystem _fileSystem;
|
||||
private readonly bool _appendTimeTicks;
|
||||
private readonly int _timeout;
|
||||
private RequestWechatPackageVersionOperation _requestWebPackageVersionOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal WXFSRequestPackageVersionOperation(WechatFileSystem fileSystem, int timeout)
|
||||
internal WXFSRequestPackageVersionOperation(WechatFileSystem fileSystem, bool appendTimeTicks, int timeout)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_appendTimeTicks = appendTimeTicks;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
|
@ -34,7 +36,7 @@ internal class WXFSRequestPackageVersionOperation : FSRequestPackageVersionOpera
|
|||
{
|
||||
if (_requestWebPackageVersionOp == null)
|
||||
{
|
||||
_requestWebPackageVersionOp = new RequestWechatPackageVersionOperation(_fileSystem, _timeout);
|
||||
_requestWebPackageVersionOp = new RequestWechatPackageVersionOperation(_fileSystem, _appendTimeTicks, _timeout);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _requestWebPackageVersionOp);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ internal class RequestWechatPackageVersionOperation : AsyncOperationBase
|
|||
|
||||
private readonly WechatFileSystem _fileSystem;
|
||||
private readonly int _timeout;
|
||||
private readonly bool _appendTimeTicks;
|
||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||
private int _requestCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
@ -22,9 +23,10 @@ internal class RequestWechatPackageVersionOperation : AsyncOperationBase
|
|||
public string PackageVersion { private set; get; }
|
||||
|
||||
|
||||
public RequestWechatPackageVersionOperation(WechatFileSystem fileSystem, int timeout)
|
||||
public RequestWechatPackageVersionOperation(WechatFileSystem fileSystem, bool appendTimeTicks, int timeout)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_appendTimeTicks = appendTimeTicks;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
|
@ -78,11 +80,19 @@ internal class RequestWechatPackageVersionOperation : AsyncOperationBase
|
|||
|
||||
private string GetRequestURL(string fileName)
|
||||
{
|
||||
string url;
|
||||
|
||||
// 轮流返回请求地址
|
||||
if (_requestCount % 2 == 0)
|
||||
return _fileSystem.RemoteServices.GetRemoteMainURL(fileName);
|
||||
url = _fileSystem.RemoteServices.GetRemoteMainURL(fileName);
|
||||
else
|
||||
return _fileSystem.RemoteServices.GetRemoteFallbackURL(fileName);
|
||||
url = _fileSystem.RemoteServices.GetRemoteFallbackURL(fileName);
|
||||
|
||||
// 在URL末尾添加时间戳
|
||||
if (_appendTimeTicks)
|
||||
return $"{url}?{System.DateTime.UtcNow.Ticks}";
|
||||
else
|
||||
return url;
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using WeChatWASM;
|
||||
using System;
|
||||
|
||||
public static class WechatFileSystemCreater
|
||||
{
|
||||
|
@ -51,9 +52,12 @@ internal class WechatFileSystem : IFileSystem
|
|||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, string> _cacheFilePaths = new Dictionary<string, string>(10000);
|
||||
private WXFileSystemManager _fileSystemManager;
|
||||
private string _fileCacheRoot = string.Empty;
|
||||
/// <summary>
|
||||
/// Key:资源包GUID Value:缓存路径
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, string> _wxFilePaths = new Dictionary<string, string>(10000);
|
||||
private WXFileSystemManager _wxFileSystemMgr;
|
||||
private string _wxFileCacheRoot = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
|
@ -67,7 +71,7 @@ internal class WechatFileSystem : IFileSystem
|
|||
{
|
||||
get
|
||||
{
|
||||
return _fileCacheRoot;
|
||||
return _wxFileCacheRoot;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,12 +86,12 @@ internal class WechatFileSystem : IFileSystem
|
|||
}
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:远程服务接口
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices { private set; get; } = null;
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
||||
public WechatFileSystem()
|
||||
|
@ -107,19 +111,20 @@ internal class WechatFileSystem : IFileSystem
|
|||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new WXFSRequestPackageVersionOperation(this, timeout);
|
||||
var operation = new WXFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearAllBundleFilesOperation ClearAllBundleFilesAsync()
|
||||
{
|
||||
var operation = new FSClearAllBundleFilesCompleteOperation();
|
||||
var operation = new WXFSClearAllBundleFilesOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
public virtual FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(PackageManifest manifest)
|
||||
{
|
||||
var operation = new FSClearUnusedBundleFilesCompleteOperation();
|
||||
var operation = new WXFSClearUnusedBundleFilesAsync(this, manifest);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
@ -166,8 +171,9 @@ internal class WechatFileSystem : IFileSystem
|
|||
RemoteServices = new WebRemoteServices(webRoot);
|
||||
}
|
||||
|
||||
_fileSystemManager = WX.GetFileSystemManager();
|
||||
_fileCacheRoot = WX.env.USER_DATA_PATH; //注意:如果有子目录,请修改此处!
|
||||
_wxFileSystemMgr = WX.GetFileSystemManager();
|
||||
_wxFileCacheRoot = PathUtility.Combine(WX.PluginCachePath, $"StreamingAssets/WebGL");// WX.PluginCachePath; //注意:如果有子目录,请修改此处!
|
||||
Debug.Log($"==_wxFileCacheRoot=={_wxFileCacheRoot}");
|
||||
}
|
||||
public virtual void OnUpdate()
|
||||
{
|
||||
|
@ -179,15 +185,16 @@ internal class WechatFileSystem : IFileSystem
|
|||
}
|
||||
public virtual bool Exists(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
string result = _fileSystemManager.AccessSync(filePath);
|
||||
return result.Equals("access:ok");
|
||||
string filePath = GetWXFileLoadPath(bundle);
|
||||
//Debug.Log($"CacheFile:{WX.GetCachePath($"StreamingAssets/WebGL/v1.0.0/{bundle.FileName}")}");
|
||||
return CheckWXFileIsExist(filePath);
|
||||
}
|
||||
public virtual bool NeedDownload(PackageBundle bundle)
|
||||
{
|
||||
if (Belong(bundle) == false)
|
||||
return false;
|
||||
|
||||
//Debug.Log($"WX NeedDownload: bundleName:{bundle.BundleName} + Exists:{Exists(bundle)}");
|
||||
return Exists(bundle) == false;
|
||||
}
|
||||
public virtual bool NeedUnpack(PackageBundle bundle)
|
||||
|
@ -208,16 +215,104 @@ internal class WechatFileSystem : IFileSystem
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
private string GetCacheFileLoadPath(PackageBundle bundle)
|
||||
public byte[] ReadFileData(string filePath)
|
||||
{
|
||||
if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
||||
if (CheckWXFileIsExist(filePath))
|
||||
return _wxFileSystemMgr.ReadFileSync(filePath);
|
||||
else
|
||||
return Array.Empty<byte>();
|
||||
//throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public string ReadFileText(string filePath)
|
||||
{
|
||||
if(CheckWXFileIsExist(filePath))
|
||||
return _wxFileSystemMgr.ReadFileSync(filePath, "utf8");
|
||||
else
|
||||
return string.Empty;
|
||||
//throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有缓存文件的路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string,string> GetWXAllCacheFilePath()
|
||||
{
|
||||
return _wxFilePaths;
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断微信缓存文件是否存在
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <returns></returns>
|
||||
public bool CheckWXFileIsExist(string filePath)
|
||||
{
|
||||
string result = _wxFileSystemMgr.AccessSync(filePath);
|
||||
return result.Equals("access:ok");
|
||||
}
|
||||
#region 调用微信小游戏接口删除缓存文件目录下所有文件
|
||||
public void ClearAllCacheFile()
|
||||
{
|
||||
#if !UNITY_EDITOR && UNITY_WEBGL && WEIXINMINIGAME
|
||||
ShowModalOption showModalOp = new ShowModalOption();
|
||||
showModalOp.title = "提示";
|
||||
showModalOp.content = "是否确定要清理缓存并重启";
|
||||
showModalOp.confirmText = "确定";
|
||||
showModalOp.cancelText = "取消";
|
||||
showModalOp.complete = (GeneralCallbackResult callResult) => { Debug.Log($"complete==={callResult.errMsg}"); };
|
||||
showModalOp.fail = (GeneralCallbackResult callResult) => { Debug.Log($"fail==={callResult.errMsg}"); };
|
||||
showModalOp.success = (ShowModalSuccessCallbackResult callResult) =>
|
||||
{
|
||||
if(callResult.confirm)
|
||||
RestartMiniGame();
|
||||
};
|
||||
WX.ShowModal(showModalOp);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 微信小游戏清除缓存并且重启小游戏
|
||||
/// 参考小游戏=>出发吧麦芬
|
||||
/// </summary>
|
||||
private void RestartMiniGame()
|
||||
{
|
||||
WX.CleanAllFileCache((bool isOk) =>
|
||||
{
|
||||
filePath = PathUtility.Combine(_fileCacheRoot, bundle.FileName);
|
||||
_cacheFilePaths.Add(bundle.BundleGUID, filePath);
|
||||
RestartMiniProgramOption restartMini = new RestartMiniProgramOption();
|
||||
restartMini.complete = RestartMiniComplete;
|
||||
restartMini.fail = RestartMiniFailComplete;
|
||||
restartMini.success = RestartMiniSuccComplete;
|
||||
WX.RestartMiniProgram(restartMini);
|
||||
});
|
||||
}
|
||||
|
||||
private void RestartMiniComplete(GeneralCallbackResult result)
|
||||
{
|
||||
Debug.Log($"RestartMiniComplete:{result.errMsg}");
|
||||
}
|
||||
|
||||
private void RestartMiniFailComplete(GeneralCallbackResult result)
|
||||
{
|
||||
Debug.Log($"RestartMiniFailComplete:{result.errMsg}");
|
||||
}
|
||||
|
||||
private void RestartMiniSuccComplete(GeneralCallbackResult result)
|
||||
{
|
||||
Debug.Log($"RestartMiniSuccComplete:{result.errMsg}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region 内部方法
|
||||
private string GetWXFileLoadPath(PackageBundle bundle)
|
||||
{
|
||||
if (_wxFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
||||
{
|
||||
filePath = PathUtility.Combine(_wxFileCacheRoot, bundle.FileName);
|
||||
_wxFilePaths.Add(bundle.BundleGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
#endif
|
|
@ -74,7 +74,14 @@ internal class FsmInitializePackage : IStateNode
|
|||
if (playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
var createParameters = new WebPlayModeParameters();
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME && !UNITY_EDITOR
|
||||
string defaultHostServer = GetHostServerURL();
|
||||
string fallbackHostServer = GetHostServerURL();
|
||||
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
createParameters.WebFileSystemParameters = WechatFileSystemCreater.CreateWechatFileSystemParameters(remoteServices);
|
||||
#else
|
||||
createParameters.WebFileSystemParameters = FileSystemParameters.CreateDefaultWebFileSystemParameters();
|
||||
#endif
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue