mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
Merge pull request #59 from AlanWeekend/main
优化分包资源下载逻辑,统一WebGL平台与其他平台的远程热更资源引用方式
This commit is contained in:
@@ -29,7 +29,8 @@ namespace GameMain
|
||||
|
||||
private async UniTaskVoid InitPackage(ProcedureOwner procedureOwner)
|
||||
{
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.HostPlayMode)
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.HostPlayMode ||
|
||||
GameModule.Resource.PlayMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
if (SettingsUtils.EnableUpdateData())
|
||||
{
|
||||
@@ -44,7 +45,8 @@ namespace GameMain
|
||||
|
||||
if (!string.IsNullOrEmpty(updateData.FallbackHostServerURL))
|
||||
{
|
||||
SettingsUtils.FrameworkGlobalSettings.FallbackHostServerURL = updateData.FallbackHostServerURL;
|
||||
SettingsUtils.FrameworkGlobalSettings.FallbackHostServerURL =
|
||||
updateData.FallbackHostServerURL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,9 +62,9 @@ namespace GameMain
|
||||
{
|
||||
//热更新阶段文本初始化
|
||||
LoadText.Instance.InitConfigData(null);
|
||||
|
||||
|
||||
GameEvent.Send(RuntimeId.ToRuntimeId("RefreshVersion"));
|
||||
|
||||
|
||||
EPlayMode playMode = GameModule.Resource.PlayMode;
|
||||
|
||||
// 编辑器模式。
|
||||
@@ -107,7 +109,9 @@ namespace GameMain
|
||||
// 打开启动UI。
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, $"资源初始化失败!");
|
||||
|
||||
UILoadTip.ShowMessageBox($"资源初始化失败!点击确认重试 \n \n <color=#FF0000>原因{initializationOperation.Error}</color>", MessageShowType.TwoButton,
|
||||
UILoadTip.ShowMessageBox(
|
||||
$"资源初始化失败!点击确认重试 \n \n <color=#FF0000>原因{initializationOperation.Error}</color>",
|
||||
MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry
|
||||
, () => { Retry(procedureOwner); }, UnityEngine.Application.Quit);
|
||||
}
|
||||
|
@@ -10,18 +10,6 @@ namespace TEngine
|
||||
public const string RootFolderName = "yoo";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询服务类。
|
||||
/// </summary>
|
||||
public class BuiltinQueryServices : IBuildinQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
// 注意:fileName包含文件格式
|
||||
return BuiltinQueryMgr.FileExists(packageName, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 内置资源资源查询帮助类。
|
||||
|
@@ -12,7 +12,7 @@ namespace TEngine
|
||||
private class GameDecryptionServices : IDecryptionServices
|
||||
{
|
||||
private const byte OffSet = 32;
|
||||
|
||||
|
||||
public ulong LoadFromFileOffset(DecryptFileInfo fileInfo)
|
||||
{
|
||||
return OffSet;
|
||||
@@ -25,7 +25,8 @@ namespace TEngine
|
||||
|
||||
public Stream LoadFromStream(DecryptFileInfo fileInfo)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
BundleStream bundleStream =
|
||||
new BundleStream(fileInfo.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
return bundleStream;
|
||||
}
|
||||
|
||||
@@ -34,7 +35,7 @@ namespace TEngine
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 默认的分发资源查询服务类
|
||||
/// </summary>
|
||||
@@ -44,40 +45,66 @@ namespace TEngine
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool QueryDeliveryFiles(string packageName, string fileName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 远程文件查询服务类。
|
||||
/// </summary>
|
||||
private class RemoteServices: IRemoteServices
|
||||
private class RemoteServices : IRemoteServices
|
||||
{
|
||||
private readonly string _defaultHostServer;
|
||||
private readonly string _fallbackHostServer;
|
||||
private string _packageName;
|
||||
|
||||
public RemoteServices()
|
||||
public RemoteServices(string packageName)
|
||||
{
|
||||
_defaultHostServer = SettingsUtils.FrameworkGlobalSettings.HostServerURL;
|
||||
_fallbackHostServer = SettingsUtils.FrameworkGlobalSettings.FallbackHostServerURL;
|
||||
_packageName = packageName;
|
||||
}
|
||||
|
||||
|
||||
public RemoteServices(string defaultHostServer, string fallbackHostServer)
|
||||
{
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
}
|
||||
|
||||
|
||||
public string GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_defaultHostServer}/{fileName}";
|
||||
return $"{_defaultHostServer}/{_packageName}/{fileName}";
|
||||
}
|
||||
|
||||
public string GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_fallbackHostServer}/{fileName}";
|
||||
return $"{_defaultHostServer}/{_packageName}/{fileName}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询服务类。
|
||||
/// </summary>
|
||||
public class BuiltinQueryServices : IBuildinQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
// 注意:fileName包含文件格式
|
||||
return BuiltinQueryMgr.FileExists(packageName, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WebGL内置文件查询服务类。WebGL平台不需要内置查询,直接使用远程热更资源。
|
||||
/// </summary>
|
||||
public class WebGLBuiltinQueryServices : IBuildinQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +113,8 @@ namespace TEngine
|
||||
{
|
||||
public const byte KEY = 128;
|
||||
|
||||
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access, share)
|
||||
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access,
|
||||
share)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -384,7 +384,7 @@ namespace TEngine
|
||||
createParameters.DecryptionServices = new GameDecryptionServices();
|
||||
createParameters.BuildinQueryServices = new BuiltinQueryServices();
|
||||
createParameters.DeliveryQueryServices = new DefaultDeliveryQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices();
|
||||
createParameters.RemoteServices = new RemoteServices(targetPackageName);
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
@@ -394,8 +394,11 @@ namespace TEngine
|
||||
YooAssets.SetCacheSystemDisableCacheOnWebGL();
|
||||
var createParameters = new WebPlayModeParameters();
|
||||
createParameters.DecryptionServices = new GameDecryptionServices();
|
||||
createParameters.BuildinQueryServices = new BuiltinQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices();
|
||||
createParameters.BuildinQueryServices = new WebGLBuiltinQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices(targetPackageName);
|
||||
// WebGL运行模式下,直接使用远程热更资源。
|
||||
createParameters.BuildinRootDirectory = SettingsUtils.FrameworkGlobalSettings.HostServerURL;
|
||||
createParameters.SandboxRootDirectory = SettingsUtils.FrameworkGlobalSettings.HostServerURL;
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user