Compare commits

...

17 Commits
1.3.4 ... 1.3.5

Author SHA1 Message Date
hevinci
3bb01ef9a8 Update CHANGELOG.md 2022-11-19 18:34:43 +08:00
hevinci
0204f5f68f Update package.json 2022-11-19 18:34:39 +08:00
hevinci
217d88beaa Update basic sample 2022-11-19 18:34:31 +08:00
hevinci
77080b3934 Update basic sample 2022-11-19 17:54:41 +08:00
hevinci
83f6dc2f76 Update editor code 2022-11-19 17:54:18 +08:00
hevinci
29b3ca4e69 Update runtime code
重构原生文件加载流程。
2022-11-19 17:54:09 +08:00
hevinci
9394ff49fd Update basic sample 2022-11-18 21:35:42 +08:00
hevinci
49949ecda5 Update runtime code
优化资源包缓存文件清理方式。
2022-11-18 21:33:58 +08:00
hevinci
1dab0f2b19 Update patch system
下载器增加取消方法。
2022-11-18 16:45:56 +08:00
hevinci
1cf03bf049 Update basic sample 2022-11-18 10:21:48 +08:00
何冠峰
c00594738f Update asset system
支持场景文件跨资源包配置。
2022-11-16 16:25:43 +08:00
何冠峰
d5f601b0eb Update runtime code 2022-11-16 14:49:38 +08:00
何冠峰
304bff1f19 Fix #43
修复了打包规则按收集器路径来命名,bundle文件名称显示不正确。
2022-11-16 11:51:01 +08:00
hevinci
ce9e0cd88c Update README.md 2022-11-11 11:02:56 +08:00
hevinci
40903d9ad5 Update runtime code 2022-11-11 11:01:37 +08:00
hevinci
0fc97ad2f1 Update document 2022-11-11 11:01:25 +08:00
hevinci
2bb66ea583 Update README.md 2022-11-11 11:01:11 +08:00
48 changed files with 870 additions and 742 deletions

View File

@@ -2,6 +2,53 @@
All notable changes to this package will be documented in this file.
## [1.3.5] - 2022-11-19
### Fixed
- 修复了同步接口加载加密文件失败的问题。
### Added
- 新增了方法AssetsPackage.ClearPackageUnusedCacheFilesAsync()
```c#
/// <summary>
/// 清理本地包裹未使用的缓存文件
/// </summary>
public ClearPackageUnusedCacheFilesOperation ClearPackageUnusedCacheFilesAsync()
```
- 新增了方法AssetsPackage.LoadRawFileAsync()
```c#
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
public RawFileOperationHandle LoadRawFileAsync(string location)
```
- 新增了方法AssetsPackage.LoadRawFileSync()
```c#
/// <summary>
/// 同步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
public RawFileOperationHandle LoadRawFileSync(string location)
```
### Changed
- 重命名AssetsPackage.UpdateStaticVersionAsync()为AssetsPackage.UpdatePackageVersionAsync();
- 重命名AssetsPackage.UpdateManifestAsync()为AssetsPackage.UpdatePackageManifestAsync();
### Removed
- 移除了方法YooAssets.ClearUnusedCacheFiles()
- 移除了方法AssetsPackage.GetRawFileAsync()
## [1.3.4] - 2022-11-04
### Fixed

View File

