mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-15 20:20:08 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0311d976bb | ||
|
|
120c07cc2e | ||
|
|
ed5ae40cb3 | ||
|
|
5931d91b5f | ||
|
|
472a5ae97a | ||
|
|
829ea66d0e | ||
|
|
ba39291ee7 |
@@ -2,6 +2,33 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [1.5.1] - 2023-07-12
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了太空战机DEMO在生成内置文件清单的时候,目录不存在引发的异常。
|
||||
- 修复了在销毁Package时,如果存在正在加载的bundle,会导致后续加载该bundle报错的问题。
|
||||
|
||||
### Changed
|
||||
|
||||
- 真机上使用错误方法加载原生文件的时候给予正确的错误提示。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了HostPlayModeParameters.RemoteServices字段
|
||||
|
||||
```c#
|
||||
/// <summary>
|
||||
/// 远端资源地址查询服务类
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices = null;
|
||||
```
|
||||
|
||||
### Removed
|
||||
|
||||
- 移除了HostPlayModeParameters.DefaultHostServer字段
|
||||
- 移除了HostPlayModeParameters.FallbackHostServer字段
|
||||
|
||||
## [1.5.0] - 2023-07-05
|
||||
|
||||
该版本重构了Persistent类,导致沙盒目录和内置目录的存储结构发生了变化。
|
||||
|
||||
@@ -79,30 +79,6 @@ namespace YooAsset
|
||||
_isUnloadSafe = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁
|
||||
/// </summary>
|
||||
public void DestroyAll()
|
||||
{
|
||||
foreach (var provider in _providerList)
|
||||
{
|
||||
provider.Destroy();
|
||||
}
|
||||
_providerList.Clear();
|
||||
_providerDic.Clear();
|
||||
|
||||
foreach (var loader in _loaderList)
|
||||
{
|
||||
loader.Destroy(true);
|
||||
}
|
||||
_loaderList.Clear();
|
||||
_loaderDic.Clear();
|
||||
|
||||
ClearSceneHandle();
|
||||
DecryptionServices = null;
|
||||
BundleServices = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源回收(卸载引用计数为零的资源)
|
||||
/// </summary>
|
||||
@@ -149,10 +125,12 @@ namespace YooAsset
|
||||
{
|
||||
foreach (var provider in _providerList)
|
||||
{
|
||||
provider.WaitForAsyncComplete();
|
||||
provider.Destroy();
|
||||
}
|
||||
foreach (var loader in _loaderList)
|
||||
{
|
||||
loader.WaitForAsyncComplete();
|
||||
loader.Destroy(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,9 +73,7 @@ namespace YooAsset
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
string filePath = Provider.RawFilePath;
|
||||
if (File.Exists(filePath) == false)
|
||||
return null;
|
||||
return File.ReadAllBytes(filePath);
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -53,6 +53,12 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.CacheBundle == null)
|
||||
{
|
||||
ProcessCacheBundleException();
|
||||
return;
|
||||
}
|
||||
|
||||
Status = EStatus.Loading;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,12 +55,7 @@ namespace YooAsset
|
||||
|
||||
if (OwnerBundle.CacheBundle == null)
|
||||
{
|
||||
if (OwnerBundle.IsDestroyed)
|
||||
throw new System.Exception("Should never get here !");
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"The bundle {OwnerBundle.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
ProcessCacheBundleException();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,12 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.CacheBundle == null)
|
||||
{
|
||||
ProcessCacheBundleException();
|
||||
return;
|
||||
}
|
||||
|
||||
Status = EStatus.Loading;
|
||||
}
|
||||
|
||||
|
||||
@@ -220,6 +220,30 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理特殊异常
|
||||
/// </summary>
|
||||
protected void ProcessCacheBundleException()
|
||||
{
|
||||
if (OwnerBundle.IsDestroyed)
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
if (OwnerBundle.MainBundleInfo.Bundle.IsRawFile)
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Cannot load asset bundle file using {nameof(ResourcePackage.LoadRawFileAsync)} method !";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"The bundle {OwnerBundle.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步操作任务
|
||||
/// </summary>
|
||||
|
||||
@@ -80,19 +80,14 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public class HostPlayModeParameters : InitializeParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认的资源服务器下载地址
|
||||
/// </summary>
|
||||
public string DefaultHostServer = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 备用的资源服务器下载地址
|
||||
/// </summary>
|
||||
public string FallbackHostServer = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源查询服务接口
|
||||
/// </summary>
|
||||
public IQueryServices QueryServices = null;
|
||||
|
||||
/// <summary>
|
||||
/// 远端资源地址查询服务类
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices = null;
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloadManifestOp == null)
|
||||
{
|
||||
_downloadManifestOp = new DownloadManifestOperation(_impl, _packageName, _packageVersion, _timeout);
|
||||
_downloadManifestOp = new DownloadManifestOperation(_impl.RemoteServices, _packageName, _packageVersion, _timeout);
|
||||
OperationSystem.StartOperation(_downloadManifestOp);
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloadManifestOp == null)
|
||||
{
|
||||
_downloadManifestOp = new DownloadManifestOperation(_impl, _packageName, _packageVersion, _timeout);
|
||||
_downloadManifestOp = new DownloadManifestOperation(_impl.RemoteServices, _packageName, _packageVersion, _timeout);
|
||||
OperationSystem.StartOperation(_downloadManifestOp);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_queryRemotePackageVersionOp == null)
|
||||
{
|
||||
_queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl, _packageName, _appendTimeTicks, _timeout);
|
||||
_queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl.RemoteServices, _packageName, _appendTimeTicks, _timeout);
|
||||
OperationSystem.StartOperation(_queryRemotePackageVersionOp);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,25 +4,28 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class HostPlayModeImpl : IPlayModeServices, IBundleServices, IRemoteServices
|
||||
internal class HostPlayModeImpl : IPlayModeServices, IBundleServices
|
||||
{
|
||||
private PackageManifest _activeManifest;
|
||||
|
||||
// 参数相关
|
||||
private string _packageName;
|
||||
private string _defaultHostServer;
|
||||
private string _fallbackHostServer;
|
||||
private IQueryServices _queryServices;
|
||||
private IRemoteServices _remoteServices;
|
||||
|
||||
public IRemoteServices RemoteServices
|
||||
{
|
||||
get { return _remoteServices; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(string packageName, string defaultHostServer, string fallbackHostServer, IQueryServices queryServices)
|
||||
public InitializationOperation InitializeAsync(string packageName, IQueryServices queryServices, IRemoteServices remoteServices)
|
||||
{
|
||||
_packageName = packageName;
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
_queryServices = queryServices;
|
||||
_remoteServices = remoteServices;
|
||||
|
||||
var operation = new HostPlayModeInitializationOperation(this, packageName);
|
||||
OperationSystem.StartOperation(operation);
|
||||
@@ -42,23 +45,12 @@ namespace YooAsset
|
||||
}
|
||||
private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle)
|
||||
{
|
||||
string remoteMainURL = GetRemoteMainURL(packageBundle.FileName);
|
||||
string remoteFallbackURL = GetRemoteFallbackURL(packageBundle.FileName);
|
||||
string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName);
|
||||
string remoteFallbackURL = _remoteServices.GetRemoteFallbackURL(packageBundle.FileName);
|
||||
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
#region IRemoteServices接口
|
||||
public string GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_defaultHostServer}/{fileName}";
|
||||
}
|
||||
public string GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_fallbackHostServer}/{fileName}";
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IPlayModeServices接口
|
||||
public PackageManifest ActiveManifest
|
||||
{
|
||||
@@ -76,7 +68,7 @@ namespace YooAsset
|
||||
if (_activeManifest != null)
|
||||
{
|
||||
PersistentTools.GetPersistent(_packageName).SaveSandboxPackageVersionFile(_activeManifest.PackageVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace YooAsset
|
||||
|
||||
if (_assetSystemImpl != null)
|
||||
{
|
||||
_assetSystemImpl.DestroyAll();
|
||||
_assetSystemImpl.ForceUnloadAllAssets();
|
||||
_assetSystemImpl = null;
|
||||
}
|
||||
}
|
||||
@@ -122,9 +122,8 @@ namespace YooAsset
|
||||
var initializeParameters = parameters as HostPlayModeParameters;
|
||||
initializeOperation = hostPlayModeImpl.InitializeAsync(
|
||||
PackageName,
|
||||
initializeParameters.DefaultHostServer,
|
||||
initializeParameters.FallbackHostServer,
|
||||
initializeParameters.QueryServices
|
||||
initializeParameters.QueryServices,
|
||||
initializeParameters.RemoteServices
|
||||
);
|
||||
}
|
||||
else
|
||||
@@ -172,12 +171,10 @@ namespace YooAsset
|
||||
if (parameters is HostPlayModeParameters)
|
||||
{
|
||||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||
if (string.IsNullOrEmpty(hostPlayModeParameters.DefaultHostServer))
|
||||
throw new Exception($"${hostPlayModeParameters.DefaultHostServer} is null or empty.");
|
||||
if (string.IsNullOrEmpty(hostPlayModeParameters.FallbackHostServer))
|
||||
throw new Exception($"${hostPlayModeParameters.FallbackHostServer} is null or empty.");
|
||||
if (hostPlayModeParameters.QueryServices == null)
|
||||
throw new Exception($"{nameof(IQueryServices)} is null.");
|
||||
if (hostPlayModeParameters.RemoteServices == null)
|
||||
throw new Exception($"{nameof(IRemoteServices)} is null.");
|
||||
}
|
||||
|
||||
// 鉴定运行模式
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal interface IRemoteServices
|
||||
public interface IRemoteServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取主资源站的资源地址
|
||||
/// </summary>
|
||||
/// <param name="fileName">请求的文件名称</param>
|
||||
string GetRemoteMainURL(string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取备用资源站的资源地址
|
||||
/// </summary>
|
||||
/// <param name="fileName">请求的文件名称</param>
|
||||
string GetRemoteFallbackURL(string fileName);
|
||||
}
|
||||
}
|
||||
@@ -65,11 +65,12 @@ internal class FsmInitialize : IStateNode
|
||||
// 联机运行模式
|
||||
if (playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
string defaultHostServer = GetHostServerURL();
|
||||
string fallbackHostServer = GetHostServerURL();
|
||||
var createParameters = new HostPlayModeParameters();
|
||||
createParameters.DecryptionServices = new GameDecryptionServices();
|
||||
createParameters.QueryServices = new GameQueryServices();
|
||||
createParameters.DefaultHostServer = GetHostServerURL();
|
||||
createParameters.FallbackHostServer = GetHostServerURL();
|
||||
createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
@@ -115,6 +116,30 @@ internal class FsmInitialize : IStateNode
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 远端资源地址查询服务类
|
||||
/// </summary>
|
||||
private class RemoteServices : IRemoteServices
|
||||
{
|
||||
private readonly string _defaultHostServer;
|
||||
private readonly string _fallbackHostServer;
|
||||
|
||||
public RemoteServices(string defaultHostServer, string fallbackHostServer)
|
||||
{
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
}
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_defaultHostServer}/{fileName}";
|
||||
}
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_fallbackHostServer}/{fileName}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件解密服务类
|
||||
/// </summary>
|
||||
|
||||
@@ -51,9 +51,12 @@ public sealed class StreamingAssetsHelper
|
||||
{
|
||||
_isInit = true;
|
||||
var manifest = Resources.Load<BuildinFileManifest>("BuildinFileManifest");
|
||||
foreach (string fileName in manifest.BuildinFiles)
|
||||
if (manifest != null)
|
||||
{
|
||||
_cacheData.Add(fileName);
|
||||
foreach (string fileName in manifest.BuildinFiles)
|
||||
{
|
||||
_cacheData.Add(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,10 +84,19 @@ internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
/// </summary>
|
||||
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||
{
|
||||
var manifest = ScriptableObject.CreateInstance<BuildinFileManifest>();
|
||||
string saveFilePath = "Assets/Resources/BuildinFileManifest.asset";
|
||||
if (File.Exists(saveFilePath))
|
||||
File.Delete(saveFilePath);
|
||||
|
||||
string folderPath = $"{Application.dataPath}/StreamingAssets/{StreamingAssetsDefine.RootFolderName}";
|
||||
DirectoryInfo root = new DirectoryInfo(folderPath);
|
||||
if (root.Exists == false)
|
||||
{
|
||||
Debug.Log($"没有发现YooAsset内置目录 : {folderPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
var manifest = ScriptableObject.CreateInstance<BuildinFileManifest>();
|
||||
FileInfo[] files = root.GetFiles("*", SearchOption.AllDirectories);
|
||||
foreach (var fileInfo in files)
|
||||
{
|
||||
@@ -95,9 +107,6 @@ internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
manifest.BuildinFiles.Add(fileInfo.Name);
|
||||
}
|
||||
|
||||
string saveFilePath = "Assets/Resources/BuildinFileManifest.asset";
|
||||
if (File.Exists(saveFilePath))
|
||||
File.Delete(saveFilePath);
|
||||
if (Directory.Exists("Assets/Resources") == false)
|
||||
Directory.CreateDirectory("Assets/Resources");
|
||||
UnityEditor.AssetDatabase.CreateAsset(manifest, saveFilePath);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "1.5.0",
|
||||
"version": "1.5.1",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user