Compare commits

..

7 Commits

Author SHA1 Message Date
hevinci 191fbff768 update package system
增加对清单激活的检测
2023-07-19 18:18:03 +08:00
hevinci e8a4ddf331 update runtime code 2023-07-19 17:48:26 +08:00
hevinci aee6e2d2f8 update space shooter 2023-07-19 17:06:35 +08:00
hevinci b737b20602 update runtime code
支持开发者资源分发和加载
2023-07-19 17:06:20 +08:00
hevinci b5df539392 update package system
增加对UpdatePackageManifestOperation参数的检测
2023-07-19 15:57:34 +08:00
hevinci 36c53e5d94 update space shooter 2023-07-19 14:34:51 +08:00
hevinci 15ce6b8c8c update runtime code 2023-07-19 14:34:43 +08:00
13 changed files with 138 additions and 31 deletions

View File

@ -72,6 +72,11 @@ namespace YooAsset
_steps = ESteps.LoadFile; _steps = ESteps.LoadFile;
FileLoadPath = MainBundleInfo.Bundle.CachedDataFilePath; FileLoadPath = MainBundleInfo.Bundle.CachedDataFilePath;
} }
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromDelivery)
{
_steps = ESteps.LoadFile;
FileLoadPath = MainBundleInfo.DeliveryFilePath;
}
else else
{ {
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString()); throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());

View File

@ -54,6 +54,11 @@ namespace YooAsset
_steps = ESteps.CheckFile; _steps = ESteps.CheckFile;
FileLoadPath = MainBundleInfo.Bundle.CachedDataFilePath; FileLoadPath = MainBundleInfo.Bundle.CachedDataFilePath;
} }
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromDelivery)
{
_steps = ESteps.CheckFile;
FileLoadPath = MainBundleInfo.DeliveryFilePath;
}
else else
{ {
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString()); throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());

View File

@ -6,6 +6,7 @@ namespace YooAsset
public enum ELoadMode public enum ELoadMode
{ {
None, None,
LoadFromDelivery,
LoadFromStreaming, LoadFromStreaming,
LoadFromCache, LoadFromCache,
LoadFromRemote, LoadFromRemote,
@ -25,6 +26,11 @@ namespace YooAsset
/// </summary> /// </summary>
public string RemoteFallbackURL { private set; get; } public string RemoteFallbackURL { private set; get; }
/// <summary>
/// 开发者分发的文件地址
/// </summary>
public string DeliveryFilePath { private set; get; }
/// <summary> /// <summary>
/// 注意:该字段只用于帮助编辑器下的模拟模式。 /// 注意:该字段只用于帮助编辑器下的模拟模式。
/// </summary> /// </summary>
@ -40,6 +46,15 @@ namespace YooAsset
LoadMode = loadMode; LoadMode = loadMode;
RemoteMainURL = mainURL; RemoteMainURL = mainURL;
RemoteFallbackURL = fallbackURL; RemoteFallbackURL = fallbackURL;
DeliveryFilePath = string.Empty;
}
public BundleInfo(PackageBundle bundle, ELoadMode loadMode, string deliveryFilePath)
{
Bundle = bundle;
LoadMode = loadMode;
RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty;
DeliveryFilePath = deliveryFilePath;
} }
public BundleInfo(PackageBundle bundle, ELoadMode loadMode) public BundleInfo(PackageBundle bundle, ELoadMode loadMode)
{ {
@ -47,6 +62,7 @@ namespace YooAsset
LoadMode = loadMode; LoadMode = loadMode;
RemoteMainURL = string.Empty; RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty; RemoteFallbackURL = string.Empty;
DeliveryFilePath = string.Empty;
} }
/// <summary> /// <summary>

View File

@ -74,7 +74,7 @@ namespace YooAsset
string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion); string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
string webURL = GetDownloadRequestURL(fileName); string webURL = GetDownloadRequestURL(fileName);
YooLogger.Log($"Beginning to download manifest file : {webURL}"); YooLogger.Log($"Beginning to download package manifest file : {webURL}");
_downloader2 = new UnityWebFileRequester(); _downloader2 = new UnityWebFileRequester();
_downloader2.SendRequest(webURL, savePath, _timeout); _downloader2.SendRequest(webURL, savePath, _timeout);
} }

View File

