【m】优化加载架构
This commit is contained in:
@@ -13,6 +13,8 @@ namespace Stary.Evo
|
||||
private TransformCtor transformCtor;
|
||||
|
||||
public ProgressBarPanel ProgressBarPanel { get; set; }
|
||||
|
||||
public bool IsLogin = false;
|
||||
public void SetOpenDomainType(OpenDomainType type)
|
||||
{
|
||||
this.OpenDomainType = type;
|
||||
|
||||
@@ -23,18 +23,6 @@ namespace Stary.Evo
|
||||
Debug.Log("UnityEvo:启动开始资源初始化...");
|
||||
|
||||
|
||||
//初始化读取资源配置表
|
||||
HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
|
||||
if (hotfixMainResDomain != null)
|
||||
{
|
||||
AppConfig.IpConfig = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
|
||||
AppConfig.UserName = hotfixMainResDomain.hotfixMainResDomainEntity.username;
|
||||
AppConfig.PassWord = hotfixMainResDomain.hotfixMainResDomainEntity.password;
|
||||
AppConfig.ProductName =Application.identifier;
|
||||
AppConfig.MainDomainVersion = hotfixMainResDomain.hotfixMainResDomainEntity.mainDomainVersion;
|
||||
}
|
||||
|
||||
Debug.Log($"UnityEvo:读取资源配置表成功...{AppConfig.IpConfig}{AppConfig.UserName}{AppConfig.PassWord}");
|
||||
// 初始化资源系统
|
||||
YooAssets.Initialize();
|
||||
//初始化资源加载模块
|
||||
@@ -53,20 +41,20 @@ namespace Stary.Evo
|
||||
await EDITOR_SIMULATEMODE(package);
|
||||
await FsmSystem.SetCurState(nameof(ResEditorSimulateState));
|
||||
#elif OFFLINE_PLAYMODE
|
||||
await OFFLINE_PLAYMODE(package);
|
||||
await FsmSystem.SetCurState(nameof(ResUpdateLocalState));
|
||||
await OFFLINE_PLAYMODE(package);
|
||||
await FsmSystem.SetCurState(nameof(ResUpdateLocalState));
|
||||
#elif HOST_PLAYMODE
|
||||
|
||||
//登录
|
||||
string url = AppConfig.IpConfig + "/Authentication/login";
|
||||
bool isLogin = await WebRequestSystem.Login(url, AppConfig.UserName, AppConfig.PassWord);
|
||||
if (isLogin)
|
||||
await HOST_PLAYMODE(package);
|
||||
else
|
||||
await ChChe_PLAYMODE(package);
|
||||
//登录
|
||||
if (((FsmLoadSystem)FsmSystem).IsLogin)
|
||||
await HOST_PLAYMODE(package);
|
||||
else
|
||||
{
|
||||
await OFFLINE_PLAYMODE(package);
|
||||
await ChChe_PLAYMODE(package);
|
||||
}
|
||||
|
||||
|
||||
await FsmSystem.SetCurState(nameof(ResUpdateLocalState));
|
||||
await FsmSystem.SetCurState(nameof(ResUpdateLocalState));
|
||||
|
||||
#elif WEB_PLAYMODE
|
||||
// IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
@@ -113,8 +101,7 @@ namespace Stary.Evo
|
||||
|
||||
private async UniTask EDITOR_SIMULATEMODE(ResourcePackage package)
|
||||
{
|
||||
|
||||
var initParams=YooAssetFileSystem.EditorSimulateInitializeParameter(package.PackageName);
|
||||
var initParams = YooAssetFileSystem.EditorSimulateInitializeParameter(package.PackageName);
|
||||
var initialization = package.InitializeAsync(initParams);
|
||||
await initialization;
|
||||
if (initialization.Status == EOperationStatus.Succeed)
|
||||
@@ -127,12 +114,20 @@ namespace Stary.Evo
|
||||
Debug.LogError($"UnityEvo:资源包初始化失败:{initialization.Error}");
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask ChChe_PLAYMODE(ResourcePackage package)
|
||||
{
|
||||
Debug.Log("UnityEvo:网络连接不通畅,切换缓存加载!");
|
||||
var initParams=YooAssetFileSystem.HostInitializeParameter();
|
||||
//Debug.Log("UnityEvo:网络连接不通畅,切换缓存加载!");
|
||||
var initParams = YooAssetFileSystem.HostInitializeParameter();
|
||||
var initOperation = package.InitializeAsync(initParams);
|
||||
await initOperation;
|
||||
if (initOperation.Status == EOperationStatus.Succeed)
|
||||
Debug.Log("UnityEvo:从本地缓存中资源包,初始化成功!");
|
||||
else
|
||||
{
|
||||
Debug.LogError($"UnityEvo:从本地缓存中资源包,初始化失败:{initOperation.Error}");
|
||||
}
|
||||
|
||||
|
||||
var operation = package.RequestPackageVersionAsync();
|
||||
await operation;
|
||||
@@ -140,37 +135,87 @@ namespace Stary.Evo
|
||||
{
|
||||
PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", operation.PackageVersion);
|
||||
Debug.Log("UnityEvo:从本地缓存中加载资源包,初始化获取版本号成功!");
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"UnityEvo:从本地缓存中加载资源包,初始化获取版本号失败!");
|
||||
}
|
||||
|
||||
if (initOperation.Status == EOperationStatus.Succeed)
|
||||
Debug.Log("UnityEvo:从本地缓存中资源包,初始化成功!");
|
||||
else
|
||||
Debug.LogError($"UnityEvo:从本地缓存中资源包,初始化失败:{initOperation.Error}");
|
||||
}
|
||||
|
||||
private async UniTask OFFLINE_PLAYMODE(ResourcePackage package)
|
||||
{
|
||||
var initParams=YooAssetFileSystem.OfflineInitializeParameter();
|
||||
var initOperation = package.InitializeAsync(initParams);
|
||||
await initOperation;
|
||||
Debug.Log("UnityEvo:网络连接不通畅,切换缓存加载!");
|
||||
CopyLocalFile();
|
||||
// var initParams = YooAssetFileSystem.OfflineInitializeParameter();
|
||||
// var initOperation = package.InitializeAsync(initParams);
|
||||
// await initOperation;
|
||||
//
|
||||
// var operation = package.RequestPackageVersionAsync();
|
||||
// await operation;
|
||||
// if (operation.Status == EOperationStatus.Succeed)
|
||||
// {
|
||||
// PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", operation.PackageVersion);
|
||||
// Debug.Log("UnityEvo:从本地StreamingAssets加载资源包,初始化获取版本号成功!");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debug.LogError($"UnityEvo:从本地StreamingAssets加载资源包,初始化获取版本号失败!");
|
||||
// }
|
||||
//
|
||||
// if (initOperation.Status == EOperationStatus.Succeed)
|
||||
// Debug.Log("UnityEvo:从本地StreamingAssets加载资源包,初始化成功!");
|
||||
// else
|
||||
// Debug.LogError($"UnityEvo:从本地StreamingAssets加载资源包,初始化失败:{initOperation.Error}");
|
||||
}
|
||||
|
||||
var operation = package.RequestPackageVersionAsync();
|
||||
await operation;
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
private void CopyLocalFile()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
// 将StreamingAssets下指定的package拷贝到目标路径
|
||||
string sourcePath = Path.Combine(Application.streamingAssetsPath,
|
||||
YooAssetSettingsData.GetDefaultYooFolderName(), AppConfig.PackageDomainName);
|
||||
string loadPath = Path.Combine(Application.temporaryCachePath, "DownloadedContent",
|
||||
AppConfig.PackageDomainName);
|
||||
|
||||
// 创建目标目录(如果不存在)
|
||||
if (!Directory.Exists(loadPath))
|
||||
{
|
||||
PlayerPrefs.SetString($"{AppConfig.PackageDomainName}_GAME_VERSION", operation.PackageVersion);
|
||||
Debug.Log("UnityEvo:从本地加载资源包,初始化获取版本号成功!");
|
||||
}else
|
||||
Directory.CreateDirectory(loadPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"UnityEvo:从本地加载资源包,初始化获取版本号失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (initOperation.Status == EOperationStatus.Succeed)
|
||||
Debug.Log("UnityEvo:从本地加载资源包,初始化成功!");
|
||||
// 检查源路径是否存在
|
||||
if (Directory.Exists(sourcePath))
|
||||
{
|
||||
// 拷贝所有文件
|
||||
string[] files = Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
{
|
||||
// 计算目标文件路径
|
||||
string relativePath = Path.GetRelativePath(sourcePath, file);
|
||||
string destFile = Path.Combine(loadPath, relativePath);
|
||||
|
||||
// 创建目标子目录(如果不存在)
|
||||
string destDir = Path.GetDirectoryName(destFile);
|
||||
if (!Directory.Exists(destDir))
|
||||
{
|
||||
Directory.CreateDirectory(destDir);
|
||||
}
|
||||
|
||||
// 拷贝文件
|
||||
File.Copy(file, destFile, true);
|
||||
}
|
||||
|
||||
Debug.Log($"UnityEvo:成功将StreamingAssets下的{AppConfig.PackageDomainName}包拷贝到{loadPath}");
|
||||
}
|
||||
else
|
||||
Debug.LogError($"UnityEvo:从本地加载资源包,初始化失败:{initOperation.Error}");
|
||||
{
|
||||
Debug.LogError($"UnityEvo:StreamingAssets下的{AppConfig.PackageDomainName}包不存在");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public async UniTask HOST_PLAYMODE(ResourcePackage package)
|
||||
@@ -217,7 +262,7 @@ namespace Stary.Evo
|
||||
Debug.LogError($"UnityEvo:获取资源版本失败: 【{resDmainMessageEntity.message}】");
|
||||
}
|
||||
|
||||
var initParams=YooAssetFileSystem.HostInitializeParameter();
|
||||
var initParams = YooAssetFileSystem.HostInitializeParameter();
|
||||
// initParameters.CacheFileSystemParameters = cacheFileSystemParams;
|
||||
|
||||
var initOperation = package.InitializeAsync(initParams);
|
||||
@@ -242,26 +287,28 @@ namespace Stary.Evo
|
||||
// 等一帧,让系统真正释放句柄
|
||||
await UniTask.DelayFrame(1);
|
||||
}
|
||||
FsmLoadSystem loadSystem =FsmSystem as FsmLoadSystem;
|
||||
|
||||
FsmLoadSystem loadSystem = FsmSystem as FsmLoadSystem;
|
||||
if (loadSystem.ProgressBarPanel == null)
|
||||
{
|
||||
loadSystem.ProgressBarPanel =Object.Instantiate(Resources.Load<GameObject>("ProgressBarPanel"),
|
||||
loadSystem.ProgressBarPanel = Object.Instantiate(Resources.Load<GameObject>("ProgressBarPanel"),
|
||||
Camera.main.transform).GetOrAddComponent<ProgressBarPanel>();
|
||||
}
|
||||
|
||||
await ZipTool.DownloadAndUnzipAsync(fileId, loadPath, DownLoadProgress, UnzipProgress);
|
||||
}
|
||||
|
||||
private void DownLoadProgress(float progress)
|
||||
{
|
||||
Debug.Log($"下载进度:{progress:P0}");
|
||||
FsmLoadSystem loadSystem =FsmSystem as FsmLoadSystem;
|
||||
FsmLoadSystem loadSystem = FsmSystem as FsmLoadSystem;
|
||||
loadSystem.ProgressBarPanel.SetProgressBarValue("下载中", progress);
|
||||
}
|
||||
|
||||
private void UnzipProgress(float progress)
|
||||
{
|
||||
Debug.Log($"解压进度:{progress:P0}");
|
||||
FsmLoadSystem loadSystem =FsmSystem as FsmLoadSystem;
|
||||
FsmLoadSystem loadSystem = FsmSystem as FsmLoadSystem;
|
||||
loadSystem.ProgressBarPanel.SetProgressBarValue("解压中", progress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,38 +20,17 @@ namespace Stary.Evo
|
||||
|
||||
//更新失败
|
||||
|
||||
Debug.Log($"UnityEvo:切换为加载本地缓存资源...");
|
||||
string packageVersion = "";
|
||||
// if (package.PackageName.Equals("Main"))
|
||||
// {
|
||||
// var operation = package.RequestPackageVersionAsync();
|
||||
// await operation;
|
||||
// if (operation.Status == EOperationStatus.Succeed)
|
||||
// {
|
||||
// //更新成功
|
||||
// packageVersion = operation.PackageVersion;
|
||||
// Debug.Log($"Unity:【Main】Request package Version : {packageVersion}");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //更新失败
|
||||
// Debug.LogError("Unity:【Main】" + operation.Error);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
Debug.Log($"UnityEvo:开始加载本地缓存资源...");
|
||||
|
||||
// 获取上次成功记录的版本
|
||||
string packageVersion = PlayerPrefs.GetString($"{AppConfig.PackageDomainName}_GAME_VERSION", string.Empty);
|
||||
if (string.IsNullOrEmpty(packageVersion))
|
||||
{
|
||||
// 获取上次成功记录的版本
|
||||
packageVersion = PlayerPrefs.GetString($"{AppConfig.PackageDomainName}_GAME_VERSION", string.Empty);
|
||||
if (string.IsNullOrEmpty(packageVersion))
|
||||
{
|
||||
Debug.Log($"UnityEvo:没有找到本地版本记录,需要更新资源!");
|
||||
return;
|
||||
}
|
||||
Debug.Log($"UnityEvo:没有找到本地版本记录,需要更新资源!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Debug.Log($"UnityEvo:获取资源版本 Version : 【{packageVersion}】");
|
||||
Debug.Log($"UnityEvo:开始加载本地资源...");
|
||||
// Assert.AreEqual(EOperationStatus.Succeed, requetVersionOp.Status);
|
||||
|
||||
|
||||
@@ -74,7 +53,7 @@ namespace Stary.Evo
|
||||
|
||||
|
||||
//4.下载补丁包
|
||||
await Download();
|
||||
//await Download();
|
||||
|
||||
|
||||
//加载热更配置文件
|
||||
|
||||
Reference in New Issue
Block a user