refactor : 代码重构

This commit is contained in:
何冠峰
2026-01-12 11:09:27 +08:00
committed by 何冠峰
parent d228e41df7
commit 5b81269090
1614 changed files with 44418 additions and 42154 deletions

View File

@@ -14,7 +14,7 @@ namespace YooAsset.Editor
UnityEditor.Build.Pipeline.Utilities.BuildCache.PurgeCache(false);
// 删除AssetDependDB文件
string projectPath = YooAsset.Editor.EditorTools.GetProjectPath();
string projectPath = YooAsset.Editor.EditorPathUtility.GetProjectPath();
string databaseFilePath = $"{projectPath}/Library/AssetDependencyDB";
if (File.Exists(databaseFilePath))
{

View File

@@ -55,7 +55,7 @@ namespace YooAsset.Editor
string packageName = directoryInfo.Name;
try
{
bool result = CatalogTools.CreateCatalogFile(null, packageName, packageRoot); //TODO 自行处理解密
bool result = BuiltinCatalogHelper.CreateFile(null, packageName, packageRoot); //TODO 自行处理解密
if (result == false)
{
Debug.LogError($"Create package {packageName} catalog file failed ! See the detail error in console !");

View File

@@ -34,7 +34,7 @@ namespace YooAsset.Editor
{
if (GUILayout.Button("生成空的Catalog文件", GUILayout.MaxWidth(150)))
{
string outputPath = EditorTools.OpenFolderPanel("输出目录", "Assets/");
string outputPath = EditorDialogUtility.OpenFolderPanel("输出目录", "Assets/");
if (string.IsNullOrEmpty(outputPath) == false)
{
CreateEmptyCatalogFile(outputPath);
@@ -47,7 +47,7 @@ namespace YooAsset.Editor
{
try
{
bool result = CatalogTools.CreateEmptyCatalogFile(_packageName, string.Empty, outputPath);
bool result = BuiltinCatalogHelper.CreateEmptyFile(_packageName, string.Empty, outputPath);
if (result == false)
{
Debug.LogError($"Create package {_packageName} catalog file failed ! See the detail error in console !");

View File

@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
using YooAsset.Editor;
[BuildPipelineAttribute("CustomBuildPipeline")]
internal class CustomBuildPipelineViewer : BuiltinBuildPipelineViewer
internal class CustomBuildPipelineViewer : LegacyBuildPipelineViewer
{
protected override string GetDefaultPackageVersion()
{

View File

@@ -6,11 +6,11 @@ using UnityEngine;
using YooAsset.Editor;
[DisplayName("打包特效纹理(自定义)")]
public class PackEffectTexture : IPackRule
public class PackEffectTexture : IBundlePackRule
{
private const string PackDirectory = "Assets/Effect/Textures/";
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
BundlePackRuleResult IBundlePackRule.GetPackRuleResult(BundlePackRuleData data)
{
string assetPath = data.AssetPath;
if (assetPath.StartsWith(PackDirectory) == false)
@@ -19,20 +19,20 @@ public class PackEffectTexture : IPackRule
string assetName = Path.GetFileName(assetPath).ToLower();
string firstChar = assetName.Substring(0, 1);
string bundleName = $"{PackDirectory}effect_texture_{firstChar}";
var packRuleResult = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
var packRuleResult = new BundlePackRuleResult(bundleName, DefaultBundlePackRule.AssetBundleFileExtension);
return packRuleResult;
}
}
[DisplayName("打包视频(自定义)")]
public class PackVideo : IPackRule
public class PackVideo : IBundlePackRule
{
public PackRuleResult GetPackRuleResult(PackRuleData data)
public BundlePackRuleResult GetPackRuleResult(BundlePackRuleData data)
{
string bundleName = RemoveExtension(data.AssetPath);
string fileExtension = Path.GetExtension(data.AssetPath);
fileExtension = fileExtension.Remove(0, 1);
PackRuleResult result = new PackRuleResult(bundleName, fileExtension);
BundlePackRuleResult result = new BundlePackRuleResult(bundleName, fileExtension);
return result;
}

View File

@@ -106,11 +106,11 @@ namespace YooAsset.Editor
// 加载补丁清单1
byte[] bytesData1 = FileUtility.ReadAllBytes(_manifestPath1);
PackageManifest manifest1 = ManifestTools.DeserializeFromBinary(bytesData1, null); //TODO 自行处理解密
PackageManifest manifest1 = PackageManifestHelper.DeserializeManifestFromBinary(bytesData1, null); //TODO 自行处理解密
// 加载补丁清单1
byte[] bytesData2 = FileUtility.ReadAllBytes(_manifestPath2);
PackageManifest manifest2 = ManifestTools.DeserializeFromBinary(bytesData2, null); //TODO 自行处理解密
PackageManifest manifest2 = PackageManifestHelper.DeserializeManifestFromBinary(bytesData2, null); //TODO 自行处理解密
// 拷贝文件列表
foreach (var bundle2 in manifest2.BundleList)

View File

@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using UnityEngine;
using UnityEditor;
@@ -39,8 +39,8 @@ namespace YooAsset.Editor
{
if (GUILayout.Button("导入补丁包(全部文件)", GUILayout.MaxWidth(150)))
{
string streamingAssetsRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
EditorTools.ClearFolder(streamingAssetsRoot);
string streamingAssetsRoot = BundleBuilderHelper.GetStreamingAssetsRoot();
EditorFileUtility.ClearFolder(streamingAssetsRoot);
CopyPackageFiles(_manifestPath);
}
}
@@ -54,33 +54,33 @@ namespace YooAsset.Editor
// 拷贝核心文件
{
string sourcePath = $"{outputDirectory}/{manifestFileName}.bytes";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.bytes";
EditorTools.CopyFile(sourcePath, destPath, true);
string destPath = $"{BundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.bytes";
EditorFileUtility.CopyFile(sourcePath, destPath, true);
}
{
string sourcePath = $"{outputDirectory}/{manifestFileName}.hash";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.hash";
EditorTools.CopyFile(sourcePath, destPath, true);
string destPath = $"{BundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.hash";
EditorFileUtility.CopyFile(sourcePath, destPath, true);
}
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
string fileName = YooAssetConfiguration.GetPackageVersionFileName(_packageName);
string sourcePath = $"{outputDirectory}/{fileName}";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{fileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
string destPath = $"{BundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{fileName}";
EditorFileUtility.CopyFile(sourcePath, destPath, true);
}
// 加载补丁清单
byte[] bytesData = FileUtility.ReadAllBytes(manifestFilePath);
PackageManifest manifest = ManifestTools.DeserializeFromBinary(bytesData, null); //TODO 自行处理解密
PackageManifest manifest = PackageManifestHelper.DeserializeManifestFromBinary(bytesData, null); //TODO 自行处理解密
// 拷贝文件列表
int fileCount = 0;
foreach (var packageBundle in manifest.BundleList)
{
fileCount++;
string sourcePath = $"{outputDirectory}/{packageBundle.FileName}";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{packageBundle.FileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
string sourcePath = $"{outputDirectory}/{packageBundle.GetFileName()}";
string destPath = $"{BundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{packageBundle.GetFileName()}";
EditorFileUtility.CopyFile(sourcePath, destPath, true);
}
Debug.Log($"补丁包拷贝完成,一共拷贝了{fileCount}个资源文件");

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using YooAsset.Editor;
namespace YooAsset
{
@@ -16,7 +17,7 @@ namespace YooAsset
{
YooLogger.Log("Begin to create catalog file !");
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
string rootPath = BundleBuilderHelper.GetStreamingAssetsRoot();
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists == false)
{
@@ -32,7 +33,7 @@ namespace YooAsset
string pacakgeDirectory = subDirectory.FullName;
try
{
bool result = CatalogTools.CreateCatalogFile(null, packageName, pacakgeDirectory); //TODO 自行处理解密
bool result = BuiltinCatalogHelper.CreateFile(null, packageName, pacakgeDirectory); //TODO 自行处理解密
if (result == false)
{
Debug.LogError($"Create package {packageName} catalog file failed ! See the detail error in console !");

View File

@@ -11,19 +11,19 @@ public static class ShaderVariantCollectionHelper
{
public static void ClearCurrentShaderVariantCollection()
{
EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "ClearCurrentShaderVariantCollection");
EditorAssemblyUtility.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "ClearCurrentShaderVariantCollection");
}
public static void SaveCurrentShaderVariantCollection(string savePath)
{
EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "SaveCurrentShaderVariantCollection", savePath);
EditorAssemblyUtility.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "SaveCurrentShaderVariantCollection", savePath);
}
public static int GetCurrentShaderVariantCollectionShaderCount()
{
return (int)EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetCurrentShaderVariantCollectionShaderCount");
return (int)EditorAssemblyUtility.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetCurrentShaderVariantCollectionShaderCount");
}
public static int GetCurrentShaderVariantCollectionVariantCount()
{
return (int)EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetCurrentShaderVariantCollectionVariantCount");
return (int)EditorAssemblyUtility.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetCurrentShaderVariantCollectionVariantCount");
}
/// <summary>
@@ -32,7 +32,7 @@ public static class ShaderVariantCollectionHelper
public static string GetShaderVariantCount(string assetPath)
{
Shader shader = AssetDatabase.LoadAssetAtPath<Shader>(assetPath);
var variantCount = EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetVariantCount", shader, true);
var variantCount = EditorAssemblyUtility.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetVariantCount", shader, true);
return variantCount.ToString();
}
}

View File

@@ -50,14 +50,14 @@ public static class ShaderVariantCollector
// 注意先删除再保存否则ShaderVariantCollection内容将无法及时刷新
AssetDatabase.DeleteAsset(savePath);
EditorTools.CreateFileDirectory(savePath);
EditorFileUtility.CreateFileDirectory(savePath);
_savePath = savePath;
_packageName = packageName;
_processMaxNum = processMaxNum;
_completedCallback = completedCallback;
// 聚焦到游戏窗口
EditorTools.FocusUnityGameWindow();
EditorWindowUtility.FocusUnityGameWindow();
// 创建临时测试场景
CreateTempScene();
@@ -142,7 +142,7 @@ public static class ShaderVariantCollector
private static List<string> GetAllMaterials()
{
// 获取所有打包的资源
CollectResult collectResult = AssetBundleCollectorSettingData.Setting.BeginCollect(_packageName, false, false);
CollectResult collectResult = BundleCollectorSettingData.Setting.BeginCollect(_packageName, false, false);
// 搜集所有材质球
int progressValue = 0;
@@ -164,9 +164,9 @@ public static class ShaderVariantCollector
result.Add(assetPath);
}
}
EditorTools.DisplayProgressBar("搜集所有材质球", ++progressValue, collectResult.CollectAssets.Count);
EditorDialogUtility.DisplayProgressBar("搜集所有材质球", ++progressValue, collectResult.CollectAssets.Count);
}
EditorTools.ClearProgressBar();
EditorDialogUtility.ClearProgressBar();
// 返回结果
return result.ToList();
@@ -208,9 +208,9 @@ public static class ShaderVariantCollector
{
x++;
}
EditorTools.DisplayProgressBar("照射所有材质球", ++progressValue, materials.Count);
EditorDialogUtility.DisplayProgressBar("照射所有材质球", ++progressValue, materials.Count);
}
EditorTools.ClearProgressBar();
EditorDialogUtility.ClearProgressBar();
}
private static GameObject CreateSphere(string assetPath, Vector3 position, int index)
{

View File

@@ -1,5 +1,4 @@
#if UNITY_2019_4_OR_NEWER
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
@@ -34,7 +33,7 @@ public class ShaderVariantCollectorWindow : EditorWindow
VisualElement root = this.rootVisualElement;
// 加载布局文件
var visualAsset = UxmlLoader.LoadWindowUXML<ShaderVariantCollectorWindow>();
var visualAsset = UxmlLoader.LoadWindowUxml<ShaderVariantCollectorWindow>();
if (visualAsset == null)
return;
@@ -140,11 +139,10 @@ public class ShaderVariantCollectorWindow : EditorWindow
private List<string> GetBuildPackageNames()
{
List<string> result = new List<string>();
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
foreach (var package in BundleCollectorSettingData.Setting.Packages)
{
result.Add(package.PackageName);
}
return result;
}
}
#endif
}

View File

@@ -0,0 +1,502 @@
using System.Collections.Generic;
using UnityEngine;
using YooAsset;
#region InitializeParameters
/// <summary>
/// 初始化参数
/// </summary>
public abstract class InitializeParameters
{
/// <summary>
/// 同时加载Bundle文件的最大并发数
/// </summary>
public int BundleLoadingMaxConcurrency = int.MaxValue;
/// <summary>
/// 当资源引用计数为零的时候自动释放资源包
/// </summary>
public bool AutoUnloadBundleWhenUnused = false;
/// <summary>
/// WebGL平台强制同步加载资源对象
/// </summary>
public bool WebGLForceSyncLoadAsset = false;
}
/// <summary>
/// 编辑器下模拟运行模式的初始化参数
/// </summary>
public class EditorSimulateModeParameters : InitializeParameters
{
public FileSystemParameters EditorFileSystemParameters;
}
/// <summary>
/// 离线运行模式的初始化参数
/// </summary>
public class OfflinePlayModeParameters : InitializeParameters
{
public FileSystemParameters BuiltinFileSystemParameters;
}
/// <summary>
/// 联机运行模式的初始化参数
/// </summary>
public class HostPlayModeParameters : InitializeParameters
{
public FileSystemParameters BuiltinFileSystemParameters;
public FileSystemParameters CacheFileSystemParameters;
}
/// <summary>
/// WebGL运行模式的初始化参数
/// </summary>
public class WebPlayModeParameters : InitializeParameters
{
public FileSystemParameters WebServerFileSystemParameters;
public FileSystemParameters WebRemoteFileSystemParameters;
}
#endregion
#region InitializationOperation
public class InitializationOperation : AsyncOperationBase
{
private bool _isDone = false;
private readonly InitializePackageOperation _operation;
internal InitializationOperation(InitializePackageOperation op)
{
_operation = op;
}
protected override void InternalStart()
{
}
protected override void InternalUpdate()
{
if (_isDone)
return;
_operation.UpdateOperation();
if (_operation.IsDone == false)
return;
_isDone = true;
if (_operation.Status == EOperationStatus.Succeeded)
SetResult();
else
SetError(_operation.Error);
}
}
#endregion
#region DestroyOperation
public class DestroyOperation : AsyncOperationBase
{
private bool _isDone = false;
private readonly DestroyPackageOperation _operation;
internal DestroyOperation(DestroyPackageOperation op)
{
_operation = op;
}
protected override void InternalStart()
{
}
protected override void InternalUpdate()
{
if (_isDone)
return;
_operation.UpdateOperation();
if (_operation.IsDone == false)
return;
_isDone = true;
if (_operation.Status == EOperationStatus.Succeeded)
SetResult();
else
SetError(_operation.Error);
}
}
#endregion
#region UpdatePackageManifestOperation
public class UpdatePackageManifestOperation : AsyncOperationBase
{
private bool _isDone = false;
private readonly LoadPackageManifestOperation _operation;
internal UpdatePackageManifestOperation(LoadPackageManifestOperation op)
{
_operation = op;
}
protected override void InternalStart()
{
}
protected override void InternalUpdate()
{
if (_isDone)
return;
_operation.UpdateOperation();
if (_operation.IsDone == false)
return;
_isDone = true;
if (_operation.Status == EOperationStatus.Succeeded)
SetResult();
else
SetError(_operation.Error);
}
}
#endregion
#region ImportFileInfo
public struct ImportFileInfo
{
/// <summary>
/// 本地文件路径
/// </summary>
public string FilePath;
/// <summary>
/// 资源包名称
/// </summary>
public string BundleName;
/// <summary>
/// 资源包GUID
/// </summary>
public string BundleGuid;
}
#endregion
public static class CompatibleResourcePackage
{
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static InitializationOperation InitializeAsync(this ResourcePackage package, InitializeParameters parameters)
{
if (parameters is EditorSimulateModeParameters)
{
var initializeParameters = parameters as EditorSimulateModeParameters;
var options = new EditorSimulateModeOptions();
options.BundleLoadingMaxConcurrency = initializeParameters.BundleLoadingMaxConcurrency;
options.AutoUnloadBundleWhenUnused = initializeParameters.AutoUnloadBundleWhenUnused;
options.WebGLForceSyncLoadAsset = initializeParameters.WebGLForceSyncLoadAsset;
options.EditorFileSystemParameters = initializeParameters.EditorFileSystemParameters;
var operation = package.InitializePackageAsync(options);
var wrapper = new InitializationOperation(operation);
AsyncOperationSystem.StartOperation(package.PackageName, wrapper);
return wrapper;
}
else if (parameters is OfflinePlayModeParameters)
{
var initializeParameters = parameters as OfflinePlayModeParameters;
var options = new OfflinePlayModeOptions();
options.BundleLoadingMaxConcurrency = initializeParameters.BundleLoadingMaxConcurrency;
options.AutoUnloadBundleWhenUnused = initializeParameters.AutoUnloadBundleWhenUnused;
options.WebGLForceSyncLoadAsset = initializeParameters.WebGLForceSyncLoadAsset;
options.BuiltinFileSystemParameters = initializeParameters.BuiltinFileSystemParameters;
var operation = package.InitializePackageAsync(options);
var wrapper = new InitializationOperation(operation);
AsyncOperationSystem.StartOperation(package.PackageName, wrapper);
return wrapper;
}
else if (parameters is HostPlayModeParameters)
{
var initializeParameters = parameters as HostPlayModeParameters;
var options = new HostPlayModeOptions();
options.BundleLoadingMaxConcurrency = initializeParameters.BundleLoadingMaxConcurrency;
options.AutoUnloadBundleWhenUnused = initializeParameters.AutoUnloadBundleWhenUnused;
options.WebGLForceSyncLoadAsset = initializeParameters.WebGLForceSyncLoadAsset;
options.BuiltinFileSystemParameters = initializeParameters.BuiltinFileSystemParameters;
options.CacheFileSystemParameters = initializeParameters.CacheFileSystemParameters;
var operation = package.InitializePackageAsync(options);
var wrapper = new InitializationOperation(operation);
AsyncOperationSystem.StartOperation(package.PackageName, wrapper);
return wrapper;
}
else if (parameters is WebPlayModeParameters)
{
var initializeParameters = parameters as WebPlayModeParameters;
var options = new WebPlayModeOptions();
options.BundleLoadingMaxConcurrency = initializeParameters.BundleLoadingMaxConcurrency;
options.AutoUnloadBundleWhenUnused = initializeParameters.AutoUnloadBundleWhenUnused;
options.WebGLForceSyncLoadAsset = initializeParameters.WebGLForceSyncLoadAsset;
options.WebServerFileSystemParameters = initializeParameters.WebServerFileSystemParameters;
options.WebRemoteFileSystemParameters = initializeParameters.WebRemoteFileSystemParameters;
var operation = package.InitializePackageAsync(options);
var wrapper = new InitializationOperation(operation);
AsyncOperationSystem.StartOperation(package.PackageName, wrapper);
return wrapper;
}
else
{
throw new System.NotImplementedException();
}
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static DestroyOperation DestroyAsync(this ResourcePackage package)
{
var operation = package.DestroyPackageAsync();
var wrapper = new DestroyOperation(operation);
AsyncOperationSystem.StartOperation(package.PackageName, wrapper);
return wrapper;
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static RequestPackageVersionOperation RequestPackageVersionAsync(this ResourcePackage package, bool appendTimeTicks = true, int timeout = 60)
{
var options = new RequestPackageVersionOptions(appendTimeTicks, timeout);
return package.RequestPackageVersionAsync(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static UpdatePackageManifestOperation UpdatePackageManifestAsync(this ResourcePackage package, string packageVersion, int timeout = 60)
{
var options = new LoadPackageManifestOptions(packageVersion, timeout);
var operation = package.LoadPackageManifestAsync(options);
var wrapper = new UpdatePackageManifestOperation(operation);
AsyncOperationSystem.StartOperation(package.PackageName, wrapper);
return wrapper;
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static PrefetchManifestOperation PreDownloadContentAsync(this ResourcePackage package, string packageVersion, int timeout = 60)
{
var options = new PrefetchManifestOptions(packageVersion, timeout);
return package.PrefetchManifestAsync(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ClearCacheOperation ClearCacheFilesAsync(this ResourcePackage package, string fileClearMode, object clearParam = null)
{
var options = new ClearCacheOptions(fileClearMode, clearParam);
return package.ClearCacheAsync(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync(this ResourcePackage package, int loopCount)
{
var options = new UnloadUnusedAssetsOptions(loopCount);
return package.UnloadUnusedAssetsAsync(options);
}
#region
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateResourceDownloader(this ResourcePackage package, int downloadingMaxNumber, int failedTryAgain)
{
var options = new ResourceDownloaderOptions(downloadingMaxNumber, failedTryAgain);
return package.CreateResourceDownloader(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateResourceDownloader(this ResourcePackage package, string tag, int downloadingMaxNumber, int failedTryAgain)
{
string[] tags = new string[] { tag };
var options = new ResourceDownloaderOptions(tags, downloadingMaxNumber, failedTryAgain);
return package.CreateResourceDownloader(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateResourceDownloader(this ResourcePackage package, string[] tags, int downloadingMaxNumber, int failedTryAgain)
{
var options = new ResourceDownloaderOptions(tags, downloadingMaxNumber, failedTryAgain);
return package.CreateResourceDownloader(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
var assetInfo = package.ConvertLocationToAssetInfo(location, null);
var options = new BundleDownloaderOptions(assetInfo, recursiveDownload, downloadingMaxNumber, failedTryAgain);
return package.CreateResourceDownloader(options);
}
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string location, int downloadingMaxNumber, int failedTryAgain)
{
return package.CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
foreach (var location in locations)
{
var assetInfo = package.ConvertLocationToAssetInfo(location, null);
assetInfos.Add(assetInfo);
}
var options = new BundleDownloaderOptions(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain);
return package.CreateResourceDownloader(options);
}
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string[] locations, int downloadingMaxNumber, int failedTryAgain)
{
return package.CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo assetInfo, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
return package.CreateResourceDownloader(options);
}
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain)
{
return package.CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
return package.CreateResourceDownloader(options);
}
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
{
return package.CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain);
}
#endregion
#region
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceUnpackerOperation CreateResourceUnpacker(this ResourcePackage package, int unpackingMaxNumber, int failedTryAgain)
{
var options = new ResourceUnpackerOptions(unpackingMaxNumber, failedTryAgain);
return package.CreateResourceUnpacker(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceUnpackerOperation CreateResourceUnpacker(this ResourcePackage package, string tag, int unpackingMaxNumber, int failedTryAgain)
{
string[] tags = new string[] { tag };
var options = new ResourceUnpackerOptions(tags, unpackingMaxNumber, failedTryAgain);
return package.CreateResourceUnpacker(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceUnpackerOperation CreateResourceUnpacker(this ResourcePackage package, string[] tags, int unpackingMaxNumber, int failedTryAgain)
{
var options = new ResourceUnpackerOptions(tags, unpackingMaxNumber, failedTryAgain);
return package.CreateResourceUnpacker(options);
}
#endregion
#region
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceImporterOperation CreateResourceImporter(this ResourcePackage package, string[] filePaths, int importerMaxNumber, int failedTryAgain)
{
ImportFileInfo[] fileInfos = new ImportFileInfo[filePaths.Length];
for (int i = 0; i < filePaths.Length; i++)
{
ImportFileInfo fileInfo = new ImportFileInfo();
fileInfo.FilePath = filePaths[i];
fileInfos[i] = fileInfo;
}
return package.CreateResourceImporter(fileInfos, importerMaxNumber, failedTryAgain);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceImporterOperation CreateResourceImporter(this ResourcePackage package, ImportFileInfo[] fileInfos, int importerMaxNumber, int failedTryAgain)
{
ImportBundleInfo[] bundleInfos = new ImportBundleInfo[fileInfos.Length];
for (int i = 0; i < fileInfos.Length; i++)
{
bundleInfos[i] = new ImportBundleInfo(
filePath: fileInfos[i].FilePath,
bundleName: fileInfos[i].BundleName,
bundleGuid: fileInfos[i].BundleGuid);
}
var options = new BundleImporterOptions(bundleInfos, importerMaxNumber, failedTryAgain);
return package.CreateResourceImporter(options);
}
#endregion
}
public static class CompatibleAssetHandle
{
public static GameObject InstantiateSync(this AssetHandle handle, Transform parent)
{
var options = new InstantiateOptions(true, parent, false);
return handle.InstantiateSync(options);
}
public static GameObject InstantiateSync(this AssetHandle handle, Transform parent, bool worldPositionStays)
{
var options = new InstantiateOptions(true, parent, worldPositionStays);
return handle.InstantiateSync(options);
}
public static GameObject InstantiateSync(this AssetHandle handle, Vector3 position, Quaternion rotation)
{
var options = new InstantiateOptions(true, position, rotation);
return handle.InstantiateSync(options);
}
public static GameObject InstantiateSync(this AssetHandle handle, Vector3 position, Quaternion rotation, Transform parent)
{
var options = new InstantiateOptions(true, parent, position, rotation);
return handle.InstantiateSync(options);
}
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Transform parent, bool actived = true)
{
var options = new InstantiateOptions(actived, parent, false);
return handle.InstantiateAsync(options);
}
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Transform parent, bool worldPositionStays, bool actived = true)
{
var options = new InstantiateOptions(actived, parent, worldPositionStays);
return handle.InstantiateAsync(options);
}
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Vector3 position, Quaternion rotation, bool actived = true)
{
var options = new InstantiateOptions(actived, position, rotation);
return handle.InstantiateAsync(options);
}
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Vector3 position, Quaternion rotation, Transform parent, bool actived = true)
{
var options = new InstantiateOptions(actived, parent, position, rotation);
return handle.InstantiateAsync(options);
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 71a99a94d7563fe4a9d56ea0e15aa8d1
guid: b974d3d744622f3499d026f99074cd72
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -7,6 +7,6 @@ public static class HandleBaseExtension
{
public static bool IsSucceed(this HandleBase thisHandle)
{
return thisHandle.IsDone && thisHandle.Status == EOperationStatus.Succeed;
return thisHandle.IsDone && thisHandle.Status == EOperationStatus.Succeeded;
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
@@ -7,7 +7,7 @@ using YooAsset;
/// <summary>
/// 拷贝内置清单文件到沙盒目录
/// </summary>
public class CopyBuildinManifestOperation : GameAsyncOperation
public class CopyBuildinManifestOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -22,8 +22,8 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
private readonly string _packageName;
private readonly string _packageVersion;
private readonly IDownloadBackend _backend;
private IDownloadFileRequest _hashFileRequestOp;
private IDownloadFileRequest _manifestFileRequestOp;
private IDownloadFileRequest _hashFileRequest;
private IDownloadFileRequest _manifestFileRequest;
private ESteps _steps = ESteps.None;
public CopyBuildinManifestOperation(string packageName, string packageVersion)
@@ -32,11 +32,11 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
_packageVersion = packageVersion;
_backend = new UnityWebRequestBackend();
}
protected override void OnStart()
protected override void InternalStart()
{
_steps = ESteps.CheckHashFile;
}
protected override void OnUpdate()
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
@@ -55,28 +55,27 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
if (_steps == ESteps.UnpackHashFile)
{
if(_hashFileRequestOp == null)
if(_hashFileRequest == null)
{
string sourcePath = GetBuildinHashFilePath();
string destPath = GetCacheHashFilePath();
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
var args = new DownloadFileRequestArgs(url, destPath, 60, 0);
_hashFileRequestOp = _backend.CreateFileRequest(args);
_hashFileRequestOp.SendRequest();
string url = DownloadUrlHelper.ToLocalFileUrl(sourcePath);
var args = new DownloadFileRequestArgs(url, 60, 0, destPath);
_hashFileRequest = _backend.CreateFileRequest(args);
_hashFileRequest.SendRequest();
}
if (_hashFileRequestOp.IsDone == false)
if (_hashFileRequest.IsDone == false)
return;
if (_hashFileRequestOp.Status == EDownloadRequestStatus.Succeed)
if (_hashFileRequest.Status == EDownloadRequestStatus.Succeeded)
{
_steps = ESteps.CheckManifestFile;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _hashFileRequestOp.Error;
SetError(_hashFileRequest.Error);
}
}
@@ -86,7 +85,7 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
if (File.Exists(manifestFilePath))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
SetResult();
return;
}
@@ -95,67 +94,63 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
if (_steps == ESteps.UnpackManifestFile)
{
if (_manifestFileRequestOp == null)
if (_manifestFileRequest == null)
{
string sourcePath = GetBuildinManifestFilePath();
string destPath = GetCacheManifestFilePath();
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
var args = new DownloadFileRequestArgs(url, destPath, 60, 0);
_manifestFileRequestOp = _backend.CreateFileRequest(args);
_manifestFileRequestOp.SendRequest();
string url = DownloadUrlHelper.ToLocalFileUrl(sourcePath);
var args = new DownloadFileRequestArgs(url, 60, 0, destPath);
_manifestFileRequest = _backend.CreateFileRequest(args);
_manifestFileRequest.SendRequest();
}
if (_manifestFileRequestOp.IsDone == false)
if (_manifestFileRequest.IsDone == false)
return;
if (_manifestFileRequestOp.Status == EDownloadRequestStatus.Succeed)
if (_manifestFileRequest.Status == EDownloadRequestStatus.Succeeded)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
SetResult();
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _manifestFileRequestOp.Error;
SetError(_manifestFileRequest.Error);
}
}
}
protected override void OnAbort()
{
}
private string GetBuildinYooRoot()
{
return YooAssetSettingsData.GetYooDefaultBuildinRoot();
return YooAssetConfiguration.GetDefaultBuiltinRoot();
}
private string GetBuildinHashFilePath()
{
string fileRoot = GetBuildinYooRoot();
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
string fileName = YooAssetConfiguration.GetPackageHashFileName(_packageName, _packageVersion);
return PathUtility.Combine(fileRoot, _packageName, fileName);
}
private string GetBuildinManifestFilePath()
{
string fileRoot = GetBuildinYooRoot();
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
string fileName = YooAssetConfiguration.GetManifestBinaryFileName(_packageName, _packageVersion);
return PathUtility.Combine(fileRoot, _packageName, fileName);
}
private string GetCacheYooRoot()
{
return YooAssetSettingsData.GetYooDefaultCacheRoot();
return YooAssetConfiguration.GetDefaultCacheRoot();
}
private string GetCacheHashFilePath()
{
string fileRoot = GetCacheYooRoot();
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
string fileName = YooAssetConfiguration.GetPackageHashFileName(_packageName, _packageVersion);
return PathUtility.Combine(fileRoot, _packageName, fileName);
}
private string GetCacheManifestFilePath()
{
string fileRoot = GetCacheYooRoot();
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
string fileName = YooAssetConfiguration.GetManifestBinaryFileName(_packageName, _packageVersion);
return PathUtility.Combine(fileRoot, _packageName, fileName);
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
@@ -7,7 +7,7 @@ using YooAsset;
/// <summary>
/// 获取包体里的内置资源清单版本
/// </summary>
public class GetBuildinPackageVersionOperation : GameAsyncOperation
public class GetBuildinPackageVersionOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -18,7 +18,7 @@ public class GetBuildinPackageVersionOperation : GameAsyncOperation
private readonly string _packageName;
private readonly IDownloadBackend _backend;
private IDownloadTextRequest _versionFileRequestOp;
private IDownloadTextRequest _downloadTextRequest;
private ESteps _steps = ESteps.None;
/// <summary>
@@ -31,55 +31,51 @@ public class GetBuildinPackageVersionOperation : GameAsyncOperation
_packageName = packageName;
_backend = new UnityWebRequestBackend();
}
protected override void OnStart()
protected override void InternalStart()
{
_steps = ESteps.GetPackageVersion;
}
protected override void OnUpdate()
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.GetPackageVersion)
{
if (_versionFileRequestOp == null)
if (_downloadTextRequest == null)
{
string filePath = GetBuildinPackageVersionFilePath();
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
string url = DownloadUrlHelper.ToLocalFileUrl(filePath);
var args = new DownloadDataRequestArgs(url, 60, 0);
_versionFileRequestOp = _backend.CreateTextRequest(args);
_versionFileRequestOp.SendRequest();
_downloadTextRequest = _backend.CreateTextRequest(args);
_downloadTextRequest.SendRequest();
}
if (_versionFileRequestOp.IsDone == false)
if (_downloadTextRequest.IsDone == false)
return;
if (_versionFileRequestOp.Status == EDownloadRequestStatus.Succeed)
if (_downloadTextRequest.Status == EDownloadRequestStatus.Succeeded)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
PackageVersion = _versionFileRequestOp.Result;
SetResult();
PackageVersion = _downloadTextRequest.Result;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _versionFileRequestOp.Error;
SetError(_downloadTextRequest.Error);
}
}
}
protected override void OnAbort()
{
}
private string GetBuildinYooRoot()
{
return YooAssetSettingsData.GetYooDefaultBuildinRoot();
return YooAssetConfiguration.GetDefaultBuiltinRoot();
}
private string GetBuildinPackageVersionFilePath()
{
string fileRoot = GetBuildinYooRoot();
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
string fileName = YooAssetConfiguration.GetPackageVersionFileName(_packageName);
return PathUtility.Combine(fileRoot, _packageName, fileName);
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
@@ -7,7 +7,7 @@ using YooAsset;
/// <summary>
/// 获取沙盒目录里缓存文件大小
/// </summary>
public class GetCacheBundleSizeOperation : GameAsyncOperation
public class GetCacheBundleSizeOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -29,11 +29,11 @@ public class GetCacheBundleSizeOperation : GameAsyncOperation
{
_packageName = packageName;
}
protected override void OnStart()
protected override void InternalStart()
{
_steps = ESteps.GetCacheFiles;
}
protected override void OnUpdate()
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
@@ -54,17 +54,14 @@ public class GetCacheBundleSizeOperation : GameAsyncOperation
TotalSize = totalSize;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
SetResult();
}
}
protected override void OnAbort()
{
}
private string GetCacheDirectoryRoot()
{
string rootDirectory = YooAssetSettingsData.GetYooDefaultCacheRoot();
string rootDirectory = YooAssetConfiguration.GetDefaultCacheRoot();
string packageRoot = PathUtility.Combine(rootDirectory, _packageName);
return PathUtility.Combine(packageRoot, DefaultCacheFileSystemDefine.BundleFilesFolderName);
return PathUtility.Combine(packageRoot, SandboxFileSystemConsts.BundleFilesFolderName);
}
}

View File

@@ -1,10 +1,10 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using YooAsset;
public class LoadAssetsByTagOperation<TObject> : GameAsyncOperation where TObject : UnityEngine.Object
public class LoadAssetsByTagOperation<TObject> : AsyncOperationBase where TObject : UnityEngine.Object
{
private enum ESteps
{
@@ -14,6 +14,7 @@ public class LoadAssetsByTagOperation<TObject> : GameAsyncOperation where TObjec
Done,
}
private readonly string _packageName;
private readonly string _tag;
private ESteps _steps = ESteps.None;
private List<AssetHandle> _handles;
@@ -24,26 +25,28 @@ public class LoadAssetsByTagOperation<TObject> : GameAsyncOperation where TObjec
public List<TObject> AssetObjects { private set; get; }
public LoadAssetsByTagOperation(string tag)
public LoadAssetsByTagOperation(string packageName, string tag)
{
_packageName = packageName;
_tag = tag;
}
protected override void OnStart()
protected override void InternalStart()
{
_steps = ESteps.LoadAssets;
}
protected override void OnUpdate()
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadAssets)
{
AssetInfo[] assetInfos = YooAssets.GetAssetInfos(_tag);
var package = YooAssets.GetPackage(_packageName);
AssetInfo[] assetInfos = package.GetAssetInfos(_tag);
_handles = new List<AssetHandle>(assetInfos.Length);
foreach (var assetInfo in assetInfos)
{
var handle = YooAssets.LoadAssetAsync(assetInfo);
var handle = package.LoadAssetAsync(assetInfo);
_handles.Add(handle);
}
_steps = ESteps.CheckResult;
@@ -53,7 +56,7 @@ public class LoadAssetsByTagOperation<TObject> : GameAsyncOperation where TObjec
{
int index = 0;
foreach (var handle in _handles)
{
{
if (handle.IsDone == false)
{
Progress = (float)index / _handles.Count;
@@ -65,7 +68,7 @@ public class LoadAssetsByTagOperation<TObject> : GameAsyncOperation where TObjec
AssetObjects = new List<TObject>(_handles.Count);
foreach (var handle in _handles)
{
if (handle.Status == EOperationStatus.Succeed)
if (handle.Status == EOperationStatus.Succeeded)
{
var assetObject = handle.AssetObject as TObject;
if (assetObject != null)
@@ -77,29 +80,30 @@ public class LoadAssetsByTagOperation<TObject> : GameAsyncOperation where TObjec
string error = $"资源类型转换失败:{handle.AssetObject.name}";
Debug.LogError($"{error}");
AssetObjects.Clear();
SetFinish(false, error);
SetFailed(error);
return;
}
}
else
{
Debug.LogError($"{handle.LastError}");
Debug.LogError($"{handle.Error}");
AssetObjects.Clear();
SetFinish(false, handle.LastError);
SetFailed(handle.Error);
return;
}
}
SetFinish(true);
SetSucceed();
}
}
protected override void OnAbort()
private void SetSucceed()
{
SetResult();
_steps = ESteps.Done;
}
private void SetFinish(bool succeed, string error = "")
private void SetFailed(string error)
{
Error = error;
Status = succeed ? EOperationStatus.Succeed : EOperationStatus.Failed;
SetError(error);
_steps = ESteps.Done;
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -6,15 +6,15 @@ using YooAsset;
public static class YooAssetsExtension
{
public static LoadGameObjectOperation LoadGameObjectAsync(this ResourcePackage resourcePackage, string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
public static LoadGameObjectOperation LoadGameObjectAsync(this ResourcePackage package, string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
{
var operation = new LoadGameObjectOperation(location, position, rotation, parent, destroyGoOnRelease);
YooAssets.StartOperation(operation);
var operation = new LoadGameObjectOperation(package.PackageName, location, position, rotation, parent, destroyGoOnRelease);
AsyncOperationSystem.StartOperation(AsyncOperationSystem.GlobalSchedulerName, operation);
return operation;
}
}
public class LoadGameObjectOperation : GameAsyncOperation
public class LoadGameObjectOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -23,6 +23,7 @@ public class LoadGameObjectOperation : GameAsyncOperation
Done,
}
private readonly string _packageName;
private readonly string _location;
private readonly Vector3 _positon;
private readonly Quaternion _rotation;
@@ -37,19 +38,20 @@ public class LoadGameObjectOperation : GameAsyncOperation
public GameObject Go { private set; get; }
public LoadGameObjectOperation(string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
public LoadGameObjectOperation(string packageName, string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
{
_packageName = packageName;
_location = location;
_positon = position;
_rotation = rotation;
_parent = parent;
_destroyGoOnRelease = destroyGoOnRelease;
}
protected override void OnStart()
protected override void InternalStart()
{
_steps = ESteps.LoadAsset;
}
protected override void OnUpdate()
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
@@ -58,30 +60,27 @@ public class LoadGameObjectOperation : GameAsyncOperation
{
if (_handle == null)
{
_handle = YooAssets.LoadAssetAsync<GameObject>(_location);
var package = YooAssets.GetPackage(_packageName);
_handle = package.LoadAssetAsync<GameObject>(_location);
}
Progress = _handle.Progress;
if (_handle.IsDone == false)
return;
if (_handle.Status != EOperationStatus.Succeed)
if (_handle.Status != EOperationStatus.Succeeded)
{
Error = _handle.LastError;
Status = EOperationStatus.Failed;
SetError(_handle.Error);
_steps = ESteps.Done;
}
else
{
Go = _handle.InstantiateSync(_positon, _rotation, _parent);
Status = EOperationStatus.Succeed;
SetResult();
_steps = ESteps.Done;
}
}
}
protected override void OnAbort()
{
}
/// <summary>
/// 释放资源句柄

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using YooAsset;
public class OperationHelper
{
/// <summary>
/// 开始一个业务实现的自定义异步任务
/// </summary>
public static void StartOperation(AsyncOperationBase operation)
{
AsyncOperationSystem.StartOperation(AsyncOperationSystem.GlobalSchedulerName, operation);
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: bc47317a416e9f542b7ec6b77485a8b7
guid: fd52bc7cb896369498d42a12081816ee
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using YooAsset;
#if UNITY_EDITOR
@@ -50,7 +50,7 @@ public class GameObjectAssetReference : MonoBehaviour
public void Start()
{
var package = YooAssets.GetPackage("DefaultPackage");
var assetInfo = package.GetAssetInfoByGUID(AssetGUID);
var assetInfo = package.GetAssetInfoByGuid(AssetGUID);
_handle = package.LoadAssetAsync(assetInfo);
_handle.Completed += Handle_Completed;
}
@@ -65,7 +65,7 @@ public class GameObjectAssetReference : MonoBehaviour
private void Handle_Completed(AssetHandle handle)
{
if (handle.Status == EOperationStatus.Succeed)
if (handle.Status == EOperationStatus.Succeeded)
{
handle.InstantiateSync(this.transform);
}

View File

@@ -6,8 +6,6 @@ public static class OperationMonitor
{
public static void RegisterOperationCallback()
{
OperationSystem.RegisterStartCallback(OperationStartCallback);
OperationSystem.RegisterFinishCallback(OperationFinishCallback);
}
private static void OperationStartCallback(string packageName, AsyncOperationBase operation)

View File

@@ -31,9 +31,9 @@ public class SpriteAtlasLoader : MonoBehaviour
{
var package = YooAssets.GetPackage("DefaultPackage");
var loadHandle = package.LoadAssetSync<SpriteAtlas>(atlasName);
if (loadHandle.Status != EOperationStatus.Succeed)
if (loadHandle.Status != EOperationStatus.Succeeded)
{
Debug.LogWarning($"Failed to load sprite atlas : {atlasName} ! {loadHandle.LastError}");
Debug.LogWarning($"Failed to load sprite atlas : {atlasName} ! {loadHandle.Error}");
return;
}

View File

@@ -1,280 +1,34 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using System;
using System.Collections.Generic;
using UnityEngine;
using YooAsset;
using AlipaySdk;
public static class AlipayFileSystemCreater
{
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices)
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
{
string fileSystemClass = $"{nameof(AlipayFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices, IWebDecryptionServices decryptionServices)
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor decryptor)
{
string fileSystemClass = $"{nameof(AlipayFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, decryptor);
return fileSystemParams;
}
}
/// <summary>
/// 支付宝小游戏文件系统
/// 参考https://opendocs.alipay.com/mini-game/0ftleg
/// </summary>
internal class AlipayFileSystem : IFileSystem
internal class AlipayFileSystem : WebGameFileSystem
{
private class WebRemoteServices : IRemoteServices
protected override IWebGamePlatform CreatePlatform(string packageRoot)
{
private readonly string _webPackageRoot;
protected readonly Dictionary<string, string> _mapping = new Dictionary<string, string>(10000);
public WebRemoteServices(string buildinPackRoot)
{
_webPackageRoot = buildinPackRoot;
}
string IRemoteServices.GetRemoteMainURL(string fileName)
{
return GetFileLoadURL(fileName);
}
string IRemoteServices.GetRemoteFallbackURL(string fileName)
{
return GetFileLoadURL(fileName);
}
private string GetFileLoadURL(string fileName)
{
if (_mapping.TryGetValue(fileName, out string url) == false)
{
string filePath = PathUtility.Combine(_webPackageRoot, fileName);
url = DownloadSystemHelper.ConvertToWWWPath(filePath);
_mapping.Add(fileName, url);
}
return url;
}
return new AlipayPlatform();
}
private readonly Dictionary<string, string> _cacheFilePathMapping = new Dictionary<string, string>(10000);
private AlipayFSManager _fileSystemMgr;
private string _aliCacheRoot = string.Empty;
/// <summary>
/// 包裹名称
/// </summary>
public string PackageName { private set; get; }
/// <summary>
/// 文件根目录
/// </summary>
public string FileRoot
{
get
{
return _aliCacheRoot;
}
}
/// <summary>
/// 文件数量
/// </summary>
public int FileCount
{
get
{
return 0;
}
}
#region
/// <summary>
/// 自定义参数:远程服务接口
/// </summary>
public IRemoteServices RemoteServices { private set; get; } = null;
/// <summary>
/// 自定义参数:解密方法类
/// </summary>
public IWebDecryptionServices DecryptionServices { private set; get; }
/// <summary>
/// 自定义参数:资源清单服务类
/// </summary>
public IManifestRestoreServices ManifestServices { private set; get; }
#endregion
public AlipayFileSystem()
{
}
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
{
var operation = new APFSInitializeOperation(this);
return operation;
}
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
{
var operation = new APFSLoadPackageManifestOperation(this, packageVersion, timeout);
return operation;
}
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new APFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
return operation;
}
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
{
var operation = new FSClearCacheFilesCompleteOperation();
return operation;
}
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
{
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
options.SetURL(mainURL, fallbackURL);
var operation = new APFSDownloadFileOperation(this, bundle, options);
return operation;
}
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
{
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
{
var operation = new APFSLoadBundleOperation(this, bundle);
return operation;
}
else
{
string error = $"{nameof(AlipayFileSystem)} not support load bundle type : {bundle.BundleType}";
var operation = new FSLoadBundleCompleteOperation(error);
return operation;
}
}
public virtual void SetParameter(string name, object value)
{
if (name == FileSystemParametersDefine.REMOTE_SERVICES)
{
RemoteServices = (IRemoteServices)value;
}
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
{
DecryptionServices = (IWebDecryptionServices)value;
}
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES)
{
ManifestServices = (IManifestRestoreServices)value;
}
else
{
YooLogger.Warning($"Invalid parameter : {name}");
}
}
public virtual void OnCreate(string packageName, string rootDirectory)
{
PackageName = packageName;
_aliCacheRoot = rootDirectory;
if (string.IsNullOrEmpty(_aliCacheRoot))
{
throw new System.Exception("请配置小游戏的缓存根目录!");
}
// 注意CDN服务未启用的情况下使用WEB服务器
if (RemoteServices == null)
{
string webRoot = PathUtility.Combine(Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName, packageName);
RemoteServices = new WebRemoteServices(webRoot);
}
_fileSystemMgr = AlipaySDK.API.GetFileSystemManager();
}
public virtual void OnDestroy()
{
}
public virtual bool Belong(PackageBundle bundle)
{
return true;
}
public virtual bool Exists(PackageBundle bundle)
{
return CheckCacheFileExist(bundle);
}
public virtual bool NeedDownload(PackageBundle bundle)
{
if (Belong(bundle) == false)
return false;
return Exists(bundle) == false;
}
public virtual bool NeedUnpack(PackageBundle bundle)
{
return false;
}
public virtual bool NeedImport(PackageBundle bundle)
{
return false;
}
public virtual string GetBundleFilePath(PackageBundle bundle)
{
return GetCacheFileLoadPath(bundle);
}
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
{
if (CheckCacheFileExist(bundle))
{
string filePath = GetCacheFileLoadPath(bundle);
return _fileSystemMgr.ReadFileSync(filePath);
}
else
{
return Array.Empty<byte>();
}
}
public virtual string ReadBundleFileText(PackageBundle bundle)
{
if (CheckCacheFileExist(bundle))
{
string filePath = GetCacheFileLoadPath(bundle);
return _fileSystemMgr.ReadFileSync(filePath, "utf8");
}
else
{
return string.Empty;
}
}
#region
public AlipayFSManager GetFileSystemMgr()
{
return _fileSystemMgr;
}
public bool CheckCacheFileExist(PackageBundle bundle)
{
//TODO : 效率极低
/*
string filePath = GetCacheFileLoadPath(bundle);
string result = _fileSystemMgr.AccessSync(filePath);
return result.Equals("access:ok", StringComparison.Ordinal);
*/
return false;
}
private string GetCacheFileLoadPath(PackageBundle bundle)
{
if (_cacheFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = PathUtility.Combine(_aliCacheRoot, bundle.FileName);
_cacheFilePathMapping.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
#endregion
}
#endif

View File

@@ -0,0 +1,44 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using UnityEngine;
using UnityEngine.Networking;
using YooAsset;
using AlipaySdk;
/// <summary>
/// 支付宝小游戏平台实现
/// 参考https://opendocs.alipay.com/mini-game/
/// </summary>
internal class AlipayPlatform : IWebGamePlatform
{
/// <inheritdoc/>
public UnityWebRequest CreateAssetBundleRequest(string url)
{
return APAssetBundle.GetAssetBundle(url);
}
/// <inheritdoc/>
public AssetBundle ExtractAssetBundle(UnityWebRequest request)
{
var downloadHandler = (DownloadHandlerAPAssetBundle)request.downloadHandler;
return downloadHandler.assetBundle;
}
/// <inheritdoc/>
public void UnloadAssetBundle(AssetBundle assetBundle, bool unloadAll)
{
assetBundle.APUnload(unloadAll);
}
/// <inheritdoc/>
public bool IsCached(string cacheFilePath)
{
return false;
}
/// <inheritdoc/>
public string GetCacheFilePath(string rootPath, PackageBundle bundle)
{
return PathUtility.Combine(rootPath, bundle.GetFileName());
}
}
#endif

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 1de437726bd89584da56aaddfdb1a07c
guid: 86530504595f2dc438ca3b6bf542d4ca
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,67 +0,0 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
using AlipaySdk;
namespace YooAsset
{
internal class APAssetBundleResult : BundleResult
{
private readonly IFileSystem _fileSystem;
private readonly PackageBundle _packageBundle;
private readonly AssetBundle _assetBundle;
public APAssetBundleResult(IFileSystem fileSystem, PackageBundle packageBundle, AssetBundle assetBundle)
{
_fileSystem = fileSystem;
_packageBundle = packageBundle;
_assetBundle = assetBundle;
}
public override void UnloadBundleFile()
{
if (_assetBundle != null)
{
if (_packageBundle.Encrypted)
_assetBundle.Unload(true);
else
_assetBundle.APUnload(true);
}
}
public override string GetBundleFilePath()
{
return _fileSystem.GetBundleFilePath(_packageBundle);
}
public override byte[] ReadBundleFileData()
{
return _fileSystem.ReadBundleFileData(_packageBundle);
}
public override string ReadBundleFileText()
{
return _fileSystem.ReadBundleFileText(_packageBundle);
}
public override FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadAssetOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadAllAssetsOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadSubAssetsOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
{
var operation = new AssetBundleLoadSceneOperation(assetInfo, loadParams, suspendLoad);
return operation;
}
}
}
#endif

View File

@@ -1,113 +0,0 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using UnityEngine;
using YooAsset;
internal class APFSDownloadFileOperation : FSDownloadFileOperation
{
protected enum ESteps
{
None,
CreateRequest,
CheckRequest,
TryAgain,
Done,
}
private readonly AlipayFileSystem _fileSystem;
private readonly DownloadFileOptions _options;
private UnityWebCacheRequestOperation _webCacheRequestOp;
private int _requestCount = 0;
private float _tryAgainTimer = 0;
private int _failedTryAgain;
private ESteps _steps = ESteps.None;
internal APFSDownloadFileOperation(AlipayFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
{
_fileSystem = fileSystem;
_options = options;
_failedTryAgain = options.FailedTryAgain;
}
internal override void InternalStart()
{
_steps = ESteps.CreateRequest;
}
internal override void InternalUpdate()
{
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
string url = GetRequestURL();
_webCacheRequestOp = new UnityWebCacheRequestOperation(url);
_webCacheRequestOp.StartOperation();
AddChildOperation(_webCacheRequestOp);
_steps = ESteps.CheckRequest;
}
// 检测下载结果
if (_steps == ESteps.CheckRequest)
{
_webCacheRequestOp.UpdateOperation();
Progress = _webCacheRequestOp.Progress;
DownloadProgress = _webCacheRequestOp.DownloadProgress;
DownloadedBytes = _webCacheRequestOp.DownloadedBytes;
if (_webCacheRequestOp.IsDone == false)
return;
if (_webCacheRequestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
//TODO 需要验证插件请求器的下载进度
DownloadProgress = 1f;
DownloadedBytes = Bundle.FileSize;
Progress = 1f;
}
else
{
if (_failedTryAgain > 0)
{
_steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_webCacheRequestOp.URL} Try again !");
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _webCacheRequestOp.Error;
YooLogger.Error(Error);
}
}
}
// 重新尝试下载
if (_steps == ESteps.TryAgain)
{
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
_tryAgainTimer = 0f;
_failedTryAgain--;
Progress = 0f;
DownloadProgress = 0f;
DownloadedBytes = 0;
_steps = ESteps.CreateRequest;
}
}
}
/// <summary>
/// 获取网络请求地址
/// </summary>
private string GetRequestURL()
{
// 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return _options.FallbackURL;
else
return _options.MainURL;
}
}
#endif

View File

@@ -1,20 +0,0 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using YooAsset;
internal partial class APFSInitializeOperation : FSInitializeFileSystemOperation
{
private readonly AlipayFileSystem _fileSystem;
public APFSInitializeOperation(AlipayFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalUpdate()
{
}
}
#endif

View File

@@ -1,88 +0,0 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using YooAsset;
internal class APFSLoadBundleOperation : FSLoadBundleOperation
{
private enum ESteps
{
None,
LoadAssetBundle,
Done,
}
private readonly AlipayFileSystem _fileSystem;
private readonly PackageBundle _bundle;
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
private ESteps _steps = ESteps.None;
internal APFSLoadBundleOperation(AlipayFileSystem fileSystem, PackageBundle bundle)
{
_fileSystem = fileSystem;
_bundle = bundle;
}
internal override void InternalStart()
{
_steps = ESteps.LoadAssetBundle;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadAssetBundle)
{
if (_loadWebAssetBundleOp == null)
{
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
options.SetURL(mainURL, fallbackURL);
if (_bundle.Encrypted)
{
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
_loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp);
}
else
{
_loadWebAssetBundleOp = new LoadAlipayAssetBundleOperation(_bundle, options);
_loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp);
}
}
_loadWebAssetBundleOp.UpdateOperation();
Progress = _loadWebAssetBundleOp.Progress;
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
if (_loadWebAssetBundleOp.IsDone == false)
return;
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
{
var assetBundle = _loadWebAssetBundleOp.Result;
_steps = ESteps.Done;
Result = new APAssetBundleResult(_fileSystem, _bundle, assetBundle);
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadWebAssetBundleOp.Error;
}
}
}
internal override void InternalWaitForAsyncComplete()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "WebGL platform not support sync load method !";
UnityEngine.Debug.LogError(Error);
}
}
}
#endif

View File

@@ -1,95 +0,0 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using YooAsset;
internal class APFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
{
private enum ESteps
{
None,
RequestPackageHash,
LoadPackageManifest,
Done,
}
private readonly AlipayFileSystem _fileSystem;
private readonly string _packageVersion;
private readonly int _timeout;
private RequestWebPackageHashOperation _requestPackageHashOp;
private LoadWebPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None;
public APFSLoadPackageManifestOperation(AlipayFileSystem fileSystem, string packageVersion, int timeout)
{
_fileSystem = fileSystem;
_packageVersion = packageVersion;
_timeout = timeout;
}
internal override void InternalStart()
{
_steps = ESteps.RequestPackageHash;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageHash)
{
if (_requestPackageHashOp == null)
{
_requestPackageHashOp = new RequestWebPackageHashOperation(_fileSystem.RemoteServices, _fileSystem.PackageName, _packageVersion, _timeout);
_requestPackageHashOp.StartOperation();
AddChildOperation(_requestPackageHashOp);
}
_requestPackageHashOp.UpdateOperation();
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;
string packageName = _fileSystem.PackageName;
var manifestServices = _fileSystem.ManifestServices;
var remoteServices = _fileSystem.RemoteServices;
_loadPackageManifestOp = new LoadWebPackageManifestOperation(manifestServices, remoteServices, packageName, _packageVersion, packageHash, _timeout);
_loadPackageManifestOp.StartOperation();
AddChildOperation(_loadPackageManifestOp);
}
_loadPackageManifestOp.UpdateOperation();
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

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 335885fb4e1977a4ca5c26263eda03d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,64 +0,0 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using YooAsset;
internal class APFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
{
private enum ESteps
{
None,
RequestPackageVersion,
Done,
}
private readonly AlipayFileSystem _fileSystem;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private RequestWebPackageVersionOperation _requestWebPackageVersionOp;
private ESteps _steps = ESteps.None;
internal APFSRequestPackageVersionOperation(AlipayFileSystem fileSystem, bool appendTimeTicks, int timeout)
{
_fileSystem = fileSystem;
_appendTimeTicks = appendTimeTicks;
_timeout = timeout;
}
internal override void InternalStart()
{
_steps = ESteps.RequestPackageVersion;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageVersion)
{
if (_requestWebPackageVersionOp == null)
{
_requestWebPackageVersionOp = new RequestWebPackageVersionOperation(_fileSystem.RemoteServices, _fileSystem.PackageName, _appendTimeTicks, _timeout);
_requestWebPackageVersionOp.StartOperation();
AddChildOperation(_requestWebPackageVersionOp);
}
_requestWebPackageVersionOp.UpdateOperation();
Progress = _requestWebPackageVersionOp.Progress;
if (_requestWebPackageVersionOp.IsDone == false)
return;
if (_requestWebPackageVersionOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
PackageVersion = _requestWebPackageVersionOp.PackageVersion;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _requestWebPackageVersionOp.Error;
}
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a879fd6a506b37345b4b9ea6c5de20bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,116 +0,0 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using UnityEngine;
using AlipaySdk;
namespace YooAsset
{
internal class LoadAlipayAssetBundleOperation : LoadWebAssetBundleOperation
{
protected enum ESteps
{
None,
CreateRequest,
CheckRequest,
TryAgain,
Done,
}
private readonly PackageBundle _bundle;
private readonly DownloadFileOptions _options;
private UnityAlipayAssetBundleRequestOperation _unityAssetBundleRequestOp;
private int _requestCount = 0;
private float _tryAgainTimer = 0;
private int _failedTryAgain;
private ESteps _steps = ESteps.None;
internal LoadAlipayAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options)
{
_bundle = bundle;
_options = options;
_failedTryAgain = options.FailedTryAgain;
}
internal override void InternalStart()
{
_steps = ESteps.CreateRequest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
string url = GetRequestURL();
_unityAssetBundleRequestOp = new UnityAlipayAssetBundleRequestOperation(_bundle, url);
_unityAssetBundleRequestOp.StartOperation();
AddChildOperation(_unityAssetBundleRequestOp);
_steps = ESteps.CheckRequest;
}
// 检测下载结果
if (_steps == ESteps.CheckRequest)
{
_unityAssetBundleRequestOp.UpdateOperation();
Progress = _unityAssetBundleRequestOp.Progress;
DownloadProgress = _unityAssetBundleRequestOp.DownloadProgress;
DownloadedBytes = _unityAssetBundleRequestOp.DownloadedBytes;
if (_unityAssetBundleRequestOp.IsDone == false)
return;
if (_unityAssetBundleRequestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
Result = _unityAssetBundleRequestOp.Result;
}
else
{
if (_failedTryAgain > 0)
{
_steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_unityAssetBundleRequestOp.URL} Try again !");
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _unityAssetBundleRequestOp.Error;
YooLogger.Error(Error);
}
}
}
// 重新尝试下载
if (_steps == ESteps.TryAgain)
{
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
_tryAgainTimer = 0f;
_failedTryAgain--;
Progress = 0f;
DownloadProgress = 0f;
DownloadedBytes = 0;
_steps = ESteps.CreateRequest;
}
}
}
/// <summary>
/// 获取网络请求地址
/// </summary>
private string GetRequestURL()
{
// 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return _options.FallbackURL;
else
return _options.MainURL;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 62249d32580e2ef48a33afb58515312a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,95 +0,0 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using UnityEngine.Networking;
using UnityEngine;
using AlipaySdk;
namespace YooAsset
{
internal class UnityAlipayAssetBundleRequestOperation : UnityWebRequestOperation
{
protected enum ESteps
{
None,
CreateRequest,
Download,
Done,
}
private readonly PackageBundle _packageBundle;
private UnityWebRequestAsyncOperation _requestOperation;
private ESteps _steps = ESteps.None;
/// <summary>
/// 请求结果
/// </summary>
public AssetBundle Result { private set; get; }
internal UnityAlipayAssetBundleRequestOperation(PackageBundle bundle, string url) : base(url)
{
_packageBundle = bundle;
}
internal override void InternalStart()
{
_steps = ESteps.CreateRequest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CreateRequest)
{
CreateWebRequest();
_steps = ESteps.Download;
}
if (_steps == ESteps.Download)
{
DownloadProgress = _webRequest.downloadProgress;
DownloadedBytes = (long)_webRequest.downloadedBytes;
Progress = _requestOperation.progress;
if (_requestOperation.isDone == false)
return;
if (CheckRequestResult())
{
var downloadHanlder = (DownloadHandlerAPAssetBundle)_webRequest.downloadHandler;
AssetBundle assetBundle = downloadHanlder.assetBundle;
if (assetBundle == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"URL : {_requestURL} Download handler asset bundle object is null !";
}
else
{
_steps = ESteps.Done;
Result = assetBundle;
Status = EOperationStatus.Succeed;
//TODO 需要验证插件请求器的下载进度
DownloadProgress = 1f;
DownloadedBytes = _packageBundle.FileSize;
Progress = 1f;
}
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
}
// 注意:最终释放请求器
DisposeRequest();
}
}
private void CreateWebRequest()
{
_webRequest = APAssetBundle.GetAssetBundle(_requestURL);
_webRequest.disposeDownloadHandlerOnDispose = true;
_requestOperation = _webRequest.SendWebRequest();
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a2e7a4e37ac067f4ba0a43ebea0aa3f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,9 +1,5 @@
#if UNITY_ANDROID && GOOGLE_PLAY
using System.Collections.Generic;
using UnityEngine;
#if UNITY_ANDROID && GOOGLE_PLAY
using YooAsset;
using System.Linq;
using System;
public static class GooglePlayFileSystemCreater
{
@@ -16,27 +12,21 @@ public static class GooglePlayFileSystemCreater
}
/// <summary>
/// 兼容谷歌Play Asset Delivery的文件系统
/// Google Play Asset Delivery file system.
/// Loads asset bundles via PlayAssetDelivery instead of local file I/O.
/// See: https://developer.android.com/guide/playcore/asset-delivery
/// </summary>
internal class GooglePlayFileSystem : DefaultBuildinFileSystem
internal class GooglePlayFileSystem : BuiltinFileSystem, IFileSystem
{
public GooglePlayFileSystem()
/// <summary>
/// Override bundle loading to use Play Asset Delivery.
/// Re-implements <see cref="IFileSystem.LoadPackageBundleAsync"/> so the
/// interface dispatch reaches this method instead of the base class version.
/// </summary>
public new FSLoadPackageBundleOperation LoadPackageBundleAsync(FSLoadPackageBundleOptions options)
{
}
public override FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
{
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
{
var operation = new GPFSLoadAssetBundleOperation(this, bundle);
return operation;
}
else
{
string error = $"{nameof(GooglePlayFileSystem)} not support load bundle type : {bundle.BundleType}";
var operation = new FSLoadBundleCompleteOperation(error);
return operation;
}
var operation = new GPFSLoadPackageBundleOperation(this, options);
return operation;
}
}
#endif
#endif

View File

@@ -1,10 +1,11 @@
#if UNITY_ANDROID && GOOGLE_PLAY
using System.IO;
using UnityEngine;
using YooAsset;
using Google.Play.AssetDelivery;
internal class GPFSLoadAssetBundleOperation : FSLoadBundleOperation
/// <summary>
/// Loads an AssetBundle through Google Play Asset Delivery API.
/// </summary>
internal sealed class GPFSLoadPackageBundleOperation : FSLoadPackageBundleOperation
{
private enum ESteps
{
@@ -15,39 +16,35 @@ internal class GPFSLoadAssetBundleOperation : FSLoadBundleOperation
}
private readonly GooglePlayFileSystem _fileSystem;
private readonly PackageBundle _bundle;
private readonly FSLoadPackageBundleOptions _options;
private PlayAssetBundleRequest _bundleRequest;
private ESteps _steps = ESteps.None;
internal GPFSLoadAssetBundleOperation(GooglePlayFileSystem fileSystem, PackageBundle bundle)
internal GPFSLoadPackageBundleOperation(GooglePlayFileSystem fileSystem, FSLoadPackageBundleOptions options)
{
_fileSystem = fileSystem;
_bundle = bundle;
_options = options;
}
internal override void InternalStart()
protected override void InternalStart()
{
DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize;
_steps = ESteps.LoadAssetBundle;
}
internal override void InternalUpdate()
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadAssetBundle)
{
if (_bundle.Encrypted)
if (_options.Bundle.IsEncrypted)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"The {nameof(GooglePlayFileSystem)} not support bundle encrypted !";
YooLogger.Error(Error);
SetError($"{nameof(GooglePlayFileSystem)} does not support encrypted bundles.");
YooLogger.LogError(Error);
return;
}
_bundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync(_bundle.FileName);
_bundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync(_options.Bundle.GetFileName());
_steps = ESteps.CheckResult;
}
@@ -59,27 +56,25 @@ internal class GPFSLoadAssetBundleOperation : FSLoadBundleOperation
if (_bundleRequest.Error != AssetDeliveryErrorCode.NoError)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed to load delivery asset bundle file : {_bundle.BundleName} Error : {_bundleRequest.Error}";
YooLogger.Error(Error);
SetError($"Failed to load asset bundle via Play Asset Delivery: {_options.Bundle.BundleName} Error: {_bundleRequest.Error}");
YooLogger.LogError(Error);
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
Result = new AssetBundleResult(_fileSystem, _bundle, _bundleRequest.AssetBundle, null);
SetResult();
BundleHandle = new AssetBundleHandle(string.Empty, _options.Bundle, _bundleRequest.AssetBundle, null);
}
}
}
internal override void InternalWaitForAsyncComplete()
protected override void InternalWaitForCompletion()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"{nameof(GooglePlayFileSystem)} not support sync load method !";
UnityEngine.Debug.LogError(Error);
SetError($"{nameof(GooglePlayFileSystem)} does not support synchronous loading.");
YooLogger.LogError(Error);
}
}
}
#endif
#endif

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ff9085fca05646b4e9f6dfec5f9cd5ab
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,67 +0,0 @@
#if UNITY_WEBGL && TAPMINIGAME
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
using TapTapMiniGame;
namespace YooAsset
{
internal class TPAssetBundleResult : BundleResult
{
private readonly IFileSystem _fileSystem;
private readonly PackageBundle _packageBundle;
private readonly AssetBundle _assetBundle;
public TPAssetBundleResult(IFileSystem fileSystem, PackageBundle packageBundle, AssetBundle assetBundle)
{
_fileSystem = fileSystem;
_packageBundle = packageBundle;
_assetBundle = assetBundle;
}
public override void UnloadBundleFile()
{
if (_assetBundle != null)
{
if (_packageBundle.Encrypted)
_assetBundle.Unload(true);
else
_assetBundle.TapUnload(true);
}
}
public override string GetBundleFilePath()
{
return _fileSystem.GetBundleFilePath(_packageBundle);
}
public override byte[] ReadBundleFileData()
{
return _fileSystem.ReadBundleFileData(_packageBundle);
}
public override string ReadBundleFileText()
{
return _fileSystem.ReadBundleFileText(_packageBundle);
}
public override FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadAssetOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadAllAssetsOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadSubAssetsOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
{
var operation = new AssetBundleLoadSceneOperation(assetInfo, loadParams, suspendLoad);
return operation;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: e914b1b35e8a6ae48bdfe71a0614ab0a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: dbbb8f216603c4042b3c29cdde607705
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,113 +0,0 @@
#if UNITY_WEBGL && TAPMINIGAME
using UnityEngine;
using YooAsset;
internal class TPFSDownloadFileOperation : FSDownloadFileOperation
{
protected enum ESteps
{
None,
CreateRequest,
CheckRequest,
TryAgain,
Done,
}
private readonly TaptapFileSystem _fileSystem;
private readonly DownloadFileOptions _options;
private UnityWebCacheRequestOperation _webCacheRequestOp;
private int _requestCount = 0;
private float _tryAgainTimer = 0;
private int _failedTryAgain;
private ESteps _steps = ESteps.None;
internal TPFSDownloadFileOperation(TaptapFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
{
_fileSystem = fileSystem;
_options = options;
_failedTryAgain = options.FailedTryAgain;
}
internal override void InternalStart()
{
_steps = ESteps.CreateRequest;
}
internal override void InternalUpdate()
{
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
string url = GetRequestURL();
_webCacheRequestOp = new UnityWebCacheRequestOperation(url);
_webCacheRequestOp.StartOperation();
AddChildOperation(_webCacheRequestOp);
_steps = ESteps.CheckRequest;
}
// 检测下载结果
if (_steps == ESteps.CheckRequest)
{
_webCacheRequestOp.UpdateOperation();
Progress = _webCacheRequestOp.Progress;
DownloadProgress = _webCacheRequestOp.DownloadProgress;
DownloadedBytes = _webCacheRequestOp.DownloadedBytes;
if (_webCacheRequestOp.IsDone == false)
return;
if (_webCacheRequestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
//TODO 需要验证插件请求器的下载进度
DownloadProgress = 1f;
DownloadedBytes = Bundle.FileSize;
Progress = 1f;
}
else
{
if (_failedTryAgain > 0)
{
_steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_webCacheRequestOp.URL} Try again !");
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _webCacheRequestOp.Error;
YooLogger.Error(Error);
}
}
}
// 重新尝试下载
if (_steps == ESteps.TryAgain)
{
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
_tryAgainTimer = 0f;
_failedTryAgain--;
Progress = 0f;
DownloadProgress = 0f;
DownloadedBytes = 0;
_steps = ESteps.CreateRequest;
}
}
}
/// <summary>
/// 获取网络请求地址
/// </summary>
private string GetRequestURL()
{
// 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return _options.FallbackURL;
else
return _options.MainURL;
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: e0d44d1a88d041a4cb6240d30d96fdf2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,20 +0,0 @@
#if UNITY_WEBGL && TAPMINIGAME
using YooAsset;
internal partial class TPFSInitializeOperation : FSInitializeFileSystemOperation
{
private readonly TaptapFileSystem _fileSystem;
public TPFSInitializeOperation(TaptapFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalUpdate()
{
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 017c1f2fbc59ff8418cc781c5e66efef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,88 +0,0 @@
#if UNITY_WEBGL && TAPMINIGAME
using YooAsset;
internal class TPFSLoadBundleOperation : FSLoadBundleOperation
{
private enum ESteps
{
None,
LoadAssetBundle,
Done,
}
private readonly TaptapFileSystem _fileSystem;
private readonly PackageBundle _bundle;
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
private ESteps _steps = ESteps.None;
internal TPFSLoadBundleOperation(TaptapFileSystem fileSystem, PackageBundle bundle)
{
_fileSystem = fileSystem;
_bundle = bundle;
}
internal override void InternalStart()
{
_steps = ESteps.LoadAssetBundle;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadAssetBundle)
{
if (_loadWebAssetBundleOp == null)
{
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
options.SetURL(mainURL, fallbackURL);
if (_bundle.Encrypted)
{
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
_loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp);
}
else
{
_loadWebAssetBundleOp = new LoadTaptapAssetBundleOperation(_bundle, options);
_loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp);
}
}
_loadWebAssetBundleOp.UpdateOperation();
Progress = _loadWebAssetBundleOp.Progress;
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
if (_loadWebAssetBundleOp.IsDone == false)
return;
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
{
var assetBundle = _loadWebAssetBundleOp.Result;
_steps = ESteps.Done;
Result = new TPAssetBundleResult(_fileSystem, _bundle, assetBundle);
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadWebAssetBundleOp.Error;
}
}
}
internal override void InternalWaitForAsyncComplete()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "WebGL platform not support sync load method !";
UnityEngine.Debug.LogError(Error);
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 01680b24db924794b8adc1e0e6697865
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,95 +0,0 @@
#if UNITY_WEBGL && TAPMINIGAME
using YooAsset;
internal class TPFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
{
private enum ESteps
{
None,
RequestPackageHash,
LoadPackageManifest,
Done,
}
private readonly TaptapFileSystem _fileSystem;
private readonly string _packageVersion;
private readonly int _timeout;
private RequestWebPackageHashOperation _requestPackageHashOp;
private LoadWebPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None;
public TPFSLoadPackageManifestOperation(TaptapFileSystem fileSystem, string packageVersion, int timeout)
{
_fileSystem = fileSystem;
_packageVersion = packageVersion;
_timeout = timeout;
}
internal override void InternalStart()
{
_steps = ESteps.RequestPackageHash;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageHash)
{
if (_requestPackageHashOp == null)
{
_requestPackageHashOp = new RequestWebPackageHashOperation(_fileSystem.RemoteServices, _fileSystem.PackageName, _packageVersion, _timeout);
_requestPackageHashOp.StartOperation();
AddChildOperation(_requestPackageHashOp);
}
_requestPackageHashOp.UpdateOperation();
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;
string packageName = _fileSystem.PackageName;
var manifestServices = _fileSystem.ManifestServices;
var remoteServices = _fileSystem.RemoteServices;
_loadPackageManifestOp = new LoadWebPackageManifestOperation(manifestServices, remoteServices, packageName, _packageVersion, packageHash, _timeout);
_loadPackageManifestOp.StartOperation();
AddChildOperation(_loadPackageManifestOp);
}
_loadPackageManifestOp.UpdateOperation();
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

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a9900531297a5a140806316f844fa0a0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,64 +0,0 @@
#if UNITY_WEBGL && TAPMINIGAME
using YooAsset;
internal class TPFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
{
private enum ESteps
{
None,
RequestPackageVersion,
Done,
}
private readonly TaptapFileSystem _fileSystem;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private RequestWebPackageVersionOperation _requestWebPackageVersionOp;
private ESteps _steps = ESteps.None;
internal TPFSRequestPackageVersionOperation(TaptapFileSystem fileSystem, bool appendTimeTicks, int timeout)
{
_fileSystem = fileSystem;
_appendTimeTicks = appendTimeTicks;
_timeout = timeout;
}
internal override void InternalStart()
{
_steps = ESteps.RequestPackageVersion;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageVersion)
{
if (_requestWebPackageVersionOp == null)
{
_requestWebPackageVersionOp = new RequestWebPackageVersionOperation(_fileSystem.RemoteServices, _fileSystem.PackageName, _appendTimeTicks, _timeout);
_requestWebPackageVersionOp.StartOperation();
AddChildOperation(_requestWebPackageVersionOp);
}
_requestWebPackageVersionOp.UpdateOperation();
Progress = _requestWebPackageVersionOp.Progress;
if (_requestWebPackageVersionOp.IsDone == false)
return;
if (_requestWebPackageVersionOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
PackageVersion = _requestWebPackageVersionOp.PackageVersion;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _requestWebPackageVersionOp.Error;
}
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 877f877fd3586974d90c7c306efdf4d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: e4ea0eed64f86c54c82153463d3773bf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,115 +0,0 @@
#if UNITY_WEBGL && TAPMINIGAME
using UnityEngine;
namespace YooAsset
{
internal class LoadTaptapAssetBundleOperation : LoadWebAssetBundleOperation
{
protected enum ESteps
{
None,
CreateRequest,
CheckRequest,
TryAgain,
Done,
}
private readonly PackageBundle _bundle;
private readonly DownloadFileOptions _options;
private UnityTaptapAssetBundleRequestOperation _unityAssetBundleRequestOp;
private int _requestCount = 0;
private float _tryAgainTimer = 0;
private int _failedTryAgain;
private ESteps _steps = ESteps.None;
internal LoadTaptapAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options)
{
_bundle = bundle;
_options = options;
_failedTryAgain = options.FailedTryAgain;
}
internal override void InternalStart()
{
_steps = ESteps.CreateRequest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
string url = GetRequestURL();
_unityAssetBundleRequestOp = new UnityTaptapAssetBundleRequestOperation(_bundle, url);
_unityAssetBundleRequestOp.StartOperation();
AddChildOperation(_unityAssetBundleRequestOp);
_steps = ESteps.CheckRequest;
}
// 检测下载结果
if (_steps == ESteps.CheckRequest)
{
_unityAssetBundleRequestOp.UpdateOperation();
Progress = _unityAssetBundleRequestOp.Progress;
DownloadProgress = _unityAssetBundleRequestOp.DownloadProgress;
DownloadedBytes = _unityAssetBundleRequestOp.DownloadedBytes;
if (_unityAssetBundleRequestOp.IsDone == false)
return;
if (_unityAssetBundleRequestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
Result = _unityAssetBundleRequestOp.Result;
}
else
{
if (_failedTryAgain > 0)
{
_steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_unityAssetBundleRequestOp.URL} Try again !");
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _unityAssetBundleRequestOp.Error;
YooLogger.Error(Error);
}
}
}
// 重新尝试下载
if (_steps == ESteps.TryAgain)
{
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
_tryAgainTimer = 0f;
_failedTryAgain--;
Progress = 0f;
DownloadProgress = 0f;
DownloadedBytes = 0;
_steps = ESteps.CreateRequest;
}
}
}
/// <summary>
/// 获取网络请求地址
/// </summary>
private string GetRequestURL()
{
// 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return _options.FallbackURL;
else
return _options.MainURL;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: fabbe424782f96a4490979f4f68c6322
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,95 +0,0 @@
#if UNITY_WEBGL && TAPMINIGAME
using UnityEngine.Networking;
using UnityEngine;
using TapTapMiniGame;
namespace YooAsset
{
internal class UnityTaptapAssetBundleRequestOperation : UnityWebRequestOperation
{
protected enum ESteps
{
None,
CreateRequest,
Download,
Done,
}
private readonly PackageBundle _packageBundle;
private UnityWebRequestAsyncOperation _requestOperation;
private ESteps _steps = ESteps.None;
/// <summary>
/// 请求结果
/// </summary>
public AssetBundle Result { private set; get; }
internal UnityTaptapAssetBundleRequestOperation(PackageBundle bundle, string url) : base(url)
{
_packageBundle = bundle;
}
internal override void InternalStart()
{
_steps = ESteps.CreateRequest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CreateRequest)
{
CreateWebRequest();
_steps = ESteps.Download;
}
if (_steps == ESteps.Download)
{
DownloadProgress = _webRequest.downloadProgress;
DownloadedBytes = (long)_webRequest.downloadedBytes;
Progress = _requestOperation.progress;
if (_requestOperation.isDone == false)
return;
if (CheckRequestResult())
{
var downloadHanlder = (DownloadHandlerTapAssetBundle)_webRequest.downloadHandler;
AssetBundle assetBundle = downloadHanlder.assetBundle;
if (assetBundle == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"URL : {_requestURL} Download handler asset bundle object is null !";
}
else
{
_steps = ESteps.Done;
Result = assetBundle;
Status = EOperationStatus.Succeed;
//TODO 需要验证插件请求器的下载进度
DownloadProgress = 1f;
DownloadedBytes = _packageBundle.FileSize;
Progress = 1f;
}
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
}
// 注意:最终释放请求器
DisposeRequest();
}
}
private void CreateWebRequest()
{
_webRequest = TapAssetBundle.GetAssetBundle(_requestURL);
_webRequest.disposeDownloadHandlerOnDispose = true;
_requestOperation = _webRequest.SendWebRequest();
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ce0d7ec006993ef41b16f32335dc6224
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,281 +1,34 @@
#if UNITY_WEBGL && TAPMINIGAME
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_WEBGL && TAPMINIGAME
using YooAsset;
using TapTapMiniGame;
public static class TaptapFileSystemCreater
{
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices)
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
{
string fileSystemClass = $"{nameof(TaptapFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices, IWebDecryptionServices decryptionServices)
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor decryptor)
{
string fileSystemClass = $"{nameof(TaptapFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, decryptor);
return fileSystemParams;
}
}
/// <summary>
/// TapTap小游戏
/// 参考https://developer.taptap.cn/minigameapidoc/dev/engine/unity-adaptation/guide/
/// TapTap小游戏文件系统
/// </summary>
internal class TaptapFileSystem : IFileSystem
internal class TaptapFileSystem : WebGameFileSystem
{
private class WebRemoteServices : IRemoteServices
protected override IWebGamePlatform CreatePlatform(string packageRoot)
{
private readonly string _webPackageRoot;
protected readonly Dictionary<string, string> _mapping = new Dictionary<string, string>(10000);
public WebRemoteServices(string buildinPackRoot)
{
_webPackageRoot = buildinPackRoot;
}
string IRemoteServices.GetRemoteMainURL(string fileName)
{
return GetFileLoadURL(fileName);
}
string IRemoteServices.GetRemoteFallbackURL(string fileName)
{
return GetFileLoadURL(fileName);
}
private string GetFileLoadURL(string fileName)
{
if (_mapping.TryGetValue(fileName, out string url) == false)
{
string filePath = PathUtility.Combine(_webPackageRoot, fileName);
url = DownloadSystemHelper.ConvertToWWWPath(filePath);
_mapping.Add(fileName, url);
}
return url;
}
return new TaptapPlatform();
}
private readonly Dictionary<string, string> _cacheFilePathMapping = new Dictionary<string, string>(10000);
private TapFileSystemManager _fileSystemMgr;
private string _tapCacheRoot = string.Empty;
/// <summary>
/// 包裹名称
/// </summary>
public string PackageName { private set; get; }
/// <summary>
/// 文件根目录
/// </summary>
public string FileRoot
{
get
{
return _tapCacheRoot;
}
}
/// <summary>
/// 文件数量
/// </summary>
public int FileCount
{
get
{
return 0;
}
}
#region
/// <summary>
/// 自定义参数:远程服务接口
/// </summary>
public IRemoteServices RemoteServices { private set; get; } = null;
/// <summary>
/// 自定义参数:解密方法类
/// </summary>
public IWebDecryptionServices DecryptionServices { private set; get; }
/// <summary>
/// 自定义参数:资源清单服务类
/// </summary>
public IManifestRestoreServices ManifestServices { private set; get; }
#endregion
public TaptapFileSystem()
{
}
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
{
var operation = new TPFSInitializeOperation(this);
return operation;
}
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
{
var operation = new TPFSLoadPackageManifestOperation(this, packageVersion, timeout);
return operation;
}
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new TPFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
return operation;
}
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
{
var operation = new FSClearCacheFilesCompleteOperation();
return operation;
}
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
{
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
options.SetURL(mainURL, fallbackURL);
var operation = new TPFSDownloadFileOperation(this, bundle, options);
return operation;
}
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
{
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
{
var operation = new TPFSLoadBundleOperation(this, bundle);
return operation;
}
else
{
string error = $"{nameof(TaptapFileSystem)} not support load bundle type : {bundle.BundleType}";
var operation = new FSLoadBundleCompleteOperation(error);
return operation;
}
}
public virtual void SetParameter(string name, object value)
{
if (name == FileSystemParametersDefine.REMOTE_SERVICES)
{
RemoteServices = (IRemoteServices)value;
}
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
{
DecryptionServices = (IWebDecryptionServices)value;
}
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES)
{
ManifestServices = (IManifestRestoreServices)value;
}
else
{
YooLogger.Warning($"Invalid parameter : {name}");
}
}
public virtual void OnCreate(string packageName, string rootDirectory)
{
PackageName = packageName;
_tapCacheRoot = rootDirectory;
if (string.IsNullOrEmpty(_tapCacheRoot))
{
throw new System.Exception("请配置小游戏的缓存根目录!");
}
// 注意CDN服务未启用的情况下使用WEB服务器
if (RemoteServices == null)
{
string webRoot = PathUtility.Combine(Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName, packageName);
RemoteServices = new WebRemoteServices(webRoot);
}
_fileSystemMgr = Tap.GetFileSystemManager();
}
public virtual void OnDestroy()
{
}
public virtual bool Belong(PackageBundle bundle)
{
return true;
}
public virtual bool Exists(PackageBundle bundle)
{
return CheckCacheFileExist(bundle);
}
public virtual bool NeedDownload(PackageBundle bundle)
{
if (Belong(bundle) == false)
return false;
return Exists(bundle) == false;
}
public virtual bool NeedUnpack(PackageBundle bundle)
{
return false;
}
public virtual bool NeedImport(PackageBundle bundle)
{
return false;
}
public virtual string GetBundleFilePath(PackageBundle bundle)
{
return GetCacheFileLoadPath(bundle);
}
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
{
if (CheckCacheFileExist(bundle))
{
string filePath = GetCacheFileLoadPath(bundle);
return _fileSystemMgr.ReadFileSync(filePath);
}
else
{
return Array.Empty<byte>();
}
}
public virtual string ReadBundleFileText(PackageBundle bundle)
{
if (CheckCacheFileExist(bundle))
{
string filePath = GetCacheFileLoadPath(bundle);
return _fileSystemMgr.ReadFileSync(filePath, "utf8");
}
else
{
return string.Empty;
}
}
#region
public TapFileSystemManager GetFileSystemMgr()
{
return _fileSystemMgr;
}
public bool CheckCacheFileExist(PackageBundle bundle)
{
//TODO : 效率极低
/*
string filePath = GetCacheFileLoadPath(bundle);
string result = _fileSystemMgr.AccessSync(filePath);
return result.Equals("access:ok", StringComparison.Ordinal);
*/
return false;
}
private string GetCacheFileLoadPath(PackageBundle bundle)
{
if (_cacheFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = PathUtility.Combine(_tapCacheRoot, bundle.FileName);
_cacheFilePathMapping.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
#endregion
}
#endif
#endif

View File

@@ -0,0 +1,44 @@
#if UNITY_WEBGL && TAPMINIGAME
using UnityEngine;
using UnityEngine.Networking;
using YooAsset;
using TapTapMiniGame;
/// <summary>
/// TapTap 小游戏平台实现
/// 参考https://developer.taptap.cn/minigameapidoc/dev/engine/unity-adaptation/guide/
/// </summary>
internal class TaptapPlatform : IWebGamePlatform
{
/// <inheritdoc/>
public UnityWebRequest CreateAssetBundleRequest(string url)
{
return TapAssetBundle.GetAssetBundle(url);
}
/// <inheritdoc/>
public AssetBundle ExtractAssetBundle(UnityWebRequest request)
{
var downloadHandler = (DownloadHandlerTapAssetBundle)request.downloadHandler;
return downloadHandler.assetBundle;
}
/// <inheritdoc/>
public void UnloadAssetBundle(AssetBundle assetBundle, bool unloadAll)
{
assetBundle.TapUnload(unloadAll);
}
/// <inheritdoc/>
public bool IsCached(string cacheFilePath)
{
return false;
}
/// <inheritdoc/>
public string GetCacheFilePath(string rootPath, PackageBundle bundle)
{
return PathUtility.Combine(rootPath, bundle.GetFileName());
}
}
#endif

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f71fc4fc468d41441b00be64938b2fe9
guid: a7668d88af841f84a844ae6d3b42df09
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 44b9746ed3270394eb54d85b27a2ef04
guid: cda191ef75dc59f408545d8f7d3644b0
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using UnityEngine;
namespace YooAsset
@@ -11,10 +11,10 @@ namespace YooAsset
// 初始化小游戏文件系统
Debug.Log("初始化小游戏文件系统!");
var initializeFileSystemOp = fileSystem.InitializeFileSystemAsync();
OperationSystem.StartOperation(packageName, initializeFileSystemOp);
var initializeFileSystemOp = fileSystem.InitializeAsync();
AsyncOperationSystem.StartOperation(packageName, initializeFileSystemOp);
yield return initializeFileSystemOp;
if (initializeFileSystemOp.Status != EOperationStatus.Succeed)
if (initializeFileSystemOp.Status != EOperationStatus.Succeeded)
{
Debug.LogError($"初始化小游戏文件系统失败!{initializeFileSystemOp.Error}");
yield break;
@@ -22,10 +22,11 @@ namespace YooAsset
// 请求资源版本
Debug.Log("请求资源版本信息!");
var requestPackageVersionOp = fileSystem.RequestPackageVersionAsync(true, 60);
OperationSystem.StartOperation(packageName, requestPackageVersionOp);
var requestPackageVersionOptions = new FSRequestPackageVersionOptions(true, 60);
var requestPackageVersionOp = fileSystem.RequestPackageVersionAsync(requestPackageVersionOptions);
AsyncOperationSystem.StartOperation(packageName, requestPackageVersionOp);
yield return requestPackageVersionOp;
if (requestPackageVersionOp.Status != EOperationStatus.Succeed)
if (requestPackageVersionOp.Status != EOperationStatus.Succeeded)
{
Debug.LogError($"请求资源版本信息失败!{requestPackageVersionOp.Error}");
yield break;
@@ -34,44 +35,26 @@ namespace YooAsset
// 请求资源清单
string packageVersion = requestPackageVersionOp.PackageVersion;
Debug.Log($"加载资源清单文件!{packageVersion}");
var loadPackageManifestOp = fileSystem.LoadPackageManifestAsync(packageVersion, 60);
OperationSystem.StartOperation(packageName, loadPackageManifestOp);
var loadPackageManifestOptions = new FSLoadPackageManifestOptions(packageVersion, 60);
var loadPackageManifestOp = fileSystem.LoadPackageManifestAsync(loadPackageManifestOptions);
AsyncOperationSystem.StartOperation(packageName, loadPackageManifestOp);
yield return loadPackageManifestOp;
if (loadPackageManifestOp.Status != EOperationStatus.Succeed)
if (loadPackageManifestOp.Status != EOperationStatus.Succeeded)
{
Debug.LogError($"加载资源清单文件失败!{loadPackageManifestOp.Error}");
yield break;
}
// 预下载资源包
Debug.Log("预下载资源包!");
{
var manifest = loadPackageManifestOp.Manifest;
var packageBundle = GetPackageBundle(manifest, testLocation);
var options = new DownloadFileOptions(1);
var downloadFileOp = fileSystem.DownloadFileAsync(packageBundle, options);
OperationSystem.StartOperation(packageName, downloadFileOp);
yield return downloadFileOp;
if (downloadFileOp.Status != EOperationStatus.Succeed)
{
Debug.LogError($"预下载资源包失败!{downloadFileOp.Error}");
yield break;
}
else
{
Debug.Log("预下载资源包成功!");
}
}
// 加载资源包
Debug.Log("加载资源包!");
{
var manifest = loadPackageManifestOp.Manifest;
var packageBundle = GetPackageBundle(manifest, testLocation);
var loadBundleFileOp = fileSystem.LoadBundleFile(packageBundle);
OperationSystem.StartOperation(packageName, loadBundleFileOp);
var loadBundleFileOptions = new FSLoadPackageBundleOptions(packageBundle);
var loadBundleFileOp = fileSystem.LoadPackageBundleAsync(loadBundleFileOptions);
AsyncOperationSystem.StartOperation(packageName, loadBundleFileOp);
yield return loadBundleFileOp;
if (loadBundleFileOp.Status != EOperationStatus.Succeed)
if (loadBundleFileOp.Status != EOperationStatus.Succeeded)
{
Debug.LogError($"加载资源包失败!{loadBundleFileOp.Error}");
yield break;
@@ -82,7 +65,7 @@ namespace YooAsset
}
// 卸载资源包
loadBundleFileOp.Result.UnloadBundleFile();
loadBundleFileOp.BundleHandle.UnloadBundle();
}
Debug.Log("完整测试成功!");

View File

@@ -1,5 +1,6 @@
#if UNITY_WEBGL && DOUYINMINIGAME
#if UNITY_WEBGL && DOUYINMINIGAME
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
@@ -18,32 +19,28 @@ namespace YooAsset
string hostServer = "http://127.0.0.1/CDN/WebGL/yoo";
string packageRoot = $"{StarkSDKSpace.StarkFileSystemManager.USER_DATA_PATH}/__GAME_FILE_CACHE";
IRemoteServices remoteServices = new RemoteServices(hostServer);
IRemoteService remoteService = new RemoteService(hostServer);
TiktokFileSystem fileSystem = new TiktokFileSystem();
fileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
fileSystem.SetParameter(EFileSystemParameter.RemoteService, remoteService);
fileSystem.OnCreate(packageName, packageRoot);
FileSystemTester tester = new FileSystemTester();
yield return tester.RunTester(fileSystem, testLocation);
}
private class RemoteServices : IRemoteServices
private class RemoteService : IRemoteService
{
private readonly string _hostServer;
public RemoteServices(string hostServer)
public RemoteService(string hostServer)
{
_hostServer = hostServer;
}
string IRemoteServices.GetRemoteMainURL(string fileName)
IReadOnlyList<string> IRemoteService.GetRemoteUrls(string fileName)
{
return $"{_hostServer}/{fileName}";
}
string IRemoteServices.GetRemoteFallbackURL(string fileName)
{
return $"{_hostServer}/{fileName}";
return new List<string> { $"{_hostServer}/{fileName}" };
}
}
}
}
#endif
#endif

View File

@@ -1,5 +1,6 @@
#if UNITY_WEBGL && WEIXINMINIGAME
#if UNITY_WEBGL && WEIXINMINIGAME
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
@@ -18,32 +19,28 @@ namespace YooAsset
string hostServer = "http://127.0.0.1/CDN/WebGL/yoo";
string packageRoot = $"{WeChatWASM.WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE";
IRemoteServices remoteServices = new RemoteServices(hostServer);
IRemoteService remoteService = new RemoteService(hostServer);
WechatFileSystem fileSystem = new WechatFileSystem();
fileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
fileSystem.SetParameter(EFileSystemParameter.RemoteService, remoteService);
fileSystem.OnCreate(packageName, packageRoot);
FileSystemTester tester = new FileSystemTester();
yield return tester.RunTester(fileSystem, testLocation);
}
private class RemoteServices : IRemoteServices
private class RemoteService : IRemoteService
{
private readonly string _hostServer;
public RemoteServices(string hostServer)
public RemoteService(string hostServer)
{
_hostServer = hostServer;
}
string IRemoteServices.GetRemoteMainURL(string fileName)
IReadOnlyList<string> IRemoteService.GetRemoteUrls(string fileName)
{
return $"{_hostServer}/{fileName}";
}
string IRemoteServices.GetRemoteFallbackURL(string fileName)
{
return $"{_hostServer}/{fileName}";
return new List<string> { $"{_hostServer}/{fileName}" };
}
}
}
}
#endif
#endif

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 879f2b393f883554899ab3345f0dc998
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,67 +0,0 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
using TTSDK;
namespace YooAsset
{
internal class TTAssetBundleResult : BundleResult
{
private readonly IFileSystem _fileSystem;
private readonly PackageBundle _packageBundle;
private readonly AssetBundle _assetBundle;
public TTAssetBundleResult(IFileSystem fileSystem, PackageBundle packageBundle, AssetBundle assetBundle)
{
_fileSystem = fileSystem;
_packageBundle = packageBundle;
_assetBundle = assetBundle;
}
public override void UnloadBundleFile()
{
if (_assetBundle != null)
{
if (_packageBundle.Encrypted)
_assetBundle.Unload(true);
else
_assetBundle.TTUnload(true);
}
}
public override string GetBundleFilePath()
{
return _fileSystem.GetBundleFilePath(_packageBundle);
}
public override byte[] ReadBundleFileData()
{
return _fileSystem.ReadBundleFileData(_packageBundle);
}
public override string ReadBundleFileText()
{
return _fileSystem.ReadBundleFileText(_packageBundle);
}
public override FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadAssetOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadAllAssetsOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadSubAssetsOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
{
var operation = new AssetBundleLoadSceneOperation(assetInfo, loadParams, suspendLoad);
return operation;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 80ce0631d38cf74458c902fb325afb81
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 8cba5e0b26df8ee40a93d697f889e33d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,113 +0,0 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using UnityEngine;
using YooAsset;
internal class TTFSDownloadFileOperation : FSDownloadFileOperation
{
protected enum ESteps
{
None,
CreateRequest,
CheckRequest,
TryAgain,
Done,
}
private readonly TiktokFileSystem _fileSystem;
private readonly DownloadFileOptions _options;
private UnityWebCacheRequestOperation _webCacheRequestOp;
private int _requestCount = 0;
private float _tryAgainTimer = 0;
private int _failedTryAgain;
private ESteps _steps = ESteps.None;
internal TTFSDownloadFileOperation(TiktokFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
{
_fileSystem = fileSystem;
_options = options;
_failedTryAgain = options.FailedTryAgain;
}
internal override void InternalStart()
{
_steps = ESteps.CreateRequest;
}
internal override void InternalUpdate()
{
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
string url = GetRequestURL();
_webCacheRequestOp = new UnityWebCacheRequestOperation(url);
_webCacheRequestOp.StartOperation();
AddChildOperation(_webCacheRequestOp);
_steps = ESteps.CheckRequest;
}
// 检测下载结果
if (_steps == ESteps.CheckRequest)
{
_webCacheRequestOp.UpdateOperation();
Progress = _webCacheRequestOp.Progress;
DownloadProgress = _webCacheRequestOp.DownloadProgress;
DownloadedBytes = _webCacheRequestOp.DownloadedBytes;
if (_webCacheRequestOp.IsDone == false)
return;
if (_webCacheRequestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
//TODO 需要验证插件请求器的下载进度
DownloadProgress = 1f;
DownloadedBytes = Bundle.FileSize;
Progress = 1f;
}
else
{
if (_failedTryAgain > 0)
{
_steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_webCacheRequestOp.URL} Try again !");
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _webCacheRequestOp.Error;
YooLogger.Error(Error);
}
}
}
// 重新尝试下载
if (_steps == ESteps.TryAgain)
{
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
_tryAgainTimer = 0f;
_failedTryAgain--;
Progress = 0f;
DownloadProgress = 0f;
DownloadedBytes = 0;
_steps = ESteps.CreateRequest;
}
}
}
/// <summary>
/// 获取网络请求地址
/// </summary>
private string GetRequestURL()
{
// 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return _options.FallbackURL;
else
return _options.MainURL;
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 0bdf53359f9e17b41b08982a2be2098c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,20 +0,0 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using YooAsset;
internal partial class TTFSInitializeOperation : FSInitializeFileSystemOperation
{
private readonly TiktokFileSystem _fileSystem;
public TTFSInitializeOperation(TiktokFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalUpdate()
{
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 614227bf558da7149a7eb6de7dfa1a21
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,88 +0,0 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using YooAsset;
internal class TTFSLoadBundleOperation : FSLoadBundleOperation
{
private enum ESteps
{
None,
LoadAssetBundle,
Done,
}
private readonly TiktokFileSystem _fileSystem;
private readonly PackageBundle _bundle;
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
private ESteps _steps = ESteps.None;
internal TTFSLoadBundleOperation(TiktokFileSystem fileSystem, PackageBundle bundle)
{
_fileSystem = fileSystem;
_bundle = bundle;
}
internal override void InternalStart()
{
_steps = ESteps.LoadAssetBundle;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadAssetBundle)
{
if (_loadWebAssetBundleOp == null)
{
string mainRUL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
options.SetURL(mainRUL, fallbackURL);
if (_bundle.Encrypted)
{
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
_loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp);
}
else
{
_loadWebAssetBundleOp = new LoadTiktokAssetBundleOperation(_bundle, options);
_loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp);
}
}
_loadWebAssetBundleOp.UpdateOperation();
Progress = _loadWebAssetBundleOp.Progress;
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
if (_loadWebAssetBundleOp.IsDone == false)
return;
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
{
var assetBundle = _loadWebAssetBundleOp.Result;
_steps = ESteps.Done;
Result = new TTAssetBundleResult(_fileSystem, _bundle, assetBundle);
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadWebAssetBundleOp.Error;
}
}
}
internal override void InternalWaitForAsyncComplete()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "WebGL platform not support sync load method !";
UnityEngine.Debug.LogError(Error);
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 19997de7b89b54445961e8b973f43ab3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,95 +0,0 @@
#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 RequestWebPackageHashOperation _requestPackageHashOp;
private LoadWebPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None;
public TTFSLoadPackageManifestOperation(TiktokFileSystem fileSystem, string packageVersion, int timeout)
{
_fileSystem = fileSystem;
_packageVersion = packageVersion;
_timeout = timeout;
}
internal override void InternalStart()
{
_steps = ESteps.RequestPackageHash;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageHash)
{
if (_requestPackageHashOp == null)
{
_requestPackageHashOp = new RequestWebPackageHashOperation(_fileSystem.RemoteServices, _fileSystem.PackageName, _packageVersion, _timeout);
_requestPackageHashOp.StartOperation();
AddChildOperation(_requestPackageHashOp);
}
_requestPackageHashOp.UpdateOperation();
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;
string packageName = _fileSystem.PackageName;
var manifestServices = _fileSystem.ManifestServices;
var remoteServices = _fileSystem.RemoteServices;
_loadPackageManifestOp = new LoadWebPackageManifestOperation(manifestServices, remoteServices, packageName, _packageVersion, packageHash, _timeout);
_loadPackageManifestOp.StartOperation();
AddChildOperation(_loadPackageManifestOp);
}
_loadPackageManifestOp.UpdateOperation();
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

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 2850c0b0e742f824f9d1f12b7d68b806
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,64 +0,0 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using YooAsset;
internal class TTFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
{
private enum ESteps
{
None,
RequestPackageVersion,
Done,
}
private readonly TiktokFileSystem _fileSystem;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private RequestWebPackageVersionOperation _requestPackageVersionOp;
private ESteps _steps = ESteps.None;
internal TTFSRequestPackageVersionOperation(TiktokFileSystem fileSystem, bool appendTimeTicks, int timeout)
{
_fileSystem = fileSystem;
_appendTimeTicks = appendTimeTicks;
_timeout = timeout;
}
internal override void InternalStart()
{
_steps = ESteps.RequestPackageVersion;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageVersion)
{
if (_requestPackageVersionOp == null)
{
_requestPackageVersionOp = new RequestWebPackageVersionOperation(_fileSystem.RemoteServices, _fileSystem.PackageName, _appendTimeTicks, _timeout);
_requestPackageVersionOp.StartOperation();
AddChildOperation(_requestPackageVersionOp);
}
_requestPackageVersionOp.UpdateOperation();
Progress = _requestPackageVersionOp.Progress;
if (_requestPackageVersionOp.IsDone == false)
return;
if (_requestPackageVersionOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
PackageVersion = _requestPackageVersionOp.PackageVersion;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _requestPackageVersionOp.Error;
}
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8210185faba92a3479bf6713abab1f19
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 101c97835f86e9147993961f514caf2c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,115 +0,0 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using UnityEngine;
namespace YooAsset
{
internal class LoadTiktokAssetBundleOperation : LoadWebAssetBundleOperation
{
protected enum ESteps
{
None,
CreateRequest,
CheckRequest,
TryAgain,
Done,
}
private readonly PackageBundle _bundle;
private readonly DownloadFileOptions _options;
private UnityTiktokAssetBundleRequestOperation _unityAssetBundleRequestOp;
private int _requestCount = 0;
private float _tryAgainTimer = 0;
private int _failedTryAgain;
private ESteps _steps = ESteps.None;
internal LoadTiktokAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options)
{
_bundle = bundle;
_options = options;
_failedTryAgain = options.FailedTryAgain;
}
internal override void InternalStart()
{
_steps = ESteps.CreateRequest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
string url = GetRequestURL();
_unityAssetBundleRequestOp = new UnityTiktokAssetBundleRequestOperation(_bundle, url);
_unityAssetBundleRequestOp.StartOperation();
AddChildOperation(_unityAssetBundleRequestOp);
_steps = ESteps.CheckRequest;
}
// 检测下载结果
if (_steps == ESteps.CheckRequest)
{
_unityAssetBundleRequestOp.UpdateOperation();
Progress = _unityAssetBundleRequestOp.Progress;
DownloadProgress = _unityAssetBundleRequestOp.DownloadProgress;
DownloadedBytes = _unityAssetBundleRequestOp.DownloadedBytes;
if (_unityAssetBundleRequestOp.IsDone == false)
return;
if (_unityAssetBundleRequestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
Result = _unityAssetBundleRequestOp.Result;
}
else
{
if (_failedTryAgain > 0)
{
_steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_unityAssetBundleRequestOp.URL} Try again !");
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _unityAssetBundleRequestOp.Error;
YooLogger.Error(Error);
}
}
}
// 重新尝试下载
if (_steps == ESteps.TryAgain)
{
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
_tryAgainTimer = 0f;
_failedTryAgain--;
Progress = 0f;
DownloadProgress = 0f;
DownloadedBytes = 0;
_steps = ESteps.CreateRequest;
}
}
}
/// <summary>
/// 获取网络请求地址
/// </summary>
private string GetRequestURL()
{
// 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return _options.FallbackURL;
else
return _options.MainURL;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: fa5e1bc536118b14ba56f53930539e38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,95 +0,0 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using UnityEngine.Networking;
using UnityEngine;
using TTSDK;
namespace YooAsset
{
internal class UnityTiktokAssetBundleRequestOperation : UnityWebRequestOperation
{
protected enum ESteps
{
None,
CreateRequest,
Download,
Done,
}
private readonly PackageBundle _packageBundle;
private UnityWebRequestAsyncOperation _requestOperation;
private ESteps _steps = ESteps.None;
/// <summary>
/// 请求结果
/// </summary>
public AssetBundle Result { private set; get; }
internal UnityTiktokAssetBundleRequestOperation(PackageBundle bundle, string url) : base(url)
{
_packageBundle = bundle;
}
internal override void InternalStart()
{
_steps = ESteps.CreateRequest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CreateRequest)
{
CreateWebRequest();
_steps = ESteps.Download;
}
if (_steps == ESteps.Download)
{
DownloadProgress = _webRequest.downloadProgress;
DownloadedBytes = (long)_webRequest.downloadedBytes;
Progress = _requestOperation.progress;
if (_requestOperation.isDone == false)
return;
if (CheckRequestResult())
{
var downloadHanlder = (DownloadHandlerTTAssetBundle)_webRequest.downloadHandler;
AssetBundle assetBundle = downloadHanlder.assetBundle;
if (assetBundle == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"URL : {_requestURL} Download handler asset bundle object is null !";
}
else
{
_steps = ESteps.Done;
Result = assetBundle;
Status = EOperationStatus.Succeed;
//TODO 需要验证插件请求器的下载进度
DownloadProgress = 1f;
DownloadedBytes = _packageBundle.FileSize;
Progress = 1f;
}
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
}
// 注意:最终释放请求器
DisposeRequest();
}
}
private void CreateWebRequest()
{
_webRequest = TTAssetBundle.GetAssetBundle(_requestURL);
_webRequest.disposeDownloadHandlerOnDispose = true;
_requestOperation = _webRequest.SendWebRequest();
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: dbac28b7a131d1043af35b3c2dbe083f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,275 +1,35 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_WEBGL && DOUYINMINIGAME
using YooAsset;
using TTSDK;
public static class TiktokFileSystemCreater
{
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices)
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
{
string fileSystemClass = $"{nameof(TiktokFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices, IWebDecryptionServices decryptionServices)
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor decryptor)
{
string fileSystemClass = $"{nameof(TiktokFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, decryptor);
return fileSystemParams;
}
}
/// <summary>
/// 抖音小游戏文件系统
/// 参考https://developer.open-douyin.com/docs/resource/zh-CN/mini-game/develop/guide/know
/// </summary>
internal class TiktokFileSystem : IFileSystem
internal class TiktokFileSystem : WebGameFileSystem
{
private class WebRemoteServices : IRemoteServices
/// <inheritdoc/>
protected override IWebGamePlatform CreatePlatform(string packageRoot)
{
private readonly string _webPackageRoot;
protected readonly Dictionary<string, string> _mapping = new Dictionary<string, string>(10000);
public WebRemoteServices(string buildinPackRoot)
{
_webPackageRoot = buildinPackRoot;
}
string IRemoteServices.GetRemoteMainURL(string fileName)
{
return GetFileLoadURL(fileName);
}
string IRemoteServices.GetRemoteFallbackURL(string fileName)
{
return GetFileLoadURL(fileName);
}
private string GetFileLoadURL(string fileName)
{
if (_mapping.TryGetValue(fileName, out string url) == false)
{
string filePath = PathUtility.Combine(_webPackageRoot, fileName);
url = DownloadSystemHelper.ConvertToWWWPath(filePath);
_mapping.Add(fileName, url);
}
return url;
}
return new TiktokPlatform(TT.GetFileSystemManager());
}
private readonly Dictionary<string, string> _cacheFilePathMapping = new Dictionary<string, string>(10000);
private TTFileSystemManager _fileSystemMgr;
private string _ttCacheRoot = string.Empty;
/// <summary>
/// 包裹名称
/// </summary>
public string PackageName { private set; get; }
/// <summary>
/// 文件根目录
/// </summary>
public string FileRoot
{
get
{
return _ttCacheRoot;
}
}
/// <summary>
/// 文件数量
/// </summary>
public int FileCount
{
get
{
return 0;
}
}
#region
/// <summary>
/// 自定义参数:远程服务接口
/// </summary>
public IRemoteServices RemoteServices { private set; get; } = null;
/// <summary>
/// 自定义参数:解密方法类
/// </summary>
public IWebDecryptionServices DecryptionServices { private set; get; }
/// <summary>
/// 自定义参数:资源清单服务类
/// </summary>
public IManifestRestoreServices ManifestServices { private set; get; }
#endregion
public TiktokFileSystem()
{
}
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
{
var operation = new TTFSInitializeOperation(this);
return operation;
}
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
{
var operation = new TTFSLoadPackageManifestOperation(this, packageVersion, timeout);
return operation;
}
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new TTFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
return operation;
}
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
{
var operation = new FSClearCacheFilesCompleteOperation();
return operation;
}
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
{
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
options.SetURL(mainURL, fallbackURL);
var operation = new TTFSDownloadFileOperation(this, bundle, options);
return operation;
}
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
{
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
{
var operation = new TTFSLoadBundleOperation(this, bundle);
return operation;
}
else
{
string error = $"{nameof(TiktokFileSystem)} not support load bundle type : {bundle.BundleType}";
var operation = new FSLoadBundleCompleteOperation(error);
return operation;
}
}
public virtual void SetParameter(string name, object value)
{
if (name == FileSystemParametersDefine.REMOTE_SERVICES)
{
RemoteServices = (IRemoteServices)value;
}
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
{
DecryptionServices = (IWebDecryptionServices)value;
}
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES)
{
ManifestServices = (IManifestRestoreServices)value;
}
else
{
YooLogger.Warning($"Invalid parameter : {name}");
}
}
public virtual void OnCreate(string packageName, string packageRoot)
{
PackageName = packageName;
_ttCacheRoot = packageRoot;
if (string.IsNullOrEmpty(_ttCacheRoot))
{
throw new System.Exception("请配置小游戏的缓存根目录!");
}
// 注意CDN服务未启用的情况下使用WEB服务器
if (RemoteServices == null)
{
string webRoot = PathUtility.Combine(Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName, packageName);
RemoteServices = new WebRemoteServices(webRoot);
}
_fileSystemMgr = TT.GetFileSystemManager();
}
public virtual void OnDestroy()
{
}
public virtual bool Belong(PackageBundle bundle)
{
return true;
}
public virtual bool Exists(PackageBundle bundle)
{
return CheckCacheFileExist(bundle);
}
public virtual bool NeedDownload(PackageBundle bundle)
{
if (Belong(bundle) == false)
return false;
return Exists(bundle) == false;
}
public virtual bool NeedUnpack(PackageBundle bundle)
{
return false;
}
public virtual bool NeedImport(PackageBundle bundle)
{
return false;
}
public virtual string GetBundleFilePath(PackageBundle bundle)
{
return GetCacheFileLoadPath(bundle);
}
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
{
if (CheckCacheFileExist(bundle))
{
string filePath = GetCacheFileLoadPath(bundle);
return _fileSystemMgr.ReadFileSync(filePath);
}
else
{
return Array.Empty<byte>();
}
}
public virtual string ReadBundleFileText(PackageBundle bundle)
{
if (CheckCacheFileExist(bundle))
{
string filePath = GetCacheFileLoadPath(bundle);
return _fileSystemMgr.ReadFileSync(filePath, "utf8");
}
else
{
return string.Empty;
}
}
#region
public TTFileSystemManager GetFileSystemMgr()
{
return _fileSystemMgr;
}
public bool CheckCacheFileExist(PackageBundle bundle)
{
string url = RemoteServices.GetRemoteMainURL(bundle.FileName);
return _fileSystemMgr.IsUrlCached(url);
}
private string GetCacheFileLoadPath(PackageBundle bundle)
{
if (_cacheFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = _fileSystemMgr.GetLocalCachedPathForUrl(bundle.FileName);
_cacheFilePathMapping.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
#endregion
}
#endif
#endif

View File

@@ -0,0 +1,54 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using UnityEngine;
using UnityEngine.Networking;
using YooAsset;
using TTSDK;
/// <summary>
/// 抖音小游戏平台实现
/// </summary>
internal class TiktokPlatform : IWebGamePlatform
{
private readonly TTFileSystemManager _fileSystemMgr;
/// <summary>
/// 创建 TiktokPlatform 实例
/// </summary>
/// <param name="fileSystemMgr">抖音文件系统管理器</param>
internal TiktokPlatform(TTFileSystemManager fileSystemMgr)
{
_fileSystemMgr = fileSystemMgr;
}
/// <inheritdoc/>
public UnityWebRequest CreateAssetBundleRequest(string url)
{
return TTAssetBundle.GetAssetBundle(url);
}
/// <inheritdoc/>
public AssetBundle ExtractAssetBundle(UnityWebRequest request)
{
var downloadHandler = (DownloadHandlerTTAssetBundle)request.downloadHandler;
return downloadHandler.assetBundle;
}
/// <inheritdoc/>
public void UnloadAssetBundle(AssetBundle assetBundle, bool unloadAll)
{
assetBundle.TTUnload(unloadAll);
}
/// <inheritdoc/>
public bool IsCached(string cacheFilePath)
{
return false;
}
/// <inheritdoc/>
public string GetCacheFilePath(string rootPath, PackageBundle bundle)
{
return _fileSystemMgr.GetLocalCachedPathForUrl(bundle.GetFileName());
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a06105c2db01f6146a1de58f168eaabf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: b4c0dec5e8fae814eb7ac0299187e8f4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,67 +0,0 @@
#if UNITY_WEBGL && WEIXINMINIGAME
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
using WeChatWASM;
namespace YooAsset
{
internal class WXAssetBundleResult : BundleResult
{
private readonly IFileSystem _fileSystem;
private readonly PackageBundle _packageBundle;
private readonly AssetBundle _assetBundle;
public WXAssetBundleResult(IFileSystem fileSystem, PackageBundle packageBundle, AssetBundle assetBundle)
{
_fileSystem = fileSystem;
_packageBundle = packageBundle;
_assetBundle = assetBundle;
}
public override void UnloadBundleFile()
{
if (_assetBundle != null)
{
if (_packageBundle.Encrypted)
_assetBundle.Unload(true);
else
_assetBundle.WXUnload(true);
}
}
public override string GetBundleFilePath()
{
return _fileSystem.GetBundleFilePath(_packageBundle);
}
public override byte[] ReadBundleFileData()
{
return _fileSystem.ReadBundleFileData(_packageBundle);
}
public override string ReadBundleFileText()
{
return _fileSystem.ReadBundleFileText(_packageBundle);
}
public override FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadAssetOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadAllAssetsOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
{
var operation = new AssetBundleLoadSubAssetsOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
public override FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
{
var operation = new AssetBundleLoadSceneOperation(assetInfo, loadParams, suspendLoad);
return operation;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 750c122b5d921aa4a9c882e21982ebd5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,11 +1,8 @@
#if UNITY_WEBGL && WEIXINMINIGAME
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
#if UNITY_WEBGL && WEIXINMINIGAME
using YooAsset;
using WeChatWASM;
internal class WXFSClearAllBundleFilesOperation : FSClearCacheFilesOperation
internal sealed class WXFSClearAllBundleFilesOperation : FSClearCacheOperation
{
private enum ESteps
{
@@ -22,11 +19,11 @@ internal class WXFSClearAllBundleFilesOperation : FSClearCacheFilesOperation
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
protected override void InternalStart()
{
_steps = ESteps.ClearAllCacheFiles;
}
internal override void InternalUpdate()
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
@@ -41,14 +38,13 @@ internal class WXFSClearAllBundleFilesOperation : FSClearCacheFilesOperation
{
YooLogger.Log("微信缓存清理成功!");
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
SetResult();
}
else
{
YooLogger.Log("微信缓存清理失败!");
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "微信缓存清理失败!";
SetError("微信缓存清理失败!");
}
});
}

View File

@@ -1,11 +1,11 @@
#if UNITY_WEBGL && WEIXINMINIGAME
#if UNITY_WEBGL && WEIXINMINIGAME
using System.Collections.Generic;
using System.IO;
using System.Linq;
using YooAsset;
using WeChatWASM;
internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
internal sealed class WXFSClearUnusedBundleFilesAsync : FSClearCacheOperation
{
private enum ESteps
{
@@ -27,11 +27,11 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
_fileSystem = fileSystem;
_manifest = manifest;
}
internal override void InternalStart()
protected override void InternalStart()
{
_steps = ESteps.GetUnusedCacheFiles;
}
internal override void InternalUpdate()
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
@@ -41,9 +41,8 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
_steps = ESteps.WaitingSearch;
// 说明__GAME_FILE_CACHE/yoo/ 目录下包含所有的资源文件和清单文件
var fileSystemMgr = _fileSystem.GetFileSystemMgr();
var statOption = new WXStatOption();
statOption.path = _fileSystem.FileRoot;
statOption.path = _fileSystem.GetWXCacheRoot();
statOption.recursive = true;
statOption.success = (WXStatResponse response) =>
{
@@ -55,16 +54,15 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
continue;
// 如果是资源清单
//TODO 默认的清单文件格式
if (fileExtension == ".bytes" || fileExtension == ".hash")
continue;
// 注意:适配不同的文件命名方式!
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileStat.path);
string bundleGUID = fileNameWithoutExtension.Split('_').Last();
if (_manifest.TryGetPackageBundleByBundleGUID(bundleGUID, out PackageBundle value) == false)
string bundleGuid = fileNameWithoutExtension.Split('_').Last();
if (_manifest.TryGetPackageBundleByBundleGuid(bundleGuid, out PackageBundle value) == false)
{
string filePath = _fileSystem.FileRoot + fileStat.path;
string filePath = _fileSystem.GetWXCacheRoot() + fileStat.path;
if (_unusedCacheFiles.Contains(filePath) == false)
_unusedCacheFiles.Add(filePath);
}
@@ -77,10 +75,9 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
statOption.fail = (WXStatResponse response) =>
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = response.errMsg;
SetError(response.errMsg);
};
fileSystemMgr.Stat(statOption);
WX.GetFileSystemManager().Stat(statOption);
}
if (_steps == ESteps.ClearUnusedCacheFiles)
@@ -91,7 +88,7 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
_unusedCacheFiles.RemoveAt(i);
WX.RemoveFile(filePath, null);
if (OperationSystem.IsBusy)
if (IsBusy)
break;
}
@@ -103,9 +100,9 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
if (_unusedCacheFiles.Count == 0)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
SetResult();
}
}
}
}
#endif
#endif

View File

@@ -1,115 +0,0 @@
#if UNITY_WEBGL && WEIXINMINIGAME
using UnityEngine;
using YooAsset;
internal class WXFSDownloadFileOperation : FSDownloadFileOperation
{
protected enum ESteps
{
None,
CreateRequest,
CheckRequest,
TryAgain,
Done,
}
private readonly WechatFileSystem _fileSystem;
private readonly DownloadFileOptions _options;
private UnityWebCacheRequestOperation _webCacheRequestOp;
private int _requestCount = 0;
private float _tryAgainTimer = 0;
private int _failedTryAgain;
private ESteps _steps = ESteps.None;
internal WXFSDownloadFileOperation(WechatFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
{
_fileSystem = fileSystem;
_options = options;
_failedTryAgain = options.FailedTryAgain;
}
internal override void InternalStart()
{
_steps = ESteps.CreateRequest;
}
internal override void InternalUpdate()
{
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
string url = GetRequestURL();
_webCacheRequestOp = new UnityWebCacheRequestOperation(url);
_webCacheRequestOp.SetRequestHeader("wechatminigame-preload", "1");
_webCacheRequestOp.StartOperation();
AddChildOperation(_webCacheRequestOp);
_steps = ESteps.CheckRequest;
}
// 检测下载结果
if (_steps == ESteps.CheckRequest)
{
_webCacheRequestOp.UpdateOperation();
Progress = _webCacheRequestOp.Progress;
DownloadProgress = _webCacheRequestOp.DownloadProgress;
DownloadedBytes = _webCacheRequestOp.DownloadedBytes;
if (_webCacheRequestOp.IsDone == false)
return;
if (_webCacheRequestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
//TODO 解决微信小游戏插件问题
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
DownloadProgress = 1f;
DownloadedBytes = Bundle.FileSize;
Progress = 1f;
}
else
{
if (_failedTryAgain > 0)
{
_steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_webCacheRequestOp.URL} Try again !");
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _webCacheRequestOp.Error;
YooLogger.Error(Error);
}
}
}
// 重新尝试下载
if (_steps == ESteps.TryAgain)
{
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
_tryAgainTimer = 0f;
_failedTryAgain--;
Progress = 0f;
DownloadProgress = 0f;
DownloadedBytes = 0;
_steps = ESteps.CreateRequest;
}
}
}
/// <summary>
/// 获取网络请求地址
/// </summary>
private string GetRequestURL()
{
// 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return _options.FallbackURL;
else
return _options.MainURL;
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: e58c7876bd106e04380cbf4c00e8d584
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,20 +0,0 @@
#if UNITY_WEBGL && WEIXINMINIGAME
using YooAsset;
internal partial class WXFSInitializeOperation : FSInitializeFileSystemOperation
{
private readonly WechatFileSystem _fileSystem;
public WXFSInitializeOperation(WechatFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalUpdate()
{
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More