mirror of https://github.com/tuyoogame/YooAsset
Compare commits
5 Commits
e925d9892f
...
31a0017351
Author | SHA1 | Date |
---|---|---|
|
31a0017351 | |
|
6e8cb0366d | |
|
a02b3fbf6e | |
|
37a663e0e1 | |
|
9f844912cf |
|
@ -373,7 +373,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
if (_wrappers.ContainsKey(bundleGUID))
|
if (_wrappers.ContainsKey(bundleGUID))
|
||||||
{
|
{
|
||||||
YooLogger.Error($"{nameof(DefaultCacheFileSystem)} has record file element : {bundleGUID}");
|
YooLogger.Error($"{nameof(DefaultCacheFileSystem)} has element : {bundleGUID}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
#if UNITY_WEBGL && BYTEMINIGAME
|
|
||||||
using YooAsset;
|
|
||||||
|
|
||||||
internal partial class BGFSInitializeOperation : FSInitializeFileSystemOperation
|
|
||||||
{
|
|
||||||
private readonly ByteGameFileSystem _fileSystem;
|
|
||||||
|
|
||||||
public BGFSInitializeOperation(ByteGameFileSystem fileSystem)
|
|
||||||
{
|
|
||||||
_fileSystem = fileSystem;
|
|
||||||
}
|
|
||||||
internal override void InternalOnStart()
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
internal override void InternalOnUpdate()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,88 +0,0 @@
|
||||||
#if UNITY_WEBGL && BYTEMINIGAME
|
|
||||||
using YooAsset;
|
|
||||||
|
|
||||||
internal class BGFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
|
|
||||||
{
|
|
||||||
private enum ESteps
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
RequestRemotePackageHash,
|
|
||||||
LoadRemotePackageManifest,
|
|
||||||
Done,
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly ByteGameFileSystem _fileSystem;
|
|
||||||
private readonly string _packageVersion;
|
|
||||||
private readonly int _timeout;
|
|
||||||
private RequestByteGamePackageHashOperation _requestRemotePackageHashOp;
|
|
||||||
private LoadByteGamePackageManifestOperation _loadRemotePackageManifestOp;
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
|
|
||||||
public BGFSLoadPackageManifestOperation(ByteGameFileSystem fileSystem, string packageVersion, int timeout)
|
|
||||||
{
|
|
||||||
_fileSystem = fileSystem;
|
|
||||||
_packageVersion = packageVersion;
|
|
||||||
_timeout = timeout;
|
|
||||||
}
|
|
||||||
internal override void InternalOnStart()
|
|
||||||
{
|
|
||||||
_steps = ESteps.RequestRemotePackageHash;
|
|
||||||
}
|
|
||||||
internal override void InternalOnUpdate()
|
|
||||||
{
|
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_steps == ESteps.RequestRemotePackageHash)
|
|
||||||
{
|
|
||||||
if (_requestRemotePackageHashOp == null)
|
|
||||||
{
|
|
||||||
_requestRemotePackageHashOp = new RequestByteGamePackageHashOperation(_fileSystem, _packageVersion, _timeout);
|
|
||||||
OperationSystem.StartOperation(_fileSystem.PackageName, _requestRemotePackageHashOp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_requestRemotePackageHashOp.IsDone == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_requestRemotePackageHashOp.Status == EOperationStatus.Succeed)
|
|
||||||
{
|
|
||||||
_steps = ESteps.LoadRemotePackageManifest;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = _requestRemotePackageHashOp.Error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.LoadRemotePackageManifest)
|
|
||||||
{
|
|
||||||
if (_loadRemotePackageManifestOp == null)
|
|
||||||
{
|
|
||||||
string packageHash = _requestRemotePackageHashOp.PackageHash;
|
|
||||||
_loadRemotePackageManifestOp = new LoadByteGamePackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
|
|
||||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadRemotePackageManifestOp);
|
|
||||||
}
|
|
||||||
|
|
||||||
Progress = _loadRemotePackageManifestOp.Progress;
|
|
||||||
if (_loadRemotePackageManifestOp.IsDone == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_loadRemotePackageManifestOp.Status == EOperationStatus.Succeed)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Manifest = _loadRemotePackageManifestOp.Manifest;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = _loadRemotePackageManifestOp.Error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,15 +1,14 @@
|
||||||
#if UNITY_WEBGL && BYTEMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
using StarkSDKSpace;
|
|
||||||
|
|
||||||
internal class BGFSDownloadFileOperation : DefaultDownloadFileOperation
|
internal class TTFSDownloadFileOperation : DefaultDownloadFileOperation
|
||||||
{
|
{
|
||||||
private ByteGameFileSystem _fileSystem;
|
private TiktokFileSystem _fileSystem;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal BGFSDownloadFileOperation(ByteGameFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param)
|
internal TTFSDownloadFileOperation(TiktokFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
internal partial class TTFSInitializeOperation : FSInitializeFileSystemOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
RecordCacheFiles,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
|
private RecordTiktokCacheFilesOperation _recordTiktokCacheFilesOp;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
public TTFSInitializeOperation(TiktokFileSystem fileSystem)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
}
|
||||||
|
internal override void InternalOnStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.RecordCacheFiles;
|
||||||
|
}
|
||||||
|
internal override void InternalOnUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.RecordCacheFiles)
|
||||||
|
{
|
||||||
|
if (_recordTiktokCacheFilesOp == null)
|
||||||
|
{
|
||||||
|
_recordTiktokCacheFilesOp = new RecordTiktokCacheFilesOperation(_fileSystem);
|
||||||
|
OperationSystem.StartOperation(_fileSystem.PackageName, _recordTiktokCacheFilesOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_recordTiktokCacheFilesOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_recordTiktokCacheFilesOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _recordTiktokCacheFilesOp.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -1,10 +1,10 @@
|
||||||
#if UNITY_WEBGL && BYTEMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
using StarkSDKSpace;
|
using TTSDK;
|
||||||
|
|
||||||
internal class BGFSLoadBundleOperation : FSLoadBundleOperation
|
internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
|
@ -13,12 +13,12 @@ internal class BGFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ByteGameFileSystem _fileSystem;
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private UnityWebRequest _webRequest;
|
private UnityWebRequest _webRequest;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal BGFSLoadBundleOperation(ByteGameFileSystem fileSystem, PackageBundle bundle)
|
internal TTFSLoadBundleOperation(TiktokFileSystem fileSystem, PackageBundle bundle)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_bundle = bundle;
|
_bundle = bundle;
|
|
@ -0,0 +1,88 @@
|
||||||
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
internal class TTFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
RequestPackageHash,
|
||||||
|
LoadPackageManifest,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
|
private readonly string _packageVersion;
|
||||||
|
private readonly int _timeout;
|
||||||
|
private RequestTiktokPackageHashOperation _requestPackageHashOp;
|
||||||
|
private LoadTiktokPackageManifestOperation _loadPackageManifestOp;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
public TTFSLoadPackageManifestOperation(TiktokFileSystem fileSystem, string packageVersion, int timeout)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
_packageVersion = packageVersion;
|
||||||
|
_timeout = timeout;
|
||||||
|
}
|
||||||
|
internal override void InternalOnStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.RequestPackageHash;
|
||||||
|
}
|
||||||
|
internal override void InternalOnUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.RequestPackageHash)
|
||||||
|
{
|
||||||
|
if (_requestPackageHashOp == null)
|
||||||
|
{
|
||||||
|
_requestPackageHashOp = new RequestTiktokPackageHashOperation(_fileSystem, _packageVersion, _timeout);
|
||||||
|
OperationSystem.StartOperation(_fileSystem.PackageName, _requestPackageHashOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_requestPackageHashOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_requestPackageHashOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadPackageManifest;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _requestPackageHashOp.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadPackageManifest)
|
||||||
|
{
|
||||||
|
if (_loadPackageManifestOp == null)
|
||||||
|
{
|
||||||
|
string packageHash = _requestPackageHashOp.PackageHash;
|
||||||
|
_loadPackageManifestOp = new LoadTiktokPackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
|
||||||
|
OperationSystem.StartOperation(_fileSystem.PackageName, _loadPackageManifestOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
Progress = _loadPackageManifestOp.Progress;
|
||||||
|
if (_loadPackageManifestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Manifest = _loadPackageManifestOp.Manifest;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _loadPackageManifestOp.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -1,7 +1,7 @@
|
||||||
#if UNITY_WEBGL && BYTEMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
internal class BGFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
|
internal class TTFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
|
@ -10,13 +10,13 @@ internal class BGFSRequestPackageVersionOperation : FSRequestPackageVersionOpera
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ByteGameFileSystem _fileSystem;
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
private RequestByteGamePackageVersionOperation _requestWebPackageVersionOp;
|
private RequestTiktokPackageVersionOperation _requestPackageVersionOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
internal BGFSRequestPackageVersionOperation(ByteGameFileSystem fileSystem, int timeout)
|
internal TTFSRequestPackageVersionOperation(TiktokFileSystem fileSystem, int timeout)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_timeout = timeout;
|
_timeout = timeout;
|
||||||
|
@ -32,27 +32,27 @@ internal class BGFSRequestPackageVersionOperation : FSRequestPackageVersionOpera
|
||||||
|
|
||||||
if (_steps == ESteps.RequestPackageVersion)
|
if (_steps == ESteps.RequestPackageVersion)
|
||||||
{
|
{
|
||||||
if (_requestWebPackageVersionOp == null)
|
if (_requestPackageVersionOp == null)
|
||||||
{
|
{
|
||||||
_requestWebPackageVersionOp = new RequestByteGamePackageVersionOperation(_fileSystem, _timeout);
|
_requestPackageVersionOp = new RequestTiktokPackageVersionOperation(_fileSystem, _timeout);
|
||||||
OperationSystem.StartOperation(_fileSystem.PackageName, _requestWebPackageVersionOp);
|
OperationSystem.StartOperation(_fileSystem.PackageName, _requestPackageVersionOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
Progress = _requestWebPackageVersionOp.Progress;
|
Progress = _requestPackageVersionOp.Progress;
|
||||||
if (_requestWebPackageVersionOp.IsDone == false)
|
if (_requestPackageVersionOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_requestWebPackageVersionOp.Status == EOperationStatus.Succeed)
|
if (_requestPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
PackageVersion = _requestWebPackageVersionOp.PackageVersion;
|
PackageVersion = _requestPackageVersionOp.PackageVersion;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _requestWebPackageVersionOp.Error;
|
Error = _requestPackageVersionOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#if UNITY_WEBGL && BYTEMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
internal class LoadByteGamePackageManifestOperation : AsyncOperationBase
|
internal class LoadTiktokPackageManifestOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ internal class LoadByteGamePackageManifestOperation : AsyncOperationBase
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ByteGameFileSystem _fileSystem;
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
private readonly string _packageVersion;
|
private readonly string _packageVersion;
|
||||||
private readonly string _packageHash;
|
private readonly string _packageHash;
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
|
@ -27,7 +27,7 @@ internal class LoadByteGamePackageManifestOperation : AsyncOperationBase
|
||||||
public PackageManifest Manifest { private set; get; }
|
public PackageManifest Manifest { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal LoadByteGamePackageManifestOperation(ByteGameFileSystem fileSystem, string packageVersion, string packageHash, int timeout)
|
internal LoadTiktokPackageManifestOperation(TiktokFileSystem fileSystem, string packageVersion, string packageHash, int timeout)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_packageVersion = packageVersion;
|
_packageVersion = packageVersion;
|
||||||
|
@ -36,7 +36,7 @@ internal class LoadByteGamePackageManifestOperation : AsyncOperationBase
|
||||||
}
|
}
|
||||||
internal override void InternalOnStart()
|
internal override void InternalOnStart()
|
||||||
{
|
{
|
||||||
_requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(LoadByteGamePackageManifestOperation));
|
_requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(LoadTiktokPackageManifestOperation));
|
||||||
_steps = ESteps.RequestFileData;
|
_steps = ESteps.RequestFileData;
|
||||||
}
|
}
|
||||||
internal override void InternalOnUpdate()
|
internal override void InternalOnUpdate()
|
||||||
|
@ -67,7 +67,7 @@ internal class LoadByteGamePackageManifestOperation : AsyncOperationBase
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _webDataRequestOp.Error;
|
Error = _webDataRequestOp.Error;
|
||||||
WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(LoadByteGamePackageManifestOperation));
|
WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(LoadTiktokPackageManifestOperation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
|
using YooAsset;
|
||||||
|
using TTSDK;
|
||||||
|
|
||||||
|
internal class RecordTiktokCacheFilesOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
RecordCacheFiles,
|
||||||
|
WaitResponse,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
public RecordTiktokCacheFilesOperation(TiktokFileSystem fileSystem)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
}
|
||||||
|
internal override void InternalOnStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.RecordCacheFiles;
|
||||||
|
}
|
||||||
|
internal override void InternalOnUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.RecordCacheFiles)
|
||||||
|
{
|
||||||
|
_steps = ESteps.WaitResponse;
|
||||||
|
|
||||||
|
var fileSystemMgr = _fileSystem.GetFileSystemMgr();
|
||||||
|
var getSavedFileListParam = new GetSavedFileListParam();
|
||||||
|
getSavedFileListParam.success = (TTGetSavedFileListResponse response) =>
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
foreach (var fileInfo in response.fileList)
|
||||||
|
{
|
||||||
|
//TODO 需要确认存储文件为Bundle文件
|
||||||
|
_fileSystem.RecordBundleFile(fileInfo.filePath);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getSavedFileListParam.fail = (TTGetSavedFileListResponse response) =>
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = response.errMsg;
|
||||||
|
};
|
||||||
|
fileSystemMgr.GetSavedFileList(getSavedFileListParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e4420bd73f37dec468a9b23425be68f2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -1,7 +1,7 @@
|
||||||
#if UNITY_WEBGL && BYTEMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
internal class RequestByteGamePackageHashOperation : AsyncOperationBase
|
internal class RequestTiktokPackageHashOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ internal class RequestByteGamePackageHashOperation : AsyncOperationBase
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ByteGameFileSystem _fileSystem;
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
private readonly string _packageVersion;
|
private readonly string _packageVersion;
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||||
|
@ -23,7 +23,7 @@ internal class RequestByteGamePackageHashOperation : AsyncOperationBase
|
||||||
public string PackageHash { private set; get; }
|
public string PackageHash { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
public RequestByteGamePackageHashOperation(ByteGameFileSystem fileSystem, string packageVersion, int timeout)
|
public RequestTiktokPackageHashOperation(TiktokFileSystem fileSystem, string packageVersion, int timeout)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_packageVersion = packageVersion;
|
_packageVersion = packageVersion;
|
||||||
|
@ -31,7 +31,7 @@ internal class RequestByteGamePackageHashOperation : AsyncOperationBase
|
||||||
}
|
}
|
||||||
internal override void InternalOnStart()
|
internal override void InternalOnStart()
|
||||||
{
|
{
|
||||||
_requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestByteGamePackageHashOperation));
|
_requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestTiktokPackageHashOperation));
|
||||||
_steps = ESteps.RequestPackageHash;
|
_steps = ESteps.RequestPackageHash;
|
||||||
}
|
}
|
||||||
internal override void InternalOnUpdate()
|
internal override void InternalOnUpdate()
|
||||||
|
@ -73,7 +73,7 @@ internal class RequestByteGamePackageHashOperation : AsyncOperationBase
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _webTextRequestOp.Error;
|
Error = _webTextRequestOp.Error;
|
||||||
WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestByteGamePackageHashOperation));
|
WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestTiktokPackageHashOperation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#if UNITY_WEBGL && BYTEMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
internal class RequestByteGamePackageVersionOperation : AsyncOperationBase
|
internal class RequestTiktokPackageVersionOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ internal class RequestByteGamePackageVersionOperation : AsyncOperationBase
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ByteGameFileSystem _fileSystem;
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||||
private int _requestCount = 0;
|
private int _requestCount = 0;
|
||||||
|
@ -22,14 +22,14 @@ internal class RequestByteGamePackageVersionOperation : AsyncOperationBase
|
||||||
public string PackageVersion { private set; get; }
|
public string PackageVersion { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
public RequestByteGamePackageVersionOperation(ByteGameFileSystem fileSystem, int timeout)
|
public RequestTiktokPackageVersionOperation(TiktokFileSystem fileSystem, int timeout)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_timeout = timeout;
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalOnStart()
|
internal override void InternalOnStart()
|
||||||
{
|
{
|
||||||
_requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestByteGamePackageVersionOperation));
|
_requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestTiktokPackageVersionOperation));
|
||||||
_steps = ESteps.RequestPackageVersion;
|
_steps = ESteps.RequestPackageVersion;
|
||||||
}
|
}
|
||||||
internal override void InternalOnUpdate()
|
internal override void InternalOnUpdate()
|
||||||
|
@ -71,7 +71,7 @@ internal class RequestByteGamePackageVersionOperation : AsyncOperationBase
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _webTextRequestOp.Error;
|
Error = _webTextRequestOp.Error;
|
||||||
WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestByteGamePackageVersionOperation));
|
WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestTiktokPackageVersionOperation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,15 +1,17 @@
|
||||||
#if UNITY_WEBGL && BYTEMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
using StarkSDKSpace;
|
using TTSDK;
|
||||||
|
using System.Linq;
|
||||||
|
using System;
|
||||||
|
|
||||||
public static class ByteGameFileSystemCreater
|
public static class TiktokFileSystemCreater
|
||||||
{
|
{
|
||||||
public static FileSystemParameters CreateByteGameFileSystemParameters(IRemoteServices remoteServices)
|
public static FileSystemParameters CreateByteGameFileSystemParameters(IRemoteServices remoteServices, string packageRoot)
|
||||||
{
|
{
|
||||||
string fileSystemClass = $"{nameof(ByteGameFileSystem)},YooAsset.RuntimeExtension";
|
string fileSystemClass = $"{nameof(TiktokFileSystem)},YooAsset.RuntimeExtension";
|
||||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||||
fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices);
|
fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices);
|
||||||
return fileSystemParams;
|
return fileSystemParams;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +21,7 @@ public static class ByteGameFileSystemCreater
|
||||||
/// 抖音小游戏文件系统
|
/// 抖音小游戏文件系统
|
||||||
/// 参考:https://developer.open-douyin.com/docs/resource/zh-CN/mini-game/develop/guide/know
|
/// 参考:https://developer.open-douyin.com/docs/resource/zh-CN/mini-game/develop/guide/know
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class ByteGameFileSystem : IFileSystem
|
internal class TiktokFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
private class WebRemoteServices : IRemoteServices
|
private class WebRemoteServices : IRemoteServices
|
||||||
{
|
{
|
||||||
|
@ -51,8 +53,10 @@ internal class ByteGameFileSystem : IFileSystem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly HashSet<string> _recorders = new HashSet<string>();
|
||||||
private readonly Dictionary<string, string> _cacheFilePaths = new Dictionary<string, string>(10000);
|
private readonly Dictionary<string, string> _cacheFilePaths = new Dictionary<string, string>(10000);
|
||||||
private StarkFileSystemManager _fileSystemManager;
|
private TTFileSystemManager _fileSystemMgr;
|
||||||
|
private string _ttCacheRoot = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 包裹名称
|
/// 包裹名称
|
||||||
|
@ -66,7 +70,7 @@ internal class ByteGameFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return string.Empty;
|
return _ttCacheRoot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +81,7 @@ internal class ByteGameFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return 0;
|
return _recorders.Count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,24 +93,24 @@ internal class ByteGameFileSystem : IFileSystem
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public ByteGameFileSystem()
|
public TiktokFileSystem()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
|
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
|
||||||
{
|
{
|
||||||
var operation = new BGFSInitializeOperation(this);
|
var operation = new TTFSInitializeOperation(this);
|
||||||
OperationSystem.StartOperation(PackageName, operation);
|
OperationSystem.StartOperation(PackageName, operation);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||||
{
|
{
|
||||||
var operation = new BGFSLoadPackageManifestOperation(this, packageVersion, timeout);
|
var operation = new TTFSLoadPackageManifestOperation(this, packageVersion, timeout);
|
||||||
OperationSystem.StartOperation(PackageName, operation);
|
OperationSystem.StartOperation(PackageName, operation);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||||
{
|
{
|
||||||
var operation = new BGFSRequestPackageVersionOperation(this, timeout);
|
var operation = new TTFSRequestPackageVersionOperation(this, timeout);
|
||||||
OperationSystem.StartOperation(PackageName, operation);
|
OperationSystem.StartOperation(PackageName, operation);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +124,7 @@ internal class ByteGameFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
param.MainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
param.MainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||||
param.FallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
param.FallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||||
var operation = new BGFSDownloadFileOperation(this, bundle, param);
|
var operation = new TTFSDownloadFileOperation(this, bundle, param);
|
||||||
OperationSystem.StartOperation(PackageName, operation);
|
OperationSystem.StartOperation(PackageName, operation);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
@ -128,13 +132,13 @@ internal class ByteGameFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||||
{
|
{
|
||||||
var operation = new BGFSLoadBundleOperation(this, bundle);
|
var operation = new TTFSLoadBundleOperation(this, bundle);
|
||||||
OperationSystem.StartOperation(PackageName, operation);
|
OperationSystem.StartOperation(PackageName, operation);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string error = $"{nameof(ByteGameFileSystem)} not support load bundle type : {bundle.BundleType}";
|
string error = $"{nameof(TiktokFileSystem)} not support load bundle type : {bundle.BundleType}";
|
||||||
var operation = new FSLoadBundleCompleteOperation(error);
|
var operation = new FSLoadBundleCompleteOperation(error);
|
||||||
OperationSystem.StartOperation(PackageName, operation);
|
OperationSystem.StartOperation(PackageName, operation);
|
||||||
return operation;
|
return operation;
|
||||||
|
@ -155,6 +159,12 @@ internal class ByteGameFileSystem : IFileSystem
|
||||||
public virtual void OnCreate(string packageName, string rootDirectory)
|
public virtual void OnCreate(string packageName, string rootDirectory)
|
||||||
{
|
{
|
||||||
PackageName = packageName;
|
PackageName = packageName;
|
||||||
|
_ttCacheRoot = rootDirectory;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(_ttCacheRoot))
|
||||||
|
{
|
||||||
|
throw new System.Exception("请配置抖音小游戏的缓存根目录!");
|
||||||
|
}
|
||||||
|
|
||||||
// 注意:CDN服务未启用的情况下,使用抖音WEB服务器
|
// 注意:CDN服务未启用的情况下,使用抖音WEB服务器
|
||||||
if (RemoteServices == null)
|
if (RemoteServices == null)
|
||||||
|
@ -163,7 +173,7 @@ internal class ByteGameFileSystem : IFileSystem
|
||||||
RemoteServices = new WebRemoteServices(webRoot);
|
RemoteServices = new WebRemoteServices(webRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
_fileSystemManager = StarkSDK.API.GetStarkFileSystemManager();
|
_fileSystemMgr = TT.GetFileSystemManager();
|
||||||
}
|
}
|
||||||
public virtual void OnUpdate()
|
public virtual void OnUpdate()
|
||||||
{
|
{
|
||||||
|
@ -176,7 +186,7 @@ internal class ByteGameFileSystem : IFileSystem
|
||||||
public virtual bool Exists(PackageBundle bundle)
|
public virtual bool Exists(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
string filePath = GetCacheFileLoadPath(bundle);
|
string filePath = GetCacheFileLoadPath(bundle);
|
||||||
return _fileSystemManager.AccessSync(filePath);
|
return _recorders.Contains(filePath);
|
||||||
}
|
}
|
||||||
public virtual bool NeedDownload(PackageBundle bundle)
|
public virtual bool NeedDownload(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
|
@ -196,27 +206,80 @@ internal class ByteGameFileSystem : IFileSystem
|
||||||
|
|
||||||
public virtual string GetBundleFilePath(PackageBundle bundle)
|
public virtual string GetBundleFilePath(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
return GetCacheFileLoadPath(bundle);
|
||||||
}
|
}
|
||||||
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
|
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
string filePath = GetCacheFileLoadPath(bundle);
|
||||||
|
if (CheckCacheFileExist(filePath))
|
||||||
|
return _fileSystemMgr.ReadFileSync(filePath);
|
||||||
|
else
|
||||||
|
return Array.Empty<byte>();
|
||||||
}
|
}
|
||||||
public virtual string ReadBundleFileText(PackageBundle bundle)
|
public virtual string ReadBundleFileText(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
string filePath = GetCacheFileLoadPath(bundle);
|
||||||
|
if (CheckCacheFileExist(filePath))
|
||||||
|
return _fileSystemMgr.ReadFileSync(filePath, "utf8");
|
||||||
|
else
|
||||||
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 内部方法
|
#region 内部方法
|
||||||
|
public TTFileSystemManager GetFileSystemMgr()
|
||||||
|
{
|
||||||
|
return _fileSystemMgr;
|
||||||
|
}
|
||||||
|
public bool CheckCacheFileExist(string filePath)
|
||||||
|
{
|
||||||
|
return _fileSystemMgr.AccessSync(filePath);
|
||||||
|
}
|
||||||
private string GetCacheFileLoadPath(PackageBundle bundle)
|
private string GetCacheFileLoadPath(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
||||||
{
|
{
|
||||||
filePath = _fileSystemManager.GetLocalCachedPathForUrl(bundle.FileName);
|
filePath = _fileSystemMgr.GetLocalCachedPathForUrl(bundle.FileName);
|
||||||
_cacheFilePaths.Add(bundle.BundleGUID, filePath);
|
_cacheFilePaths.Add(bundle.BundleGUID, filePath);
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 本地记录
|
||||||
|
public List<string> GetAllRecords()
|
||||||
|
{
|
||||||
|
return _recorders.ToList();
|
||||||
|
}
|
||||||
|
public bool RecordBundleFile(string filePath)
|
||||||
|
{
|
||||||
|
if (_recorders.Contains(filePath))
|
||||||
|
{
|
||||||
|
YooLogger.Error($"{nameof(TiktokFileSystem)} has element : {filePath}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_recorders.Add(filePath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public void TryRecordBundle(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
string filePath = GetCacheFileLoadPath(bundle);
|
||||||
|
if (_recorders.Contains(filePath) == false)
|
||||||
|
{
|
||||||
|
_recorders.Add(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void ClearAllRecords()
|
||||||
|
{
|
||||||
|
_recorders.Clear();
|
||||||
|
}
|
||||||
|
public void ClearRecord(string filePath)
|
||||||
|
{
|
||||||
|
if (_recorders.Contains(filePath))
|
||||||
|
{
|
||||||
|
_recorders.Remove(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -11,13 +11,13 @@ internal class WXFSClearAllBundleFilesOperation : FSClearCacheFilesOperation
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
ClearAllCacheFiles,
|
ClearAllCacheFiles,
|
||||||
|
WaitResult,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly WechatFileSystem _fileSystem;
|
private readonly WechatFileSystem _fileSystem;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
internal WXFSClearAllBundleFilesOperation(WechatFileSystem fileSystem)
|
internal WXFSClearAllBundleFilesOperation(WechatFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
@ -33,16 +33,25 @@ internal class WXFSClearAllBundleFilesOperation : FSClearCacheFilesOperation
|
||||||
|
|
||||||
if (_steps == ESteps.ClearAllCacheFiles)
|
if (_steps == ESteps.ClearAllCacheFiles)
|
||||||
{
|
{
|
||||||
|
_steps = ESteps.WaitResult;
|
||||||
|
|
||||||
WX.CleanAllFileCache((bool isOk) =>
|
WX.CleanAllFileCache((bool isOk) =>
|
||||||
{
|
{
|
||||||
if (isOk)
|
if (isOk)
|
||||||
|
{
|
||||||
YooLogger.Log("微信缓存清理成功!");
|
YooLogger.Log("微信缓存清理成功!");
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
_fileSystem.ClearAllRecords();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
YooLogger.Log("微信缓存清理失败!");
|
YooLogger.Log("微信缓存清理失败!");
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = "微信缓存清理失败!";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,11 @@ using UnityEngine;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
using WeChatWASM;
|
using WeChatWASM;
|
||||||
|
|
||||||
|
|
||||||
internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
|
internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
GetAllCacheFiles,
|
|
||||||
WaitResult,
|
|
||||||
GetUnusedCacheFiles,
|
GetUnusedCacheFiles,
|
||||||
ClearUnusedCacheFiles,
|
ClearUnusedCacheFiles,
|
||||||
Done,
|
Done,
|
||||||
|
@ -22,7 +19,6 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
|
||||||
private readonly PackageManifest _manifest;
|
private readonly PackageManifest _manifest;
|
||||||
private List<string> _unusedCacheFiles;
|
private List<string> _unusedCacheFiles;
|
||||||
private int _unusedFileTotalCount = 0;
|
private int _unusedFileTotalCount = 0;
|
||||||
private GetSavedFileListSuccessCallbackResult _result;
|
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal WXFSClearUnusedBundleFilesAsync(WechatFileSystem fileSystem, PackageManifest manifest)
|
internal WXFSClearUnusedBundleFilesAsync(WechatFileSystem fileSystem, PackageManifest manifest)
|
||||||
|
@ -32,38 +28,13 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
|
||||||
}
|
}
|
||||||
internal override void InternalOnStart()
|
internal override void InternalOnStart()
|
||||||
{
|
{
|
||||||
_steps = ESteps.GetAllCacheFiles;
|
_steps = ESteps.GetUnusedCacheFiles;
|
||||||
}
|
}
|
||||||
internal override void InternalOnUpdate()
|
internal override void InternalOnUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.GetAllCacheFiles)
|
|
||||||
{
|
|
||||||
_steps = ESteps.WaitResult;
|
|
||||||
|
|
||||||
var fileSystemMgr = WX.GetFileSystemManager();
|
|
||||||
var option = new GetSavedFileListOption();
|
|
||||||
fileSystemMgr.GetSavedFileList(option);
|
|
||||||
option.fail += (FileError error) =>
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Error = error.errMsg;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
};
|
|
||||||
option.success += (GetSavedFileListSuccessCallbackResult result) =>
|
|
||||||
{
|
|
||||||
_result = result;
|
|
||||||
_steps = ESteps.GetUnusedCacheFiles;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.WaitResult)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.GetUnusedCacheFiles)
|
if (_steps == ESteps.GetUnusedCacheFiles)
|
||||||
{
|
{
|
||||||
_unusedCacheFiles = GetUnusedCacheFiles();
|
_unusedCacheFiles = GetUnusedCacheFiles();
|
||||||
|
@ -76,9 +47,10 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
|
||||||
{
|
{
|
||||||
for (int i = _unusedCacheFiles.Count - 1; i >= 0; i--)
|
for (int i = _unusedCacheFiles.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
string cacheFilePath = _unusedCacheFiles[i];
|
string clearFilePath = _unusedCacheFiles[i];
|
||||||
WX.RemoveFile(cacheFilePath, null);
|
|
||||||
_unusedCacheFiles.RemoveAt(i);
|
_unusedCacheFiles.RemoveAt(i);
|
||||||
|
_fileSystem.ClearRecord(clearFilePath);
|
||||||
|
WX.RemoveFile(clearFilePath, null);
|
||||||
|
|
||||||
if (OperationSystem.IsBusy)
|
if (OperationSystem.IsBusy)
|
||||||
break;
|
break;
|
||||||
|
@ -99,22 +71,23 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
|
||||||
|
|
||||||
private List<string> GetUnusedCacheFiles()
|
private List<string> GetUnusedCacheFiles()
|
||||||
{
|
{
|
||||||
List<string> result = new List<string>(_result.fileList.Length);
|
var allRecords = _fileSystem.GetAllRecords();
|
||||||
foreach (var fileInfo in _result.fileList)
|
List<string> result = new List<string>(allRecords.Count);
|
||||||
|
foreach (var filePath in allRecords)
|
||||||
{
|
{
|
||||||
// 如果存储文件名是按照Bundle文件哈希值存储
|
// 如果存储文件名是按照Bundle文件哈希值存储
|
||||||
string bundleGUID = Path.GetFileNameWithoutExtension(fileInfo.filePath);
|
string bundleGUID = Path.GetFileNameWithoutExtension(filePath);
|
||||||
if (_manifest.TryGetPackageBundleByBundleGUID(bundleGUID, out PackageBundle value) == false)
|
if (_manifest.TryGetPackageBundleByBundleGUID(bundleGUID, out PackageBundle value) == false)
|
||||||
{
|
{
|
||||||
result.Add(fileInfo.filePath);
|
result.Add(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果存储文件名是按照Bundle文件名称存储
|
// 如果存储文件名是按照Bundle文件名称存储
|
||||||
/*
|
/*
|
||||||
string bundleName = Path.GetFileNameWithoutExtension(fileInfo.filePath);
|
string bundleName = Path.GetFileNameWithoutExtension(filePath);
|
||||||
if (_manifest.TryGetPackageBundleByBundleName(bundleName, out PackageBundle value) == false)
|
if (_manifest.TryGetPackageBundleByBundleName(bundleName, out PackageBundle value) == false)
|
||||||
{
|
{
|
||||||
result.Add(fileInfo.filePath);
|
result.Add(filePath);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ internal class WXFSDownloadFileOperation : DefaultDownloadFileOperation
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
|
_fileSystem.TryRecordBundle(Bundle); //记录下载文件
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,16 @@ using YooAsset;
|
||||||
|
|
||||||
internal partial class WXFSInitializeOperation : FSInitializeFileSystemOperation
|
internal partial class WXFSInitializeOperation : FSInitializeFileSystemOperation
|
||||||
{
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
RecordCacheFiles,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
private readonly WechatFileSystem _fileSystem;
|
private readonly WechatFileSystem _fileSystem;
|
||||||
|
private RecordWechatCacheFilesOperation _recordWechatCacheFilesOp;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
public WXFSInitializeOperation(WechatFileSystem fileSystem)
|
public WXFSInitializeOperation(WechatFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
|
@ -11,10 +20,36 @@ internal partial class WXFSInitializeOperation : FSInitializeFileSystemOperation
|
||||||
}
|
}
|
||||||
internal override void InternalOnStart()
|
internal override void InternalOnStart()
|
||||||
{
|
{
|
||||||
Status = EOperationStatus.Succeed;
|
_steps = ESteps.RecordCacheFiles;
|
||||||
}
|
}
|
||||||
internal override void InternalOnUpdate()
|
internal override void InternalOnUpdate()
|
||||||
{
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.RecordCacheFiles)
|
||||||
|
{
|
||||||
|
if (_recordWechatCacheFilesOp == null)
|
||||||
|
{
|
||||||
|
_recordWechatCacheFilesOp = new RecordWechatCacheFilesOperation(_fileSystem);
|
||||||
|
OperationSystem.StartOperation(_fileSystem.PackageName, _recordWechatCacheFilesOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_recordWechatCacheFilesOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_recordWechatCacheFilesOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _recordWechatCacheFilesOp.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -61,6 +61,7 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
|
_fileSystem.TryRecordBundle(_bundle); //记录下载文件
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -6,16 +6,16 @@ internal class WXFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
RequestRemotePackageHash,
|
RequestPackageHash,
|
||||||
LoadRemotePackageManifest,
|
LoadPackageManifest,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly WechatFileSystem _fileSystem;
|
private readonly WechatFileSystem _fileSystem;
|
||||||
private readonly string _packageVersion;
|
private readonly string _packageVersion;
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
private RequestWechatPackageHashOperation _requestRemotePackageHashOp;
|
private RequestWechatPackageHashOperation _requestPackageHashOp;
|
||||||
private LoadWechatPackageManifestOperation _loadRemotePackageManifestOp;
|
private LoadWechatPackageManifestOperation _loadPackageManifestOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,60 +27,60 @@ internal class WXFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
|
||||||
}
|
}
|
||||||
internal override void InternalOnStart()
|
internal override void InternalOnStart()
|
||||||
{
|
{
|
||||||
_steps = ESteps.RequestRemotePackageHash;
|
_steps = ESteps.RequestPackageHash;
|
||||||
}
|
}
|
||||||
internal override void InternalOnUpdate()
|
internal override void InternalOnUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.RequestRemotePackageHash)
|
if (_steps == ESteps.RequestPackageHash)
|
||||||
{
|
{
|
||||||
if (_requestRemotePackageHashOp == null)
|
if (_requestPackageHashOp == null)
|
||||||
{
|
{
|
||||||
_requestRemotePackageHashOp = new RequestWechatPackageHashOperation(_fileSystem, _packageVersion, _timeout);
|
_requestPackageHashOp = new RequestWechatPackageHashOperation(_fileSystem, _packageVersion, _timeout);
|
||||||
OperationSystem.StartOperation(_fileSystem.PackageName, _requestRemotePackageHashOp);
|
OperationSystem.StartOperation(_fileSystem.PackageName, _requestPackageHashOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_requestRemotePackageHashOp.IsDone == false)
|
if (_requestPackageHashOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_requestRemotePackageHashOp.Status == EOperationStatus.Succeed)
|
if (_requestPackageHashOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
_steps = ESteps.LoadRemotePackageManifest;
|
_steps = ESteps.LoadPackageManifest;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _requestRemotePackageHashOp.Error;
|
Error = _requestPackageHashOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.LoadRemotePackageManifest)
|
if (_steps == ESteps.LoadPackageManifest)
|
||||||
{
|
{
|
||||||
if (_loadRemotePackageManifestOp == null)
|
if (_loadPackageManifestOp == null)
|
||||||
{
|
{
|
||||||
string packageHash = _requestRemotePackageHashOp.PackageHash;
|
string packageHash = _requestPackageHashOp.PackageHash;
|
||||||
_loadRemotePackageManifestOp = new LoadWechatPackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
|
_loadPackageManifestOp = new LoadWechatPackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
|
||||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadRemotePackageManifestOp);
|
OperationSystem.StartOperation(_fileSystem.PackageName, _loadPackageManifestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
Progress = _loadRemotePackageManifestOp.Progress;
|
Progress = _loadPackageManifestOp.Progress;
|
||||||
if (_loadRemotePackageManifestOp.IsDone == false)
|
if (_loadPackageManifestOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_loadRemotePackageManifestOp.Status == EOperationStatus.Succeed)
|
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Manifest = _loadRemotePackageManifestOp.Manifest;
|
Manifest = _loadPackageManifestOp.Manifest;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _loadRemotePackageManifestOp.Error;
|
Error = _loadPackageManifestOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||||
|
using YooAsset;
|
||||||
|
using WeChatWASM;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
internal class RecordWechatCacheFilesOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
RecordCacheFiles,
|
||||||
|
WaitResponse,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly WechatFileSystem _fileSystem;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
public RecordWechatCacheFilesOperation(WechatFileSystem fileSystem)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
}
|
||||||
|
internal override void InternalOnStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.RecordCacheFiles;
|
||||||
|
}
|
||||||
|
internal override void InternalOnUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.RecordCacheFiles)
|
||||||
|
{
|
||||||
|
_steps = ESteps.WaitResponse;
|
||||||
|
|
||||||
|
var fileSystemMgr = _fileSystem.GetFileSystemMgr();
|
||||||
|
var getSavedFileListOption = new GetSavedFileListOption();
|
||||||
|
getSavedFileListOption.success = (GetSavedFileListSuccessCallbackResult response) =>
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
foreach (var fileInfo in response.fileList)
|
||||||
|
{
|
||||||
|
//TODO 需要确认存储文件为Bundle文件
|
||||||
|
_fileSystem.RecordBundleFile(fileInfo.filePath);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getSavedFileListOption.fail = (FileError fileError) =>
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = fileError.errMsg;
|
||||||
|
};
|
||||||
|
fileSystemMgr.GetSavedFileList(getSavedFileListOption);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 640ec7bd883b8314db53b508278aea6e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -1,16 +1,17 @@
|
||||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
using WeChatWASM;
|
using WeChatWASM;
|
||||||
|
|
||||||
public static class WechatFileSystemCreater
|
public static class WechatFileSystemCreater
|
||||||
{
|
{
|
||||||
public static FileSystemParameters CreateWechatFileSystemParameters(IRemoteServices remoteServices)
|
public static FileSystemParameters CreateWechatFileSystemParameters(IRemoteServices remoteServices, string packageRoot)
|
||||||
{
|
{
|
||||||
string fileSystemClass = $"{nameof(WechatFileSystem)},YooAsset.RuntimeExtension";
|
string fileSystemClass = $"{nameof(WechatFileSystem)},YooAsset.RuntimeExtension";
|
||||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||||
fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices);
|
fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices);
|
||||||
return fileSystemParams;
|
return fileSystemParams;
|
||||||
}
|
}
|
||||||
|
@ -52,12 +53,10 @@ internal class WechatFileSystem : IFileSystem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private readonly HashSet<string> _recorders = new HashSet<string>();
|
||||||
/// Key:资源包GUID Value:缓存路径
|
|
||||||
/// </summary>
|
|
||||||
private readonly Dictionary<string, string> _cacheFilePaths = new Dictionary<string, string>(10000);
|
private readonly Dictionary<string, string> _cacheFilePaths = new Dictionary<string, string>(10000);
|
||||||
private WXFileSystemManager _wxFileSystemMgr;
|
private WXFileSystemManager _fileSystemMgr;
|
||||||
private string _fileCacheRoot = string.Empty;
|
private string _wxCacheRoot = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 包裹名称
|
/// 包裹名称
|
||||||
|
@ -71,7 +70,7 @@ internal class WechatFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _fileCacheRoot;
|
return _wxCacheRoot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +81,7 @@ internal class WechatFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return 0;
|
return _recorders.Count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +175,12 @@ internal class WechatFileSystem : IFileSystem
|
||||||
public virtual void OnCreate(string packageName, string rootDirectory)
|
public virtual void OnCreate(string packageName, string rootDirectory)
|
||||||
{
|
{
|
||||||
PackageName = packageName;
|
PackageName = packageName;
|
||||||
|
_wxCacheRoot = rootDirectory;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(_wxCacheRoot))
|
||||||
|
{
|
||||||
|
throw new System.Exception("请配置微信小游戏缓存根目录!");
|
||||||
|
}
|
||||||
|
|
||||||
// 注意:CDN服务未启用的情况下,使用微信WEB服务器
|
// 注意:CDN服务未启用的情况下,使用微信WEB服务器
|
||||||
if (RemoteServices == null)
|
if (RemoteServices == null)
|
||||||
|
@ -184,10 +189,7 @@ internal class WechatFileSystem : IFileSystem
|
||||||
RemoteServices = new WebRemoteServices(webRoot);
|
RemoteServices = new WebRemoteServices(webRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
_wxFileSystemMgr = WX.GetFileSystemManager();
|
_fileSystemMgr = WX.GetFileSystemManager();
|
||||||
_fileCacheRoot = $"{WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE";
|
|
||||||
//_fileCacheRoot = $"{WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE/子目录"; //注意:如果有子目录,请修改此处!
|
|
||||||
//_fileCacheRoot = PathUtility.Combine(WX.PluginCachePath, $"StreamingAssets/WebGL");
|
|
||||||
}
|
}
|
||||||
public virtual void OnUpdate()
|
public virtual void OnUpdate()
|
||||||
{
|
{
|
||||||
|
@ -200,7 +202,7 @@ internal class WechatFileSystem : IFileSystem
|
||||||
public virtual bool Exists(PackageBundle bundle)
|
public virtual bool Exists(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
string filePath = GetCacheFileLoadPath(bundle);
|
string filePath = GetCacheFileLoadPath(bundle);
|
||||||
return CheckCacheFileExist(filePath);
|
return _recorders.Contains(filePath);
|
||||||
}
|
}
|
||||||
public virtual bool NeedDownload(PackageBundle bundle)
|
public virtual bool NeedDownload(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
|
@ -226,7 +228,7 @@ internal class WechatFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
string filePath = GetCacheFileLoadPath(bundle);
|
string filePath = GetCacheFileLoadPath(bundle);
|
||||||
if (CheckCacheFileExist(filePath))
|
if (CheckCacheFileExist(filePath))
|
||||||
return _wxFileSystemMgr.ReadFileSync(filePath);
|
return _fileSystemMgr.ReadFileSync(filePath);
|
||||||
else
|
else
|
||||||
return Array.Empty<byte>();
|
return Array.Empty<byte>();
|
||||||
}
|
}
|
||||||
|
@ -234,26 +236,67 @@ internal class WechatFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
string filePath = GetCacheFileLoadPath(bundle);
|
string filePath = GetCacheFileLoadPath(bundle);
|
||||||
if (CheckCacheFileExist(filePath))
|
if (CheckCacheFileExist(filePath))
|
||||||
return _wxFileSystemMgr.ReadFileSync(filePath, "utf8");
|
return _fileSystemMgr.ReadFileSync(filePath, "utf8");
|
||||||
else
|
else
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 内部方法
|
#region 内部方法
|
||||||
|
public WXFileSystemManager GetFileSystemMgr()
|
||||||
|
{
|
||||||
|
return _fileSystemMgr;
|
||||||
|
}
|
||||||
public bool CheckCacheFileExist(string filePath)
|
public bool CheckCacheFileExist(string filePath)
|
||||||
{
|
{
|
||||||
string result = _wxFileSystemMgr.AccessSync(filePath);
|
string result = _fileSystemMgr.AccessSync(filePath);
|
||||||
return result.Equals("access:ok");
|
return result.Equals("access:ok");
|
||||||
}
|
}
|
||||||
public string GetCacheFileLoadPath(PackageBundle bundle)
|
public string GetCacheFileLoadPath(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
||||||
{
|
{
|
||||||
filePath = PathUtility.Combine(_fileCacheRoot, bundle.FileName);
|
filePath = PathUtility.Combine(_wxCacheRoot, bundle.FileName);
|
||||||
_cacheFilePaths.Add(bundle.BundleGUID, filePath);
|
_cacheFilePaths.Add(bundle.BundleGUID, filePath);
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 本地记录
|
||||||
|
public List<string> GetAllRecords()
|
||||||
|
{
|
||||||
|
return _recorders.ToList();
|
||||||
|
}
|
||||||
|
public bool RecordBundleFile(string filePath)
|
||||||
|
{
|
||||||
|
if (_recorders.Contains(filePath))
|
||||||
|
{
|
||||||
|
YooLogger.Error($"{nameof(WechatFileSystem)} has element : {filePath}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_recorders.Add(filePath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public void TryRecordBundle(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
string filePath = GetCacheFileLoadPath(bundle);
|
||||||
|
if (_recorders.Contains(filePath) == false)
|
||||||
|
{
|
||||||
|
_recorders.Add(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void ClearAllRecords()
|
||||||
|
{
|
||||||
|
_recorders.Clear();
|
||||||
|
}
|
||||||
|
public void ClearRecord(string filePath)
|
||||||
|
{
|
||||||
|
if (_recorders.Contains(filePath))
|
||||||
|
{
|
||||||
|
_recorders.Remove(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -129,13 +129,13 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
|
||||||
{
|
{
|
||||||
string fileRoot = GetBuildinYooRoot();
|
string fileRoot = GetBuildinYooRoot();
|
||||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
||||||
return PathUtility.Combine(fileRoot, fileName);
|
return PathUtility.Combine(fileRoot, _packageName, fileName);
|
||||||
}
|
}
|
||||||
private string GetBuildinManifestFilePath()
|
private string GetBuildinManifestFilePath()
|
||||||
{
|
{
|
||||||
string fileRoot = GetBuildinYooRoot();
|
string fileRoot = GetBuildinYooRoot();
|
||||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
||||||
return PathUtility.Combine(fileRoot, fileName);
|
return PathUtility.Combine(fileRoot, _packageName, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetCacheYooRoot()
|
private string GetCacheYooRoot()
|
||||||
|
@ -146,12 +146,12 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
|
||||||
{
|
{
|
||||||
string fileRoot = GetCacheYooRoot();
|
string fileRoot = GetCacheYooRoot();
|
||||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
||||||
return PathUtility.Combine(fileRoot, fileName);
|
return PathUtility.Combine(fileRoot, _packageName, fileName);
|
||||||
}
|
}
|
||||||
private string GetCacheManifestFilePath()
|
private string GetCacheManifestFilePath()
|
||||||
{
|
{
|
||||||
string fileRoot = GetCacheYooRoot();
|
string fileRoot = GetCacheYooRoot();
|
||||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
||||||
return PathUtility.Combine(fileRoot, fileName);
|
return PathUtility.Combine(fileRoot, _packageName, fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"references": [
|
"references": [
|
||||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||||
"GUID:5efd170ecd8084500bed5692932fe14e",
|
"GUID:5efd170ecd8084500bed5692932fe14e",
|
||||||
"GUID:0f8df04a5a494444eb8fa0504f6fb965"
|
"GUID:bb21d6197862c4c3e863390dec9859a7"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|
Loading…
Reference in New Issue