@ -58,6 +58,7 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
CheckParams,
CheckActiveManifest, CheckActiveManifest,
TryLoadCacheManifest, TryLoadCacheManifest,
DownloadManifest, DownloadManifest,
@ -87,13 +88,34 @@ namespace YooAsset
} }
internal override void Start() internal override void Start()
{ {
_steps = ESteps.CheckActiveManifest; _steps = ESteps.CheckParams;
} }
internal override void Update() internal override void Update()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.CheckParams)
{
if (string.IsNullOrEmpty(_packageName))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Package name is null or empty.";
return;
}
if (string.IsNullOrEmpty(_packageVersion))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Package version is null or empty.";
return;
}
_steps = ESteps.CheckActiveManifest;
}
if (_steps == ESteps.CheckActiveManifest) if (_steps == ESteps.CheckActiveManifest)
{ {
// 检测当前激活的清单对象 // 检测当前激活的清单对象
@ -198,6 +220,7 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
CheckParams,
CheckActiveManifest, CheckActiveManifest,
LoadRemoteManifest, LoadRemoteManifest,
Done, Done,
@ -220,13 +243,34 @@ namespace YooAsset
} }
internal override void Start() internal override void Start()
{ {
_steps = ESteps.CheckActiveManifest; _steps = ESteps.CheckParams;
} }
internal override void Update() internal override void Update()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.CheckParams)
{
if (string.IsNullOrEmpty(_packageName))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Package name is null or empty.";
return;
}
if (string.IsNullOrEmpty(_packageVersion))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Package version is null or empty.";
return;
}
_steps = ESteps.CheckActiveManifest;
}
if (_steps == ESteps.CheckActiveManifest) if (_steps == ESteps.CheckActiveManifest)
{ {
// 检测当前激活的清单对象 // 检测当前激活的清单对象

View File

@ -51,6 +51,24 @@ namespace YooAsset
return bundleInfo; return bundleInfo;
} }
// 查询相关
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
}
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
}
private bool IsDeliveryPackageBundle(PackageBundle packageBundle, out string deliveryFilePath)
{
deliveryFilePath = _queryServices.QueryDeliveryFiles(_packageName, packageBundle.FileName);
if (string.IsNullOrEmpty(deliveryFilePath))
return false;
else
return true;
}
#region IPlayModeServices接口 #region IPlayModeServices接口
public PackageManifest ActiveManifest public PackageManifest ActiveManifest
{ {
@ -71,15 +89,6 @@ namespace YooAsset
} }
} }
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
}
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
}
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout) UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
{ {
var operation = new HostPlayModeUpdatePackageVersionOperation(this, _packageName, appendTimeTicks, timeout); var operation = new HostPlayModeUpdatePackageVersionOperation(this, _packageName, appendTimeTicks, timeout);
@ -269,6 +278,13 @@ namespace YooAsset
if (packageBundle == null) if (packageBundle == null)
throw new Exception("Should never get here !"); throw new Exception("Should never get here !");
// 查询分发资源
if (IsDeliveryPackageBundle(packageBundle, out string deliveryFilePath))
{
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromDelivery, deliveryFilePath);
return bundleInfo;
}
// 查询沙盒资源 // 查询沙盒资源
if (IsCachedPackageBundle(packageBundle)) if (IsCachedPackageBundle(packageBundle))
{ {

View File

@ -18,6 +18,12 @@ namespace YooAsset
return operation; return operation;
} }
// 查询相关
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
}
#region IPlayModeServices接口 #region IPlayModeServices接口
public PackageManifest ActiveManifest public PackageManifest ActiveManifest
{ {
@ -34,11 +40,6 @@ namespace YooAsset
{ {
} }
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
}
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout) UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
{ {
var operation = new OfflinePlayModeUpdatePackageVersionOperation(); var operation = new OfflinePlayModeUpdatePackageVersionOperation();

View File

@ -41,6 +41,12 @@ namespace YooAsset
return bundleInfo; return bundleInfo;
} }
// 查询相关
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
}
#region IPlayModeServices接口 #region IPlayModeServices接口
public PackageManifest ActiveManifest public PackageManifest ActiveManifest
{ {
@ -57,11 +63,6 @@ namespace YooAsset
{ {
} }
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
}
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout) UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
{ {
var operation = new WebPlayModeUpdatePackageVersionOperation(this, _packageName, appendTimeTicks, timeout); var operation = new WebPlayModeUpdatePackageVersionOperation(this, _packageName, appendTimeTicks, timeout);

View File

@ -238,7 +238,7 @@ namespace YooAsset
/// <param name="timeout">超时时间默认值60秒</param> /// <param name="timeout">超时时间默认值60秒</param>
public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = true, int timeout = 60) public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = true, int timeout = 60)
{ {
DebugCheckInitialize(); DebugCheckInitialize(false);
return _playModeServices.UpdatePackageVersionAsync(appendTimeTicks, timeout); return _playModeServices.UpdatePackageVersionAsync(appendTimeTicks, timeout);
} }
@ -250,7 +250,7 @@ namespace YooAsset
/// <param name="timeout">超时时间默认值60秒</param> /// <param name="timeout">超时时间默认值60秒</param>
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion = true, int timeout = 60) public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion = true, int timeout = 60)
{ {
DebugCheckInitialize(); DebugCheckInitialize(false);
DebugCheckUpdateManifest(); DebugCheckUpdateManifest();
return _playModeServices.UpdatePackageManifestAsync(packageVersion, autoSaveVersion, timeout); return _playModeServices.UpdatePackageManifestAsync(packageVersion, autoSaveVersion, timeout);
} }
@ -262,7 +262,7 @@ namespace YooAsset
/// <param name="timeout">超时时间默认值60秒</param> /// <param name="timeout">超时时间默认值60秒</param>
public PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout = 60) public PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout = 60)
{ {
DebugCheckInitialize(); DebugCheckInitialize(false);
return _playModeServices.PreDownloadContentAsync(packageVersion, timeout); return _playModeServices.PreDownloadContentAsync(packageVersion, timeout);
} }
@ -294,8 +294,6 @@ namespace YooAsset
public string GetPackageVersion() public string GetPackageVersion()
{ {
DebugCheckInitialize(); DebugCheckInitialize();
if (_playModeServices.ActiveManifest == null)
return string.Empty;
return _playModeServices.ActiveManifest.PackageVersion; return _playModeServices.ActiveManifest.PackageVersion;
} }
@ -967,12 +965,18 @@ namespace YooAsset
#region 调试方法 #region 调试方法
[Conditional("DEBUG")] [Conditional("DEBUG")]
private void DebugCheckInitialize() private void DebugCheckInitialize(bool checkActiveManifest = true)
{ {
if (_initializeStatus == EOperationStatus.None) if (_initializeStatus == EOperationStatus.None)
throw new Exception("Package initialize not completed !"); throw new Exception("Package initialize not completed !");
else if (_initializeStatus == EOperationStatus.Failed) else if (_initializeStatus == EOperationStatus.Failed)
throw new Exception($"Package initialize failed ! {_initializeError}"); throw new Exception($"Package initialize failed ! {_initializeError}");
if (checkActiveManifest)
{
if (_playModeServices.ActiveManifest == null)
throw new Exception("Not found active manifest !");
}
} }
[Conditional("DEBUG")] [Conditional("DEBUG")]

