1
This commit is contained in:
@@ -155,100 +155,105 @@ namespace BITKit
|
||||
|
||||
try
|
||||
{
|
||||
_progressLabel.text="正在更新资源包版本...";
|
||||
var operation = package.UpdatePackageVersionAsync();
|
||||
try
|
||||
if (isOffline is false)
|
||||
{
|
||||
onGetCurrentVersion.Invoke(package.GetPackageVersion());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
while (operation.IsDone is false)
|
||||
{
|
||||
await UniTask.NextFrame(destroyCancellationToken);
|
||||
//_progressBar.value = operation.Progress;
|
||||
_setProgressValue?.Invoke(operation.Progress);
|
||||
}
|
||||
_progressLabel.text = "正在更新资源包版本...";
|
||||
var operation = package.UpdatePackageVersionAsync();
|
||||
try
|
||||
{
|
||||
onGetCurrentVersion.Invoke(package.GetPackageVersion());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
|
||||
while (operation.IsDone is false)
|
||||
{
|
||||
await UniTask.NextFrame(destroyCancellationToken);
|
||||
//_progressBar.value = operation.Progress;
|
||||
_setProgressValue?.Invoke(operation.Progress);
|
||||
}
|
||||
|
||||
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//更新成功
|
||||
string packageVersion = operation.PackageVersion;
|
||||
Debug.Log($"Updated package Version : {packageVersion}");
|
||||
|
||||
_progressLabel.text="正在更新资源包清单...";
|
||||
|
||||
var manifestOperation = package.UpdatePackageManifestAsync(packageVersion);
|
||||
await manifestOperation.ToUniTask();
|
||||
if (manifestOperation.Status == EOperationStatus.Succeed)
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//更新成功
|
||||
int downloadingMaxNum = 10;
|
||||
int failedTryAgain = 3;
|
||||
var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
|
||||
|
||||
//没有需要下载的资源
|
||||
if (downloader.TotalDownloadCount != 0)
|
||||
{
|
||||
//需要下载的文件总数和总大小
|
||||
int totalDownloadCount = downloader.TotalDownloadCount;
|
||||
long totalDownloadBytes = downloader.TotalDownloadBytes;
|
||||
downloader.OnDownloadProgressCallback = (totalDownloadCount, currentDownloadCount, totalDownloadBytes, currentDownloadBytes) =>
|
||||
{
|
||||
BIT4Log.Log<BITFramework>($"{totalDownloadCount},{currentDownloadCount},{totalDownloadBytes},{currentDownloadBytes}");
|
||||
//下载进度
|
||||
float progress = (float)currentDownloadBytes / totalDownloadBytes;
|
||||
_setProgressValue?.Invoke(progress);
|
||||
_setProgressLabel?.Invoke($"{currentDownloadBytes}/{totalDownloadBytes}");
|
||||
};
|
||||
downloader.OnDownloadErrorCallback=(fileName,error) =>
|
||||
{
|
||||
_setProgressLabel?.Invoke(error);
|
||||
};
|
||||
|
||||
|
||||
//注册回调方法
|
||||
// downloader.OnDownloadErrorCallback = OnDownloadErrorFunction;
|
||||
// downloader.OnDownloadProgressCallback = OnDownloadProgressUpdateFunction;
|
||||
// downloader.OnDownloadOverCallback = OnDownloadOverFunction;
|
||||
// downloader.OnStartDownloadFileCallback = OnStartDownloadFileFunction;
|
||||
string packageVersion = operation.PackageVersion;
|
||||
Debug.Log($"Updated package Version : {packageVersion}");
|
||||
|
||||
//开启下载
|
||||
downloader.BeginDownload();
|
||||
await downloader;
|
||||
//检测下载结果
|
||||
if (downloader.Status != EOperationStatus.Succeed)
|
||||
_progressLabel.text = "正在更新资源包清单...";
|
||||
|
||||
var manifestOperation = package.UpdatePackageManifestAsync(packageVersion);
|
||||
await manifestOperation.ToUniTask();
|
||||
if (manifestOperation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//更新成功
|
||||
int downloadingMaxNum = 10;
|
||||
int failedTryAgain = 3;
|
||||
var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
|
||||
|
||||
//没有需要下载的资源
|
||||
if (downloader.TotalDownloadCount != 0)
|
||||
{
|
||||
//更新失败
|
||||
Debug.LogError(operation.Error);
|
||||
_progressLabel.text =operation.Error;
|
||||
//需要下载的文件总数和总大小
|
||||
int totalDownloadCount = downloader.TotalDownloadCount;
|
||||
long totalDownloadBytes = downloader.TotalDownloadBytes;
|
||||
downloader.OnDownloadProgressCallback = (totalDownloadCount, currentDownloadCount,
|
||||
totalDownloadBytes, currentDownloadBytes) =>
|
||||
{
|
||||
BIT4Log.Log<BITFramework>(
|
||||
$"{totalDownloadCount},{currentDownloadCount},{totalDownloadBytes},{currentDownloadBytes}");
|
||||
//下载进度
|
||||
float progress = (float)currentDownloadBytes / totalDownloadBytes;
|
||||
_setProgressValue?.Invoke(progress);
|
||||
_setProgressLabel?.Invoke($"{currentDownloadBytes}/{totalDownloadBytes}");
|
||||
};
|
||||
downloader.OnDownloadErrorCallback = (fileName, error) =>
|
||||
{
|
||||
_setProgressLabel?.Invoke(error);
|
||||
};
|
||||
|
||||
|
||||
//注册回调方法
|
||||
// downloader.OnDownloadErrorCallback = OnDownloadErrorFunction;
|
||||
// downloader.OnDownloadProgressCallback = OnDownloadProgressUpdateFunction;
|
||||
// downloader.OnDownloadOverCallback = OnDownloadOverFunction;
|
||||
// downloader.OnStartDownloadFileCallback = OnStartDownloadFileFunction;
|
||||
|
||||
//开启下载
|
||||
downloader.BeginDownload();
|
||||
await downloader;
|
||||
//检测下载结果
|
||||
if (downloader.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
//更新失败
|
||||
Debug.LogError(operation.Error);
|
||||
_progressLabel.text = operation.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新失败
|
||||
Debug.LogError(operation.Error);
|
||||
_progressLabel.text = operation.Error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新失败
|
||||
Debug.LogError(operation.Error);
|
||||
_progressLabel.text =operation.Error;
|
||||
_progressLabel.text = operation.Error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新失败
|
||||
Debug.LogError(operation.Error);
|
||||
_progressLabel.text =operation.Error;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
_progressLabel.text =e.Message;
|
||||
BIT4Log.LogException(e);
|
||||
_progressLabel.text = e.Message;
|
||||
}
|
||||
|
||||
|
||||
_setProgressLabel?.Invoke("资源系统初始化完成,后处理中...");
|
||||
afterInitialize.Invoke(_setProgressValue,_setProgressLabel);
|
||||
|
||||
@@ -281,14 +286,22 @@ namespace BITKit
|
||||
if (loadEntryScene.Allow)
|
||||
{
|
||||
_progressLabel.text="正在加载场景...";
|
||||
await package.LoadSceneAsync(loadEntryScene.Value);
|
||||
if (document)
|
||||
Destroy(document);
|
||||
try
|
||||
{
|
||||
await package.LoadSceneAsync(loadEntryScene.Value);
|
||||
_progressLabel.text="场景加载完成...";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
await UniTask.NextFrame();
|
||||
_progressLabel.text = e.Message;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (document)
|
||||
Destroy(document);
|
||||
_progressLabel.text="未找到默认场景,正在加载场景[1]";
|
||||
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
}
|
||||
@@ -298,6 +311,8 @@ namespace BITKit
|
||||
_progressBar.value =0;
|
||||
_progressLabel.text = e.Message;
|
||||
}
|
||||
if (document)
|
||||
Destroy(document);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
|
@@ -6,7 +6,7 @@ using YooAsset;
|
||||
/// <summary>
|
||||
/// 资源文件查询服务类
|
||||
/// </summary>
|
||||
public class GameQueryServices : IBuildinQueryServices
|
||||
public class GameQueryServices
|
||||
{
|
||||
public bool Query(string packageName, string fileName)
|
||||
{
|
||||
|
30
Src/Unity/Scripts/Assets/YooAssetModHelper.cs
Normal file
30
Src/Unity/Scripts/Assets/YooAssetModHelper.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit.Mod;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace BITKit.IO
|
||||
{
|
||||
public class YooAssetModHelper : MonoBehaviour
|
||||
{
|
||||
private void OnEnable()
|
||||
{
|
||||
ModService.LoadAssetAsyncFactory += LoadAsset;
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
ModService.LoadAssetAsyncFactory -= LoadAsset;
|
||||
}
|
||||
|
||||
private static async UniTask<object> LoadAsset(string arg)
|
||||
{
|
||||
var handle = YooAssets.LoadAssetAsync(arg);
|
||||
await handle;
|
||||
return handle.AssetObject;
|
||||
}
|
||||
}
|
||||
}
|
11
Src/Unity/Scripts/Assets/YooAssetModHelper.cs.meta
Normal file
11
Src/Unity/Scripts/Assets/YooAssetModHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31eceddc48b358b40901eba1134d5450
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user