@@ -7,9 +7,8 @@ namespace YooAsset.Editor
/// <summary>
/// 以文件路径作为资源包名
/// 注意:每个文件独自打资源包
/// 例如:收集器路径为 "Assets/UIPanel"
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop/image/backgroud.bundle"
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop/view/main.bundle"
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image_backgroud.bundle"
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view_main.bundle"
/// </summary>
public class PackSeparately : IPackRule
{
@@ -23,9 +22,8 @@ namespace YooAsset.Editor
/// <summary>
/// 以父类文件夹路径作为资源包名
/// 注意:文件夹下所有文件打进一个资源包
/// 例如:收集器路径为 "Assets/UIPanel"
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop/image.bundle"
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop/view.bundle"
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image.bundle"
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view.bundle"
/// </summary>
public class PackDirectory : IPackRule
{
@@ -42,8 +40,8 @@ namespace YooAsset.Editor
/// 以收集器路径下顶级文件夹为资源包名
/// 注意:文件夹下所有文件打进一个资源包
/// 例如:收集器路径为 "Assets/UIPanel"
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop.bundle"
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop.bundle"
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop.bundle"
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop.bundle"
/// </summary>
public class PackTopDirectory : IPackRule
{
@@ -74,8 +72,17 @@ namespace YooAsset.Editor
{
string IPackRule.GetBundleName(PackRuleData data)
{
string bundleName = StringUtility.RemoveExtension(data.CollectPath);
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
string collectPath = data.CollectPath;
if (AssetDatabase.IsValidFolder(collectPath))
{
string bundleName = collectPath;
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
}
else
{
string bundleName = StringUtility.RemoveExtension(collectPath);
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
}
}
}

View File

@@ -185,7 +185,7 @@ namespace YooAsset.Editor
// Status
StyleColor textColor;
if (bundleInfo.Status == (int)AssetBundleLoaderBase.EStatus.Failed)
if (bundleInfo.Status == (int)BundleLoaderBase.EStatus.Failed)
textColor = new StyleColor(Color.yellow);
else
textColor = label1.style.color;

View File

@@ -8,13 +8,11 @@ namespace YooAsset
{
internal class AssetSystemImpl
{
private static string SceneRunningPackage = string.Empty;
private readonly List<AssetBundleLoaderBase> _loaders = new List<AssetBundleLoaderBase>(1000);
private readonly List<BundleLoaderBase> _loaders = new List<BundleLoaderBase>(1000);
private readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
private readonly Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
private readonly static Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
private static long _sceneCreateCount = 0;
private long _sceneCreateCount = 0;
private bool _simulationOnEditor;
private int _loadingMaxNumber;
public IDecryptionServices DecryptionServices { private set; get; }
@@ -71,9 +69,18 @@ namespace YooAsset
/// </summary>
public void DestroyAll()
{
_loaders.Clear();
foreach (var provider in _providers)
{
provider.Destroy();
}
foreach (var loader in _loaders)
{
loader.Destroy(true);
}
_providers.Clear();
_sceneHandles.Clear();
_loaders.Clear();
ClearSceneHandle();
DecryptionServices = null;
BundleServices = null;
@@ -99,12 +106,12 @@ namespace YooAsset
{
for (int i = _loaders.Count - 1; i >= 0; i--)
{
AssetBundleLoaderBase loader = _loaders[i];
BundleLoaderBase loader = _loaders[i];
loader.TryDestroyAllProviders();
}
for (int i = _loaders.Count - 1; i >= 0; i--)
{
AssetBundleLoaderBase loader = _loaders[i];
BundleLoaderBase loader = _loaders[i];
if (loader.CanDestroy())
{
loader.Destroy(false);
@@ -123,15 +130,14 @@ namespace YooAsset
{
provider.Destroy();
}
_providers.Clear();
foreach (var loader in _loaders)
{
loader.Destroy(true);
}
_loaders.Clear();
_sceneHandles.Clear();
_providers.Clear();
_loaders.Clear();
ClearSceneHandle();
// 注意:调用底层接口释放所有资源
Resources.UnloadUnusedAssets();
@@ -144,25 +150,12 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
YooLogger.Error($"Failed to load scene. {assetInfo.Error}");
YooLogger.Error($"Failed to load scene ! {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<SceneOperationHandle>();
}
// 注意:场景只允许运行在一个资源包内
if (string.IsNullOrEmpty(SceneRunningPackage))
{
SceneRunningPackage = BundleServices.GetPackageName();
}
if (BundleServices.GetPackageName() != SceneRunningPackage)
{
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
string error = $"Scene are allowed to running within only {SceneRunningPackage}";
completedProvider.SetCompleted(error);
return completedProvider.CreateHandle<SceneOperationHandle>();
}
// 如果加载的是主场景,则卸载所有缓存的场景
if (sceneMode == LoadSceneMode.Single)
{
@@ -182,6 +175,7 @@ namespace YooAsset
}
var handle = provider.CreateHandle<SceneOperationHandle>();
handle.PackageName = BundleServices.GetPackageName();
_sceneHandles.Add(providerGUID, handle);
return handle;
}
@@ -193,7 +187,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
YooLogger.Error($"Failed to load asset. {assetInfo.Error}");
YooLogger.Error($"Failed to load asset ! {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<AssetOperationHandle>();
@@ -220,7 +214,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
YooLogger.Error($"Failed to load sub assets. {assetInfo.Error}");
YooLogger.Error($"Failed to load sub assets ! {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<SubAssetsOperationHandle>();
@@ -240,6 +234,33 @@ namespace YooAsset
return provider.CreateHandle<SubAssetsOperationHandle>();
}
/// <summary>
/// 加载原生文件
/// </summary>
public RawFileOperationHandle LoadRawFileAsync(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
{
YooLogger.Error($"Failed to load raw file ! {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<RawFileOperationHandle>();
}
string providerGUID = assetInfo.GUID;
ProviderBase provider = TryGetProvider(providerGUID);
if (provider == null)
{
if (_simulationOnEditor)
provider = new DatabaseRawFileProvider(this, providerGUID, assetInfo);
else
provider = new BundledRawFileProvider(this, providerGUID, assetInfo);
provider.InitSpawnDebugInfo();
_providers.Add(provider);
}
return provider.CreateHandle<RawFileOperationHandle>();
}
internal void UnloadSubScene(ProviderBase provider)
{
string providerGUID = provider.ProviderGUID;
@@ -265,19 +286,37 @@ namespace YooAsset
// 卸载未被使用的资源(包括场景)
UnloadUnusedAssets();
}
internal void ClearSceneHandle()
{
// 释放资源包下的所有场景
string packageName = BundleServices.GetPackageName();
List<string> removeList = new List<string>();
foreach (var valuePair in _sceneHandles)
{
if (valuePair.Value.PackageName == packageName)
{
removeList.Add(valuePair.Key);
}
}
internal AssetBundleLoaderBase CreateOwnerAssetBundleLoader(AssetInfo assetInfo)
foreach (var key in removeList)
{
_sceneHandles.Remove(key);
}
}
internal BundleLoaderBase CreateOwnerAssetBundleLoader(AssetInfo assetInfo)
{
BundleInfo bundleInfo = BundleServices.GetBundleInfo(assetInfo);
return CreateAssetBundleLoaderInternal(bundleInfo);
}
internal List<AssetBundleLoaderBase> CreateDependAssetBundleLoaders(AssetInfo assetInfo)
internal List<BundleLoaderBase> CreateDependAssetBundleLoaders(AssetInfo assetInfo)
{
BundleInfo[] depends = BundleServices.GetAllDependBundleInfos(assetInfo);
List<AssetBundleLoaderBase> result = new List<AssetBundleLoaderBase>(depends.Length);
List<BundleLoaderBase> result = new List<BundleLoaderBase>(depends.Length);
foreach (var bundleInfo in depends)
{
AssetBundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(bundleInfo);
BundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(bundleInfo);
result.Add(dependLoader);
}
return result;
@@ -290,10 +329,10 @@ namespace YooAsset
}
}
private AssetBundleLoaderBase CreateAssetBundleLoaderInternal(BundleInfo bundleInfo)
private BundleLoaderBase CreateAssetBundleLoaderInternal(BundleInfo bundleInfo)
{
// 如果加载器已经存在
AssetBundleLoaderBase loader = TryGetAssetBundleLoader(bundleInfo.Bundle.BundleName);
BundleLoaderBase loader = TryGetAssetBundleLoader(bundleInfo.Bundle.BundleName);
if (loader != null)
return loader;
@@ -301,18 +340,21 @@ namespace YooAsset
#if UNITY_WEBGL
loader = new AssetBundleWebLoader(this, bundleInfo);
#else
loader = new AssetBundleFileLoader(this, bundleInfo);
if (bundleInfo.Bundle.IsRawFile)
loader = new RawBundleFileLoader(this, bundleInfo);
else
loader = new AssetBundleFileLoader(this, bundleInfo);
#endif
_loaders.Add(loader);
return loader;
}
private AssetBundleLoaderBase TryGetAssetBundleLoader(string bundleName)
private BundleLoaderBase TryGetAssetBundleLoader(string bundleName)
{
AssetBundleLoaderBase loader = null;
BundleLoaderBase loader = null;
for (int i = 0; i < _loaders.Count; i++)
{
AssetBundleLoaderBase temp = _loaders[i];
BundleLoaderBase temp = _loaders[i];
if (temp.MainBundleInfo.Bundle.BundleName.Equals(bundleName))
{
loader = temp;

View File

@@ -0,0 +1,95 @@
using System.IO;
using System.Text;
namespace YooAsset
{
public class RawFileOperationHandle : OperationHandleBase
{
private System.Action<RawFileOperationHandle> _callback;
internal RawFileOperationHandle(ProviderBase provider) : base(provider)
{
}
internal override void InvokeCallback()
{
_callback?.Invoke(this);
}
/// <summary>
/// 完成委托
/// </summary>
public event System.Action<RawFileOperationHandle> Completed
{
add
{
if (IsValid == false)
throw new System.Exception($"{nameof(RawFileOperationHandle)} is invalid");
if (Provider.IsDone)
value.Invoke(this);
else
_callback += value;
}
remove
{
if (IsValid == false)
throw new System.Exception($"{nameof(RawFileOperationHandle)} is invalid");
_callback -= value;
}
}
/// <summary>
/// 等待异步执行完毕
/// </summary>
public void WaitForAsyncComplete()
{
if (IsValid == false)
return;
Provider.WaitForAsyncComplete();
}
/// <summary>
/// 释放资源句柄
/// </summary>
public void Release()
{
this.ReleaseInternal();
}
/// <summary>
/// 获取原生文件的二进制数据
/// </summary>
public byte[] GetRawFileData()
{
if (IsValid == false)
return null;
string filePath = Provider.RawFilePath;
if (File.Exists(filePath) == false)
return null;
return File.ReadAllBytes(filePath);
}
/// <summary>
/// 获取原生文件的文本数据
/// </summary>
public string GetRawFileText()
{
if (IsValid == false)
return null;
string filePath = Provider.RawFilePath;
if (File.Exists(filePath) == false)
return null;
return File.ReadAllText(filePath, Encoding.UTF8);
}
/// <summary>
/// 获取原生文件的路径
/// </summary>
public string GetRawFilePath()
{
if (IsValid == false)
return string.Empty;
return Provider.RawFilePath;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e26f14db9addb4c49b4f0f520bf75d9d
guid: e8420ba734d425a4ba9f19173d74503c
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -3,8 +3,9 @@
namespace YooAsset
{
public class SceneOperationHandle : OperationHandleBase
{
{
private System.Action<SceneOperationHandle> _callback;
internal string PackageName { set; get; }
internal SceneOperationHandle(ProviderBase provider) : base(provider)
{

View File

@@ -6,7 +6,7 @@ using UnityEngine;
namespace YooAsset
{
internal sealed class AssetBundleFileLoader : AssetBundleLoaderBase
internal sealed class AssetBundleFileLoader : BundleLoaderBase
{
private enum ESteps
{
@@ -21,7 +21,6 @@ namespace YooAsset
}
private ESteps _steps = ESteps.None;
private string _fileLoadPath;
private bool _isWaitForAsyncComplete = false;
private bool _isShowWaitForAsyncError = false;
private DownloaderBase _unpacker;
@@ -47,7 +46,7 @@ namespace YooAsset
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
{
_steps = ESteps.Download;
_fileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
}
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
{
@@ -56,22 +55,22 @@ namespace YooAsset
if (loadMethod == EBundleLoadMethod.LoadFromMemory || loadMethod == EBundleLoadMethod.LoadFromStream)
{
_steps = ESteps.Unpack;
_fileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
}
else
{
_steps = ESteps.LoadFile;
_fileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
}
#else
_steps = ESteps.LoadFile;
_fileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
#endif
}
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
{
_steps = ESteps.LoadFile;
_fileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
}
else
{
@@ -137,11 +136,11 @@ namespace YooAsset
{
#if UNITY_EDITOR
// 注意Unity2017.4编辑器模式下如果AssetBundle文件不存在会导致编辑器崩溃这里做了预判。
if (System.IO.File.Exists(_fileLoadPath) == false)
if (System.IO.File.Exists(FileLoadPath) == false)
{
_steps = ESteps.Done;
Status = EStatus.Failed;
LastError = $"Not found assetBundle file : {_fileLoadPath}";
LastError = $"Not found assetBundle file : {FileLoadPath}";
YooLogger.Error(LastError);
return;
}
@@ -152,9 +151,9 @@ namespace YooAsset
if (loadMethod == EBundleLoadMethod.Normal)
{
if (_isWaitForAsyncComplete)
CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath);
CacheBundle = AssetBundle.LoadFromFile(FileLoadPath);
else
_createRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath);
_createRequest = AssetBundle.LoadFromFileAsync(FileLoadPath);
}
else
{
@@ -169,15 +168,15 @@ namespace YooAsset
DecryptFileInfo fileInfo = new DecryptFileInfo();
fileInfo.BundleName = MainBundleInfo.Bundle.BundleName;
fileInfo.FilePath = _fileLoadPath;
fileInfo.FilePath = FileLoadPath;
if (loadMethod == EBundleLoadMethod.LoadFromFileOffset)
{
ulong offset = Impl.DecryptionServices.LoadFromFileOffset(fileInfo);
if (_isWaitForAsyncComplete)
CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset);
CacheBundle = AssetBundle.LoadFromFile(FileLoadPath, 0, offset);
else
_createRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath, 0, offset);
_createRequest = AssetBundle.LoadFromFileAsync(FileLoadPath, 0, offset);
}
else if (loadMethod == EBundleLoadMethod.LoadFromMemory)
{
@@ -279,6 +278,14 @@ namespace YooAsset
int frame = 1000;
while (true)
{
// 文件解压
if (_unpacker != null)
{
_unpacker.Update();
if (_unpacker.IsDone() == false)
continue;
}
// 保险机制
// 注意如果需要从WEB端下载资源可能会触发保险机制
frame--;

View File

@@ -7,7 +7,7 @@ using UnityEngine.Networking;
namespace YooAsset
{
internal sealed class AssetBundleWebLoader : AssetBundleLoaderBase
internal sealed class AssetBundleWebLoader : BundleLoaderBase
{
private enum ESteps
{
@@ -24,7 +24,6 @@ namespace YooAsset
private ESteps _steps = ESteps.None;
private float _tryTimer = 0;
private string _fileLoadPath;
private bool _isShowWaitForAsyncError = false;
private DownloaderBase _downloader;
private UnityWebRequest _webRequest;
@@ -48,17 +47,17 @@ namespace YooAsset
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
{
_steps = ESteps.Download;
_fileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
}
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
{
_steps = ESteps.LoadWebFile;
_fileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
}
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
{
_steps = ESteps.LoadCacheFile;
_fileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
}
else
{
@@ -97,11 +96,11 @@ namespace YooAsset
{
#if UNITY_EDITOR
// 注意Unity2017.4编辑器模式下如果AssetBundle文件不存在会导致编辑器崩溃这里做了预判。
if (System.IO.File.Exists(_fileLoadPath) == false)
if (System.IO.File.Exists(FileLoadPath) == false)
{
_steps = ESteps.Done;
Status = EStatus.Failed;
LastError = $"Not found assetBundle file : {_fileLoadPath}";
LastError = $"Not found assetBundle file : {FileLoadPath}";
YooLogger.Error(LastError);
return;
}
@@ -111,7 +110,7 @@ namespace YooAsset
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
if (loadMethod == EBundleLoadMethod.Normal)
{
_createRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath);
_createRequest = AssetBundle.LoadFromFileAsync(FileLoadPath);
}
else
{
@@ -163,7 +162,8 @@ namespace YooAsset
// 5. 从WEB网站获取AssetBundle文件
if (_steps == ESteps.LoadWebFile)
{
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_fileLoadPath, Hash128.Parse(MainBundleInfo.Bundle.FileHash));
var hash = Hash128.Parse(MainBundleInfo.Bundle.FileHash);
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath, hash);
_webRequest.SendWebRequest();
_steps = ESteps.CheckLoadWebFile;
}
@@ -180,7 +180,7 @@ namespace YooAsset
if (_webRequest.isNetworkError || _webRequest.isHttpError)
#endif
{
YooLogger.Warning($"Failed to get asset bundle from web : {_fileLoadPath} Error : {_webRequest.error}");
YooLogger.Warning($"Failed to get asset bundle from web : {FileLoadPath} Error : {_webRequest.error}");
_steps = ESteps.TryLoadWebFile;
_tryTimer = 0;
}

View File

@@ -5,7 +5,7 @@ using UnityEngine;
namespace YooAsset
{
internal abstract class AssetBundleLoaderBase
internal abstract class BundleLoaderBase
{
public enum EStatus
{
@@ -46,9 +46,10 @@ namespace YooAsset
private readonly List<ProviderBase> _providers = new List<ProviderBase>(100);
internal AssetBundle CacheBundle { set; get; }
internal string FileLoadPath { set; get; }
public AssetBundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo)
public BundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo)
{
Impl = impl;
MainBundleInfo = bundleInfo;

View File

@@ -9,10 +9,10 @@ namespace YooAsset
/// <summary>
/// 依赖的资源包加载器列表
/// </summary>
private readonly List<AssetBundleLoaderBase> _dependBundles;
private readonly List<BundleLoaderBase> _dependBundles;
public DependAssetBundleGroup(List<AssetBundleLoaderBase> dpendBundles)
public DependAssetBundleGroup(List<BundleLoaderBase> dpendBundles)
{
_dependBundles = dpendBundles;
}
@@ -37,7 +37,7 @@ namespace YooAsset
{
foreach (var loader in _dependBundles)
{
if (loader.Status != AssetBundleLoaderBase.EStatus.Succeed)
if (loader.Status != BundleLoaderBase.EStatus.Succeed)
{
return false;
}
@@ -52,7 +52,7 @@ namespace YooAsset
{
foreach (var loader in _dependBundles)
{
if (loader.Status != AssetBundleLoaderBase.EStatus.Succeed)
if (loader.Status != BundleLoaderBase.EStatus.Succeed)
{
return loader.LastError;
}

View File

@@ -0,0 +1,174 @@
using System.IO;
namespace YooAsset
{
internal class RawBundleFileLoader : BundleLoaderBase
{
private enum ESteps
{
None,
Download,
CheckDownload,
Unpack,
CheckUnpack,
CheckFile,
Done,
}
private ESteps _steps = ESteps.None;
private bool _isWaitForAsyncComplete = false;
private bool _isShowWaitForAsyncError = false;
private DownloaderBase _unpacker;
private DownloaderBase _downloader;
public RawBundleFileLoader(AssetSystemImpl impl, BundleInfo bundleInfo) : base(impl, bundleInfo)
{
}
/// <summary>
/// 轮询更新
/// </summary>
public override void Update()
{
if (_steps == ESteps.Done)
return;
if (_steps == ESteps.None)
{
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
{
_steps = ESteps.Download;
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
}
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
{
#if UNITY_ANDROID || UNITY_WEBGL
_steps = ESteps.Unpack;
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
#else
_steps = ESteps.CheckFile;
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
#endif
}
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
{
_steps = ESteps.CheckFile;
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
}
else
{
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
}
}
// 1. 下载远端文件
if (_steps == ESteps.Download)
{
int failedTryAgain = int.MaxValue;
_downloader = DownloadSystem.BeginDownload(MainBundleInfo, failedTryAgain);
_steps = ESteps.CheckDownload;
}
// 2. 检测下载结果
if (_steps == ESteps.CheckDownload)
{
if (_downloader.IsDone() == false)
return;
if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EStatus.Failed;
LastError = _downloader.GetLastError();
}
else
{
_steps = ESteps.CheckFile;
}
}
// 3. 解压内置文件
if (_steps == ESteps.Unpack)
{
int failedTryAgain = 1;
var bundleInfo = HostPlayModeImpl.ConvertToUnpackInfo(MainBundleInfo.Bundle);
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckUnpack;
}
// 4. 检测解压结果
if (_steps == ESteps.CheckUnpack)
{
if (_unpacker.IsDone() == false)
return;
if (_unpacker.HasError())
{
_steps = ESteps.Done;
Status = EStatus.Failed;
LastError = _unpacker.GetLastError();
}
else
{
_steps = ESteps.CheckFile;
}
}
// 5. 检测结果
if (_steps == ESteps.CheckFile)
{
_steps = ESteps.Done;
if (File.Exists(FileLoadPath))
{
Status = EStatus.Succeed;
}
else
{
Status = EStatus.Failed;
LastError = $"Raw file not found : {FileLoadPath}";
}
}
}
/// <summary>
/// 主线程等待异步操作完毕
/// </summary>
public override void WaitForAsyncComplete()
{
_isWaitForAsyncComplete = true;
int frame = 1000;
while (true)
{
// 文件解压
if (_unpacker != null)
{
_unpacker.Update();
if (_unpacker.IsDone() == false)
continue;
}
// 保险机制
// 注意如果需要从WEB端下载资源可能会触发保险机制
frame--;
if (frame == 0)
{
if (_isShowWaitForAsyncError == false)
{
_isShowWaitForAsyncError = true;
YooLogger.Error($"WaitForAsyncComplete failed ! Try load bundle : {MainBundleInfo.Bundle.BundleName} from remote with sync load method !");
}
break;
}
// 驱动流程
Update();
// 完成后退出
if (IsDone())
break;
}
}
}
}

View File

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

View File

@@ -1,468 +0,0 @@
using System.IO;
namespace YooAsset
{
/// <summary>
/// 原生文件操作
/// </summary>
public abstract class RawFileOperation : AsyncOperationBase
{
internal readonly BundleInfo _bundleInfo;
/// <summary>
/// 原生文件的拷贝路径
/// </summary>
public string CopyPath { private set; get; }
internal RawFileOperation(BundleInfo bundleInfo, string copyPath)
{
_bundleInfo = bundleInfo;
CopyPath = copyPath;
}
/// <summary>
/// 原生文件的缓存路径
/// </summary>
public abstract string GetCachePath();
/// <summary>
/// 获取原生文件的二进制数据
/// </summary>
public byte[] LoadFileData()
{
string filePath = GetCachePath();
if (File.Exists(filePath) == false)
return null;
return File.ReadAllBytes(filePath);
}
/// <summary>
/// 获取原生文件的文本数据
/// </summary>
public string LoadFileText()
{
string filePath = GetCachePath();
if (File.Exists(filePath) == false)
return string.Empty;
return File.ReadAllText(filePath, System.Text.Encoding.UTF8);
}
}
/// <summary>
/// 发生错误的原生文件操作
/// </summary>
internal sealed class CompletedRawFileOperation : RawFileOperation
{
private readonly string _error;
internal CompletedRawFileOperation(string error, string copyPath) : base(null, copyPath)
{
_error = error;
}
internal override void Start()
{
Status = EOperationStatus.Failed;
Error = _error;
}
internal override void Update()
{
}
/// <summary>
/// 原生文件的缓存路径
/// </summary>
public override string GetCachePath()
{
return string.Empty;
}
}
/// <summary>
/// 编辑器下模拟运行的原生文件操作
/// </summary>
internal sealed class EditorPlayModeRawFileOperation : RawFileOperation
{
private enum ESteps
{
None,
Prepare,
CheckAndCopyFile,
Done,
}
private ESteps _steps = ESteps.None;
internal EditorPlayModeRawFileOperation(BundleInfo bundleInfo, string copyPath) : base(bundleInfo, copyPath)
{
}
internal override void Start()
{
_steps = ESteps.Prepare;
}
internal override void Update()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
// 1. 准备工作
if (_steps == ESteps.Prepare)
{
if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromEditor)
{
_steps = ESteps.CheckAndCopyFile;
return; // 模拟实现异步操作
}
else
{
throw new System.NotImplementedException(_bundleInfo.LoadMode.ToString());
}
}
// 2. 检测并拷贝原生文件
if (_steps == ESteps.CheckAndCopyFile)
{
// 如果不需要保存文件
if (string.IsNullOrEmpty(CopyPath))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
return;
}
// 如果原生文件已经存在,则将其删除
if (File.Exists(CopyPath))
{
File.Delete(CopyPath);
}
try
{
FileUtility.CreateFileDirectory(CopyPath);
File.Copy(GetCachePath(), CopyPath, true);
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
catch (System.Exception e)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = e.Message;
}
}
}
/// <summary>
/// 原生文件的缓存路径
/// </summary>
public override string GetCachePath()
{
if (_bundleInfo == null)
return string.Empty;
return _bundleInfo.EditorAssetPath;
}
}
/// <summary>
/// 离线模式的原生文件操作
/// </summary>
internal sealed class OfflinePlayModeRawFileOperation : RawFileOperation
{
private enum ESteps
{
None,
Prepare,
Unpack,
CheckUnpack,
CheckAndCopyFile,
Done,
}
private ESteps _steps = ESteps.None;
private DownloaderBase _unpacker;
public OfflinePlayModeRawFileOperation(BundleInfo bundleInfo, string copyPath) : base(bundleInfo, copyPath)
{
}
internal override void Start()
{
_steps = ESteps.Prepare;
}
internal override void Update()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
// 1. 准备工作
if (_steps == ESteps.Prepare)
{
if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.None)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Bundle info is invalid : {_bundleInfo.Bundle.BundleName}";
}
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
{
_steps = ESteps.Unpack;
}
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
{
_steps = ESteps.CheckAndCopyFile;
}
else
{
throw new System.NotImplementedException(_bundleInfo.LoadMode.ToString());
}
}
// 2. 内置文件解压
if (_steps == ESteps.Unpack)
{
int failedTryAgain = 1;
var bundleInfo = HostPlayModeImpl.ConvertToUnpackInfo(_bundleInfo.Bundle);
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckUnpack;
}
// 3. 检测内置文件解压结果
if (_steps == ESteps.CheckUnpack)
{
Progress = _unpacker.DownloadProgress;
if (_unpacker.IsDone() == false)
return;
if (_unpacker.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _unpacker.GetLastError();
}
else
{
_steps = ESteps.CheckAndCopyFile;
}
}
// 4. 检测并拷贝原生文件
if (_steps == ESteps.CheckAndCopyFile)
{
// 如果不需要保存文件
if (string.IsNullOrEmpty(CopyPath))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
return;
}
// 如果原生文件已经存在,则验证其完整性
if (File.Exists(CopyPath))
{
var verifyResult = CacheSystem.VerifyContentInternal(CopyPath, _bundleInfo.Bundle.FileSize, _bundleInfo.Bundle.FileCRC, EVerifyLevel.High);
if (verifyResult == EVerifyResult.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
return;
}
else
{
File.Delete(CopyPath);
}
}
try
{
FileUtility.CreateFileDirectory(CopyPath);
File.Copy(GetCachePath(), CopyPath, true);
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
catch (System.Exception e)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = e.Message;
}
}
}
/// <summary>
/// 原生文件的缓存路径
/// </summary>
public override string GetCachePath()
{
if (_bundleInfo == null)
return string.Empty;
return _bundleInfo.Bundle.CachedFilePath;
}
}
/// <summary>
/// 联机模式的原生文件操作
/// </summary>
internal sealed class HostPlayModeRawFileOperation : RawFileOperation
{
private enum ESteps
{
None,
Prepare,
Download,
CheckDownload,
Unpack,
CheckUnpack,
CheckAndCopyFile,
Done,
}
private ESteps _steps = ESteps.None;
private DownloaderBase _unpacker;
private DownloaderBase _downloader;
internal HostPlayModeRawFileOperation(BundleInfo bundleInfo, string copyPath) : base(bundleInfo, copyPath)
{
}
internal override void Start()
{
_steps = ESteps.Prepare;
}
internal override void Update()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
// 1. 准备工作
if (_steps == ESteps.Prepare)
{
if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.None)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Bundle info is invalid : {_bundleInfo.Bundle.BundleName}";
}
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
{
_steps = ESteps.Download;
}
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
{
_steps = ESteps.Unpack;
}
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
{
_steps = ESteps.CheckAndCopyFile;
}
else
{
throw new System.NotImplementedException(_bundleInfo.LoadMode.ToString());
}
}
// 2. 下载远端文件
if (_steps == ESteps.Download)
{
int failedTryAgain = int.MaxValue;
_downloader = DownloadSystem.BeginDownload(_bundleInfo, failedTryAgain);
_steps = ESteps.CheckDownload;
}
// 3. 检测下载结果
if (_steps == ESteps.CheckDownload)
{
Progress = _downloader.DownloadProgress;
if (_downloader.IsDone() == false)
return;
if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader.GetLastError();
}
else
{
_steps = ESteps.CheckAndCopyFile;
}
}
// 3. 解压内置文件
if (_steps == ESteps.Unpack)
{
int failedTryAgain = 1;
var bundleInfo = HostPlayModeImpl.ConvertToUnpackInfo(_bundleInfo.Bundle);
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckUnpack;
}
// 4. 检测解压结果
if (_steps == ESteps.CheckUnpack)
{
Progress = _unpacker.DownloadProgress;
if (_unpacker.IsDone() == false)
return;
if (_unpacker.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _unpacker.GetLastError();
}
else
{
_steps = ESteps.CheckAndCopyFile;
}
}
// 5. 检测并拷贝原生文件
if (_steps == ESteps.CheckAndCopyFile)
{
// 如果不需要保存文件
if (string.IsNullOrEmpty(CopyPath))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
return;
}
// 如果原生文件已经存在,则验证其完整性
if (File.Exists(CopyPath))
{
var verifyResult = CacheSystem.VerifyContentInternal(CopyPath, _bundleInfo.Bundle.FileSize, _bundleInfo.Bundle.FileCRC, EVerifyLevel.High);
if (verifyResult == EVerifyResult.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
return;
}
else
{
File.Delete(CopyPath);
}
}
try
{
FileUtility.CreateFileDirectory(CopyPath);
File.Copy(GetCachePath(), CopyPath, true);
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
catch (System.Exception e)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = e.Message;
}
}
}
/// <summary>
/// 原生文件的缓存路径
/// </summary>
public override string GetCachePath()
{
if (_bundleInfo == null)
return string.Empty;
return _bundleInfo.Bundle.CachedFilePath;
}
}
}

View File

@@ -54,7 +54,7 @@ namespace YooAsset
return;
}
if (OwnerBundle.Status != AssetBundleLoaderBase.EStatus.Succeed)
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
Status = EStatus.Fail;
LastError = OwnerBundle.LastError;

View File

@@ -5,7 +5,7 @@ namespace YooAsset
{
internal abstract class BundledProvider : ProviderBase
{
protected AssetBundleLoaderBase OwnerBundle { private set; get; }
protected BundleLoaderBase OwnerBundle { private set; get; }
protected DependAssetBundleGroup DependBundleGroup { private set; get; }
public BundledProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)

View File

@@ -0,0 +1,61 @@

namespace YooAsset
{
internal class BundledRawFileProvider : BundledProvider
{
public override float Progress
{
get
{
if (IsDone)
return 1f;
else
return 0;
}
}
public BundledRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
{
}
public override void Update()
{
DebugRecording();
if (IsDone)
return;
if (Status == EStatus.None)
{
Status = EStatus.CheckBundle;
}
if (Status == EStatus.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
OwnerBundle.WaitForAsyncComplete();
}
if (OwnerBundle.IsDone() == false)
return;
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
Status = EStatus.Fail;
LastError = OwnerBundle.LastError;
InvokeCompletion();
return;
}
Status = EStatus.Checking;
}
if (Status == EStatus.Checking)
{
RawFilePath = OwnerBundle.FileLoadPath;
Status = EStatus.Success;
InvokeCompletion();
}
}
}
}

View File

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

View File

@@ -58,7 +58,7 @@ namespace YooAsset
return;
}
if (OwnerBundle.Status != AssetBundleLoaderBase.EStatus.Succeed)
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
Status = EStatus.Fail;
LastError = OwnerBundle.LastError;

View File

@@ -54,7 +54,7 @@ namespace YooAsset
return;
}
if (OwnerBundle.Status != AssetBundleLoaderBase.EStatus.Succeed)
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
Status = EStatus.Fail;
LastError = OwnerBundle.LastError;

View File

@@ -0,0 +1,55 @@

namespace YooAsset
{
internal class DatabaseRawFileProvider : ProviderBase
{
public override float Progress
{
get
{
if (IsDone)
return 1f;
else
return 0;
}
}
public DatabaseRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
{
}
public override void Update()
{
#if UNITY_EDITOR
if (IsDone)
return;
if (Status == EStatus.None)
{
// 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
if (string.IsNullOrEmpty(guid))
{
Status = EStatus.Fail;
LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError);
InvokeCompletion();
return;
}
Status = EStatus.Checking;
// 注意:模拟异步加载效果提前返回
if (IsWaitForAsyncComplete == false)
return;
}
if(Status == EStatus.Checking)
{
RawFilePath = MainAssetInfo.AssetPath;
Status = EStatus.Success;
InvokeCompletion();
}
#endif
}
}
}

View File

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

View File

@@ -47,6 +47,11 @@ namespace YooAsset
/// </summary>
public UnityEngine.SceneManagement.Scene SceneObject { protected set; get; }
/// <summary>
/// 原生文件路径
/// </summary>
public string RawFilePath { protected set; get; }
/// <summary>
/// 当前的加载状态
@@ -152,6 +157,8 @@ namespace YooAsset
handle = new SceneOperationHandle(this);
else if (typeof(T) == typeof(SubAssetsOperationHandle))
handle = new SubAssetsOperationHandle(this);
else if (typeof(T) == typeof(RawFileOperationHandle))
handle = new RawFileOperationHandle(this);
else
throw new System.NotImplementedException();

View File

@@ -185,24 +185,24 @@ namespace YooAsset
/// 向网络端请求最新的资源版本
/// </summary>
/// <param name="timeout">超时时间默认值60秒</param>
public UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout = 60)
public UpdatePackageVersionOperation UpdatePackageVersionAsync(int timeout = 60)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorSimulateMode)
{
var operation = new EditorPlayModeUpdateStaticVersionOperation();
var operation = new EditorPlayModeUpdatePackageVersionOperation();
OperationSystem.StartOperation(operation);
return operation;
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
var operation = new OfflinePlayModeUpdateStaticVersionOperation();
var operation = new OfflinePlayModeUpdatePackageVersionOperation();
OperationSystem.StartOperation(operation);
return operation;
}
else if (_playMode == EPlayMode.HostPlayMode)
{
return _hostPlayModeImpl.UpdateStaticVersionAsync(PackageName, timeout);
return _hostPlayModeImpl.UpdatePackageVersionAsync(PackageName, timeout);
}
else
{
@@ -215,25 +215,25 @@ namespace YooAsset
/// </summary>
/// <param name="packageVersion">更新的包裹版本</param>
/// <param name="timeout">超时时间默认值60秒</param>
public UpdateManifestOperation UpdateManifestAsync(string packageVersion, int timeout = 60)
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60)
{
DebugCheckInitialize();
DebugCheckUpdateManifest();
if (_playMode == EPlayMode.EditorSimulateMode)
{
var operation = new EditorPlayModeUpdateManifestOperation();
var operation = new EditorPlayModeUpdatePackageManifestOperation();
OperationSystem.StartOperation(operation);
return operation;
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
var operation = new OfflinePlayModeUpdateManifestOperation();
var operation = new OfflinePlayModeUpdatePackageManifestOperation();
OperationSystem.StartOperation(operation);
return operation;
}
else if (_playMode == EPlayMode.HostPlayMode)
{
return _hostPlayModeImpl.UpdatePatchManifestAsync(PackageName, packageVersion, timeout);
return _hostPlayModeImpl.UpdatePackageManifestAsync(PackageName, packageVersion, timeout);
}
else
{
@@ -270,7 +270,18 @@ namespace YooAsset
}
/// <summary>
/// 获取包裹的版本信息
/// 清理本地包裹未使用的缓存文件
/// </summary>
public ClearPackageUnusedCacheFilesOperation ClearPackageUnusedCacheFilesAsync()
{
DebugCheckInitialize();
var operation = new ClearPackageUnusedCacheFilesOperation(this);
OperationSystem.StartOperation(operation);
return operation;
}
/// <summary>
/// 获取本地包裹的版本信息
/// </summary>
public string GetPackageVersion()
{
@@ -401,74 +412,63 @@ namespace YooAsset
#region
/// <summary>
/// 异步获取原生文件
/// 同步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="copyPath">拷贝路径</param>
public RawFileOperation GetRawFileAsync(string location, string copyPath = null)
/// <param name="assetInfo">资源信息</param>
public RawFileOperationHandle LoadRawFileSync(AssetInfo assetInfo)
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return GetRawFileInternal(assetInfo, copyPath);
return LoadRawFileInternal(assetInfo, true);
}
/// <summary>
/// 异步获取原生文件
/// 同步加载原生文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
/// <param name="copyPath">拷贝路径</param>
public RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null)
/// <param name="location">资源的定位地址</param>
public RawFileOperationHandle LoadRawFileSync(string location)
{
DebugCheckInitialize();
return GetRawFileInternal(assetInfo, copyPath);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return LoadRawFileInternal(assetInfo, true);
}
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
public RawFileOperationHandle LoadRawFileAsync(AssetInfo assetInfo)
{
DebugCheckInitialize();
return LoadRawFileInternal(assetInfo, false);
}
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
public RawFileOperationHandle LoadRawFileAsync(string location)
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return LoadRawFileInternal(assetInfo, false);
}
private RawFileOperation GetRawFileInternal(AssetInfo assetInfo, string copyPath)
private RawFileOperationHandle LoadRawFileInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
{
if (assetInfo.IsInvalid)
{
YooLogger.Error($"Failed to get raw file. {assetInfo.Error}");
RawFileOperation operation = new CompletedRawFileOperation(assetInfo.Error, copyPath);
OperationSystem.StartOperation(operation);
return operation;
}
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
#if UNITY_EDITOR
if (bundleInfo.Bundle.IsRawFile == false)
if (assetInfo.IsInvalid == false)
{
string error = $"Cannot load asset bundle file using {nameof(GetRawFileAsync)} method !";
YooLogger.Error(error);
RawFileOperation operation = new CompletedRawFileOperation(error, copyPath);
OperationSystem.StartOperation(operation);
return operation;
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.Bundle.IsRawFile == false)
throw new Exception($"Cannot load asset bundle file using {nameof(LoadRawFileAsync)} method !");
}
#endif
if (_playMode == EPlayMode.EditorSimulateMode)
{
RawFileOperation operation = new EditorPlayModeRawFileOperation(bundleInfo, copyPath);
OperationSystem.StartOperation(operation);
return operation;
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
RawFileOperation operation = new OfflinePlayModeRawFileOperation(bundleInfo, copyPath);
OperationSystem.StartOperation(operation);
return operation;
}
else if (_playMode == EPlayMode.HostPlayMode)
{
RawFileOperation operation = new HostPlayModeRawFileOperation(bundleInfo, copyPath);
OperationSystem.StartOperation(operation);
return operation;
}
else
{
throw new NotImplementedException();
}
var handle = _assetSystemImpl.LoadRawFileAsync(assetInfo);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
}
#endregion
@@ -581,13 +581,7 @@ namespace YooAsset
{
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.Bundle.IsRawFile)
{
string error = $"Cannot load raw file using LoadAsset method !";
YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(error);
return completedProvider.CreateHandle<AssetOperationHandle>();
}
throw new Exception($"Cannot load raw file using {nameof(LoadAssetAsync)} method !");
}
#endif
@@ -676,13 +670,7 @@ namespace YooAsset
{
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.Bundle.IsRawFile)
{
string error = $"Cannot load raw file using LoadSubAssets method !";
YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(error);
return completedProvider.CreateHandle<SubAssetsOperationHandle>();
}
throw new Exception($"Cannot load raw file using {nameof(LoadSubAssetsAsync)} method !");
}
#endif
@@ -899,24 +887,24 @@ namespace YooAsset
/// </summary>
/// <param name="packageVersion">指定更新的包裹版本</param>
/// <param name="timeout">超时时间</param>
public UpdatePackageOperation UpdatePackageAsync(string packageVersion, int timeout = 60)
public DownloadPackageOperation DownloadPackageAsync(string packageVersion, int timeout = 60)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorSimulateMode)
{
var operation = new EditorPlayModeUpdatePackageOperation();
var operation = new EditorPlayModeDownloadPackageOperation();
OperationSystem.StartOperation(operation);
return operation;
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
var operation = new OfflinePlayModeUpdatePackageOperation();
var operation = new OfflinePlayModeDownloadPackageOperation();
OperationSystem.StartOperation(operation);
return operation;
}
else if (_playMode == EPlayMode.HostPlayMode)
{
return _hostPlayModeImpl.UpdatePackageAsync(PackageName, packageVersion, timeout);
return _hostPlayModeImpl.DownloadPackageAsync(PackageName, packageVersion, timeout);
}
else
{
@@ -972,7 +960,7 @@ namespace YooAsset
var loadedBundleInfos = _assetSystemImpl.GetLoadedBundleInfos();
if (loadedBundleInfos.Count > 0)
{
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(ForceUnloadAllAssets)} method to release loaded bundle !");
YooLogger.Error($"Found loaded bundle before update manifest ! Recommended to call the {nameof(ForceUnloadAllAssets)} method to release loaded bundle !");
}
}
#endregion

View File

@@ -2,7 +2,6 @@
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
{
@@ -30,8 +29,8 @@ namespace YooAsset
/// </summary>
public static bool IsCached(PatchBundle patchBundle)
{
string fileHash = patchBundle.FileHash;
if (_cachedDic.ContainsKey(fileHash))
string cacheKey = patchBundle.CacheKey;
if (_cachedDic.ContainsKey(cacheKey))
{
string filePath = patchBundle.CachedFilePath;
if (File.Exists(filePath))
@@ -40,7 +39,7 @@ namespace YooAsset
}
else
{
_cachedDic.Remove(fileHash);
_cachedDic.Remove(cacheKey);
YooLogger.Error($"Cache file is missing : {filePath}");
return false;
}
@@ -56,12 +55,12 @@ namespace YooAsset
/// </summary>
public static void CacheBundle(PatchBundle patchBundle)
{
string fileHash = patchBundle.FileHash;
if (_cachedDic.ContainsKey(fileHash) == false)
string cacheKey = patchBundle.CacheKey;
if (_cachedDic.ContainsKey(cacheKey) == false)
{
string filePath = patchBundle.CachedFilePath;
YooLogger.Log($"Cache verify file : {filePath}");
_cachedDic.Add(fileHash, patchBundle);
_cachedDic.Add(cacheKey, patchBundle);
}
}

View File

@@ -5,9 +5,9 @@ using System.IO;
namespace YooAsset
{
/// <summary>
/// 清理未使用的缓存资源操作类
/// 清理本地包裹未使用的缓存文件
/// </summary>
public sealed class ClearUnusedCacheFilesOperation : AsyncOperationBase
public sealed class ClearPackageUnusedCacheFilesOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -17,14 +17,14 @@ namespace YooAsset
Done,
}
private readonly List<AssetsPackage> _packages;
private readonly AssetsPackage _package;
private ESteps _steps = ESteps.None;
private List<string> _unusedCacheFilePaths;
private int _unusedFileTotalCount = 0;
internal ClearUnusedCacheFilesOperation(List<AssetsPackage> packages)
internal ClearPackageUnusedCacheFilesOperation(AssetsPackage package)
{
_packages = packages;
_package = package;
}
internal override void Start()
{
@@ -84,27 +84,19 @@ namespace YooAsset
/// </summary>
private List<string> GetUnusedCacheFilePaths()
{
string cacheFolderPath = PersistentHelper.GetCacheFolderPath();
string cacheFolderPath = PersistentHelper.GetCacheFolderPath(_package.PackageName);
if (Directory.Exists(cacheFolderPath) == false)
return new List<string>();
// 获取所有缓存文件
DirectoryInfo directoryInfo = new DirectoryInfo(cacheFolderPath);
FileInfo[] fileInfos = directoryInfo.GetFiles();
List<string> result = new List<string>(fileInfos.Length);
foreach (FileInfo fileInfo in fileInfos)
{
bool used = false;
foreach (var package in _packages)
if (_package.IsIncludeBundleFile(fileInfo.Name) == false)
{
if (package.IsIncludeBundleFile(fileInfo.Name))
{
used = true;
break;
}
}
if (used == false)
result.Add(fileInfo.FullName);
}
}
return result;
}

View File

@@ -5,7 +5,7 @@ using System.IO;
namespace YooAsset
{
public abstract class UpdatePackageOperation : AsyncOperationBase
public abstract class DownloadPackageOperation : AsyncOperationBase
{
/// <summary>
/// 创建包裹下载器
@@ -19,7 +19,7 @@ namespace YooAsset
/// <summary>
/// 编辑器下模拟运行的更新资源包裹操作
/// </summary>
internal sealed class EditorPlayModeUpdatePackageOperation : UpdatePackageOperation
internal sealed class EditorPlayModeDownloadPackageOperation : DownloadPackageOperation
{
internal override void Start()
{
@@ -43,7 +43,7 @@ namespace YooAsset
/// <summary>
/// 离线模式的更新资源包裹操作
/// </summary>
internal sealed class OfflinePlayModeUpdatePackageOperation : UpdatePackageOperation
internal sealed class OfflinePlayModeDownloadPackageOperation : DownloadPackageOperation
{
internal override void Start()
{
@@ -67,7 +67,7 @@ namespace YooAsset
/// <summary>
/// 联机模式的更新资源包裹操作
/// </summary>
internal sealed class HostPlayModeUpdatePackageOperation : UpdatePackageOperation
internal sealed class HostPlayModeDownloadPackageOperation : DownloadPackageOperation
{
private enum ESteps
{
@@ -86,7 +86,7 @@ namespace YooAsset
private UnityWebDataRequester _downloader;
private PatchManifest _remotePatchManifest;
internal HostPlayModeUpdatePackageOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
internal HostPlayModeDownloadPackageOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
{
_impl = impl;
_packageName = packageName;
@@ -153,13 +153,14 @@ namespace YooAsset
{
if (Status == EOperationStatus.Succeed)
{
YooLogger.Log($"Create package downloader : {_remotePatchManifest.PackageName} {_remotePatchManifest.PackageVersion}");
List<BundleInfo> downloadList = GetDownloadList();
var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
else
{
YooLogger.Error($"{nameof(UpdatePackageOperation)} status is failed !");
YooLogger.Error($"{nameof(DownloadPackageOperation)} status is failed !");
var operation = new PackageDownloaderOperation(null, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}

View File

@@ -226,6 +226,19 @@ namespace YooAsset
{
_isPause = false;
}
/// <summary>
/// 取消下载
/// </summary>
public void CancelDownload()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "User cancel.";
}
}
}
public sealed class PackageDownloaderOperation : DownloaderOperation

View File

@@ -6,9 +6,9 @@ using System.IO;
namespace YooAsset
{
/// <summary>
/// 更新清单操作
/// 向远端请求并更新补丁清单
/// </summary>
public abstract class UpdateManifestOperation : AsyncOperationBase
public abstract class UpdatePackageManifestOperation : AsyncOperationBase
{
/// <summary>
/// 是否发现了新的补丁清单
@@ -19,7 +19,7 @@ namespace YooAsset
/// <summary>
/// 编辑器下模拟运行的更新清单操作
/// </summary>
internal sealed class EditorPlayModeUpdateManifestOperation : UpdateManifestOperation
internal sealed class EditorPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
{
internal override void Start()
{
@@ -33,7 +33,7 @@ namespace YooAsset
/// <summary>
/// 离线模式的更新清单操作
/// </summary>
internal sealed class OfflinePlayModeUpdateManifestOperation : UpdateManifestOperation
internal sealed class OfflinePlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
{
internal override void Start()
{
@@ -48,7 +48,7 @@ namespace YooAsset
/// 联机模式的更新清单操作
/// 注意:优先比对沙盒清单哈希值,如果有变化就更新远端清单文件,并保存到本地。
/// </summary>
internal sealed class HostPlayModeUpdateManifestOperation : UpdateManifestOperation
internal sealed class HostPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
{
private enum ESteps
{
@@ -77,7 +77,7 @@ namespace YooAsset
private ESteps _steps = ESteps.None;
private float _verifyTime;
internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
{
_impl = impl;
_packageName = packageName;

View File

@@ -5,9 +5,9 @@ using UnityEngine;
namespace YooAsset
{
/// <summary>
/// 获取包裹的最新版本
/// 请求远端包裹的最新版本
/// </summary>
public abstract class UpdateStaticVersionOperation : AsyncOperationBase
public abstract class UpdatePackageVersionOperation : AsyncOperationBase
{
/// <summary>
/// 当前最新的包裹版本
@@ -16,9 +16,9 @@ namespace YooAsset
}
/// <summary>
/// 编辑器下模拟运行的获取包裹的最新版本操作
/// 编辑器下模拟模式的请求远端包裹的最新版本
/// </summary>
internal sealed class EditorPlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
internal sealed class EditorPlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
{
internal override void Start()
{
@@ -30,9 +30,9 @@ namespace YooAsset
}
/// <summary>
/// 离线模式的获取包裹的最新版本操作
/// 离线模式的请求远端包裹的最新版本
/// </summary>
internal sealed class OfflinePlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
internal sealed class OfflinePlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
{
internal override void Start()
{
@@ -44,9 +44,9 @@ namespace YooAsset
}
/// <summary>
/// 联机模式的获取包裹的最新版本操作
/// 联机模式的请求远端包裹的最新版本
/// </summary>
internal sealed class HostPlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
internal sealed class HostPlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
{
private enum ESteps
{
@@ -63,7 +63,7 @@ namespace YooAsset
private ESteps _steps = ESteps.None;
private UnityWebDataRequester _downloader;
internal HostPlayModeUpdateStaticVersionOperation(HostPlayModeImpl impl, string packageName, int timeout)
internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, string packageName, int timeout)
{
_impl = impl;
_packageName = packageName;

View File

@@ -41,10 +41,11 @@ namespace YooAsset
/// </summary>
public string[] Tags;
/// <summary>
/// 文件名称
/// </summary>
public string FileName { private set; get; }
/// 所属的包裹名称
/// </summary>
private string _packageName;
/// <summary>
/// 缓存文件路径
@@ -57,7 +58,7 @@ namespace YooAsset
if (string.IsNullOrEmpty(_cachedFilePath) == false)
return _cachedFilePath;
string cacheRoot = PersistentHelper.GetCacheFolderPath();
string cacheRoot = PersistentHelper.GetCacheFolderPath(_packageName);
_cachedFilePath = $"{cacheRoot}/{FileName}";
return _cachedFilePath;
}
@@ -79,6 +80,34 @@ namespace YooAsset
}
}
/// <summary>
/// 文件名称
/// </summary>
private string _fileName;
public string FileName
{
get
{
if (string.IsNullOrEmpty(_fileName))
throw new Exception("Should never get here !");
return _fileName;
}
}
/// <summary>
/// 缓存查询Key
/// </summary>
private string _cacheKey;
public string CacheKey
{
get
{
if (string.IsNullOrEmpty(_cacheKey))
throw new Exception("Should never get here !");
return _cacheKey;
}
}
public PatchBundle(string bundleName, string fileHash, string fileCRC, long fileSize, bool isRawFile, byte loadMethod, string[] tags)
{
@@ -92,11 +121,13 @@ namespace YooAsset
}
/// <summary>
/// 解析文件名称
/// 解析资源包
/// </summary>
public void ParseFileName(int nameStype)
public void ParseBundle(string packageName, int nameStype)
{
FileName = PatchManifest.CreateBundleFileName(nameStype, BundleName, FileHash);
_packageName = packageName;
_cacheKey = $"{packageName}-{FileHash}";
_fileName = PatchManifest.CreateBundleFileName(nameStype, BundleName, FileHash);
}
/// <summary>

View File

@@ -290,7 +290,7 @@ namespace YooAsset
// BundleList
foreach (var patchBundle in patchManifest.BundleList)
{
patchBundle.ParseFileName(patchManifest.OutputNameStyle);
patchBundle.ParseBundle(patchManifest.PackageName, patchManifest.OutputNameStyle);
patchManifest.BundleDic.Add(patchBundle.BundleName, patchBundle);
}

View File

@@ -44,9 +44,9 @@ namespace YooAsset
/// <summary>
/// 异步更新资源版本号
/// </summary>
public UpdateStaticVersionOperation UpdateStaticVersionAsync(string packageName, int timeout)
public UpdatePackageVersionOperation UpdatePackageVersionAsync(string packageName, int timeout)
{
var operation = new HostPlayModeUpdateStaticVersionOperation(this, packageName, timeout);
var operation = new HostPlayModeUpdatePackageVersionOperation(this, packageName, timeout);
OperationSystem.StartOperation(operation);
return operation;
}
@@ -54,9 +54,9 @@ namespace YooAsset
/// <summary>
/// 异步更新补丁清单
/// </summary>
public UpdateManifestOperation UpdatePatchManifestAsync(string packageName, string packageVersion, int timeout)
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageName, string packageVersion, int timeout)
{
var operation = new HostPlayModeUpdateManifestOperation(this, packageName, packageVersion, timeout);
var operation = new HostPlayModeUpdatePackageManifestOperation(this, packageName, packageVersion, timeout);
OperationSystem.StartOperation(operation);
return operation;
}
@@ -74,9 +74,9 @@ namespace YooAsset
/// <summary>
/// 异步更新资源包裹
/// </summary>
public UpdatePackageOperation UpdatePackageAsync(string packageName, string packageVersion, int timeout)
public DownloadPackageOperation DownloadPackageAsync(string packageName, string packageVersion, int timeout)
{
var operation = new HostPlayModeUpdatePackageOperation(this, packageName, packageVersion, timeout);
var operation = new HostPlayModeDownloadPackageOperation(this, packageName, packageVersion, timeout);
OperationSystem.StartOperation(operation);
return operation;
}
@@ -86,6 +86,7 @@ namespace YooAsset
/// </summary>
public PatchDownloaderOperation CreatePatchDownloaderByAll(int fileLoadingMaxNumber, int failedTryAgain, int timeout)
{
YooLogger.Log($"Create patch downloader : {LocalPatchManifest.PackageName} {LocalPatchManifest.PackageVersion}");
List<BundleInfo> downloadList = GetDownloadListByAll();
var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain, timeout);
return operation;
@@ -114,6 +115,7 @@ namespace YooAsset
/// </summary>
public PatchDownloaderOperation CreatePatchDownloaderByTags(string[] tags, int fileLoadingMaxNumber, int failedTryAgain, int timeout)
{
YooLogger.Log($"Create patch downloader : {LocalPatchManifest.PackageName} {LocalPatchManifest.PackageVersion}");
List<BundleInfo> downloadList = GetDownloadListByTags(tags);
var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain, timeout);
return operation;
@@ -154,6 +156,7 @@ namespace YooAsset
/// </summary>
public PatchDownloaderOperation CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int fileLoadingMaxNumber, int failedTryAgain, int timeout)
{
YooLogger.Log($"Create patch downloader : {LocalPatchManifest.PackageName} {LocalPatchManifest.PackageVersion}");
List<BundleInfo> downloadList = GetDownloadListByPaths(assetInfos);
var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain, timeout);
return operation;
@@ -206,6 +209,7 @@ namespace YooAsset
/// </summary>
public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain, int timeout)
{
YooLogger.Log($"Create patch unpacker : {LocalPatchManifest.PackageName} {LocalPatchManifest.PackageVersion}");
List<BundleInfo> unpcakList = GetUnpackListByTags(tags);
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain, timeout);
return operation;
@@ -237,6 +241,7 @@ namespace YooAsset
/// </summary>
public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain, int timeout)
{
YooLogger.Log($"Create patch unpacker : {LocalPatchManifest.PackageName} {LocalPatchManifest.PackageVersion}");
List<BundleInfo> unpcakList = GetUnpackListByAll();
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain, timeout);
return operation;

View File

@@ -97,17 +97,18 @@ namespace YooAsset
/// </summary>
public static void DeleteCacheFolder()
{
string directoryPath = GetCacheFolderPath();
if (Directory.Exists(directoryPath))
Directory.Delete(directoryPath, true);
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
if (Directory.Exists(root))
Directory.Delete(root, true);
}
/// <summary>
/// 获取缓存文件夹路径
/// </summary>
public static string GetCacheFolderPath()
public static string GetCacheFolderPath(string packageName)
{
return PathHelper.MakePersistentLoadPath(CacheFolderName);
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
return $"{root}/{packageName}";
}
#region

View File

@@ -193,16 +193,6 @@ namespace YooAsset
#endregion
#region
/// <summary>
/// 清理未使用的缓存文件
/// </summary>
public static ClearUnusedCacheFilesOperation ClearUnusedCacheFiles()
{
ClearUnusedCacheFilesOperation operation = new ClearUnusedCacheFilesOperation(_packages);
OperationSystem.StartOperation(operation);
return operation;
}
/// <summary>
/// 获取内置文件夹名称
/// </summary>

View File

@@ -82,25 +82,43 @@ namespace YooAsset
#region
/// <summary>
/// 异步获取原生文件
/// 同步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="copyPath">拷贝路径</param>
public static RawFileOperation GetRawFileAsync(string location, string copyPath = null)
/// <param name="assetInfo">资源信息</param>
public static RawFileOperationHandle LoadRawFileSync(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetRawFileAsync(location, copyPath);
return _defaultPackage.LoadRawFileSync(assetInfo);
}
/// <summary>
/// 异步获取原生文件
/// 同步加载原生文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
/// <param name="copyPath">拷贝路径</param>
public static RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null)
/// <param name="location">资源的定位地址</param>
public static RawFileOperationHandle LoadRawFileSync(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetRawFileAsync(assetInfo, copyPath);
return _defaultPackage.LoadRawFileSync(location);
}
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static RawFileOperationHandle LoadRawFileAsync(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileAsync(assetInfo);
}
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
public static RawFileOperationHandle LoadRawFileAsync(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileAsync(location);
}
#endregion
@@ -367,14 +385,14 @@ namespace YooAsset
#region
/// <summary>
/// 创建资源包裹下载器,用于下载更新指定资源版本所有的资源包文件
/// 资源包裹更新,用于下载更新指定资源版本所有的资源包文件
/// </summary>
/// <param name="packageVersion">指定更新的包裹版本</param>
/// <param name="timeout">超时时间</param>
public static UpdatePackageOperation UpdatePackageAsync(string packageVersion, int timeout = 60)
public static DownloadPackageOperation DownloadPackageAsync(string packageVersion, int timeout = 60)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.UpdatePackageAsync(packageVersion, timeout);
return _defaultPackage.DownloadPackageAsync(packageVersion, timeout);
}
#endregion

View File

@@ -12,6 +12,7 @@ public class GameScene1 : MonoBehaviour
private readonly List<AssetOperationHandle> _cachedAssetOperationHandles = new List<AssetOperationHandle>(1000);
private readonly List<SubAssetsOperationHandle> _cachedSubAssetsOperationHandles = new List<SubAssetsOperationHandle>(1000);
private readonly List<RawFileOperationHandle> _cachedRawFileOperationHandles = new List<RawFileOperationHandle>(1000);
private int _npcIndex = 0;
void Start()
@@ -22,8 +23,8 @@ public class GameScene1 : MonoBehaviour
// 初始化窗口
InitWindow();
// 异步加载背景音乐
AsyncLoadMusic();
// 加载背景音乐
LoadMusic();
}
void OnDestroy()
{
@@ -38,6 +39,12 @@ public class GameScene1 : MonoBehaviour
handle.Release();
}
_cachedSubAssetsOperationHandles.Clear();
foreach(var handle in _cachedRawFileOperationHandles)
{
handle.Release();
}
_cachedRawFileOperationHandles.Clear();
}
void OnGUI()
{
@@ -176,9 +183,9 @@ public class GameScene1 : MonoBehaviour
var btn = CanvasRoot.transform.Find("load_rawfile/btn").GetComponent<Button>();
btn.onClick.AddListener(() =>
{
string savePath = $"{YooAssets.GetSandboxRoot()}/config1.txt";
RawFileOperation operation = YooAssets.GetRawFileAsync("config1", savePath);
operation.Completed += OnRawFile_Completed;
RawFileOperationHandle handle = YooAssets.LoadRawFileSync("config1");
_cachedRawFileOperationHandles.Add(handle);
handle.Completed += OnRawFile_Completed;
});
}
@@ -195,6 +202,7 @@ public class GameScene1 : MonoBehaviour
{
var handle = YooAssets.LoadAssetSync<GameObject>("ui_window");
handle.InstantiateSync(CanvasRoot.transform);
_cachedAssetOperationHandles.Add(handle);
}
}
@@ -208,24 +216,23 @@ public class GameScene1 : MonoBehaviour
var icon = CanvasRoot.transform.Find("load_tp_atlas/icon").GetComponent<Image>();
icon.sprite = handle.GetSubAssetObject<Sprite>("Icon_Shield_128");
}
private void OnRawFile_Completed(AsyncOperationBase operation)
private void OnRawFile_Completed(RawFileOperationHandle handle)
{
var hint = CanvasRoot.transform.Find("load_rawfile/icon/hint").GetComponent<Text>();
RawFileOperation op = operation as RawFileOperation;
hint.text = op.LoadFileText();
hint.text = handle.GetRawFileText();
}
/// <summary>
/// 异步加载背景音乐
/// </summary>
async void AsyncLoadMusic()
void LoadMusic()
{
// 加载背景音乐
{
var audioSource = CanvasRoot.transform.Find("music").GetComponent<AudioSource>();
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("music_town");
AssetOperationHandle handle = YooAssets.LoadAssetSync<AudioClip>("music_town");
_cachedAssetOperationHandles.Add(handle);
await handle.Task;
//await handle.Task;
audioSource.clip = handle.AssetObject as AudioClip;
audioSource.Play();
}

View File

@@ -9,7 +9,8 @@ internal class FsmClearCache : IFsmNode
void IFsmNode.OnEnter()
{
Debug.Log("清理未使用的缓存文件!");
var operation = YooAsset.YooAssets.ClearUnusedCacheFiles();
var package = YooAsset.YooAssets.GetAssetsPackage("DefaultPackage");
var operation = package.ClearPackageUnusedCacheFilesAsync();
operation.Completed += Operation_Completed;
}

View File

@@ -25,7 +25,7 @@ public class FsmUpdateManifest : IFsmNode
// 更新补丁清单
var package = YooAssets.GetAssetsPackage("DefaultPackage");
var operation = package.UpdateManifestAsync(PatchUpdater.PackageVersion, 30);
var operation = package.UpdatePackageManifestAsync(PatchUpdater.PackageVersion, 30);
yield return operation;
if(operation.Status == EOperationStatus.Succeed)

View File

@@ -25,7 +25,7 @@ internal class FsmUpdateStaticVersion : IFsmNode
// 更新资源版本号
var package = YooAssets.GetAssetsPackage("DefaultPackage");
var operation = package.UpdateStaticVersionAsync(30);
var operation = package.UpdatePackageVersionAsync(30);
yield return operation;
if (operation.Status == EOperationStatus.Succeed)

View File

@@ -1,7 +1,7 @@
{
"name": "com.tuyoogame.yooasset",
"displayName": "YooAsset",
"version": "1.3.4",
"version": "1.3.5",
"unity": "2019.4",
"description": "unity3d resources management system.",
"author": {

View File

@@ -21,6 +21,10 @@ YooAsset依赖于ScriptBuildPipelineSBP在PackageManager里找到SBP插
把传输类型修改为二进制就可以了。
#### 问题打包的时候报错Cannot mark assets and scenes in one AssetBundle. AssetBundle name is "assets_xxxx_scenes.bundle
Unity引擎不允许把场景文件和其它资源文件一起打包。
#### 问题ClearCacheWhenDirty参数没了吗
不是很必须的一个功能,已经移除了。可以使用以下方法代替:

View File

@@ -8,7 +8,31 @@
它可以满足商业化游戏的各类需求并且经历多款百万DAU游戏产品的验证。
## 介绍
YooAsset可以满足以下任何需求
- 我想发布一个不包含任何游戏资源的安装包,然后玩家边玩边下载。
- 我想发布一个可以保证前期体验的安装包,然后玩家自己选择下载关卡内容。
- 我想发布一个保证300MB以下内容的安装包然后进入游戏之前把剩余内容下载完毕。
- 我想发布一个偏单机的游戏安装包,在网络畅通的时候,支持正常更新。在没有网络的时候,支持游玩老版本。
- 我想发布一个MOD游戏安装包玩家可以把自己制作的MOD内容上传到服务器其它玩家可以下载游玩。
- 我们在制作一个超大体量的项目有上百GB的资源内容每次构建都花费大量时间是否可以分工程构建
## 系统特点
- **构建管线无缝切换**
支持传统的内置构建管线也支持可编程构建管线SBP
- **支持分布式构建**
支持分工程构建支持工程里分内容构建很方便支持游戏模组MOD
- **支持可寻址资源定位**
默认支持相对路径的资源定位,也支持可寻址资源定位,不需要繁琐的过程即可高效的配置寻址路径。
- **安全高效的分包方案**
基于资源标签的分包方案,自动对依赖资源包进行分类,避免人工维护成本。可以非常方便的实现零资源安装包,或者全量资源安装包。
@@ -40,14 +64,6 @@
- **灵活多变的版本管理**
支持线上版本快速回退,支持区分审核版本,测试版本,线上版本,支持灰度更新及测试。
- **可寻址资源定位**
默认支持相对路径的资源定位,也支持可寻址资源定位,不需要繁琐的过程即可高效的配置寻址路径。
- **构建管线无缝切换**
支持传统的内置构建管线也支持可编程构建管线SBP
## 入门教程
1. [快速开始](./Docs/QuickStart.md)