View File

@ -4,8 +4,13 @@ namespace YooAsset
public interface IQueryServices public interface IQueryServices
{ {
/// <summary> /// <summary>
/// 查询内置资源 /// 查询应用程序里的内置资源是否存在
/// </summary> /// </summary>
bool QueryStreamingAssets(string packageName, string fileName); bool QueryStreamingAssets(string packageName, string fileName);
/// <summary>
/// 查询开发者分发的文件加载路径
/// </summary>
string QueryDeliveryFiles(string packageName, string fileName);
} }
} }

View File

@ -142,11 +142,11 @@ internal class FsmInitialize : IStateNode
_defaultHostServer = defaultHostServer; _defaultHostServer = defaultHostServer;
_fallbackHostServer = fallbackHostServer; _fallbackHostServer = fallbackHostServer;
} }
string IRemoteServices.GetRemoteFallbackURL(string fileName) string IRemoteServices.GetRemoteMainURL(string fileName)
{ {
return $"{_defaultHostServer}/{fileName}"; return $"{_defaultHostServer}/{fileName}";
} }
string IRemoteServices.GetRemoteMainURL(string fileName) string IRemoteServices.GetRemoteFallbackURL(string fileName)
{ {
return $"{_fallbackHostServer}/{fileName}"; return $"{_fallbackHostServer}/{fileName}";
} }

View File

@ -8,6 +8,11 @@ using YooAsset;
/// </summary> /// </summary>
public class GameQueryServices : IQueryServices public class GameQueryServices : IQueryServices
{ {
public string QueryDeliveryFiles(string packageName, string fileName)
{
return null;
}
public bool QueryStreamingAssets(string packageName, string fileName) public bool QueryStreamingAssets(string packageName, string fileName)
{ {
// 注意fileName包含文件格式 // 注意fileName包含文件格式

View File

@ -11,6 +11,11 @@ using YooAsset;
/// </summary> /// </summary>
public class GameQueryServices2 : IQueryServices public class GameQueryServices2 : IQueryServices
{ {
public string QueryDeliveryFiles(string packageName, string fileName)
{
return null;
}
public bool QueryStreamingAssets(string packageName, string fileName) public bool QueryStreamingAssets(string packageName, string fileName)
{ {
return StreamingAssetsHelper2.FileExists($"{StreamingAssetsDefine.RootFolderName}/{packageName}/{fileName}"); return StreamingAssetsHelper2.FileExists($"{StreamingAssetsDefine.RootFolderName}/{packageName}/{fileName}");