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()
|
||||
|
Reference in New Issue
Block a user