Skip to content

Commit

Permalink
Merge pull request #58 from AIO-GAME/1.x
Browse files Browse the repository at this point in the history
1.x
  • Loading branch information
xinansky authored Jan 26, 2024
2 parents 633f0e6 + 954cd68 commit e544bb1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private static async Task WaitTask(DownloaderOperation operation, AssetInfo loca
break;
}
case NetworkReachability.ReachableViaLocalAreaNetwork:
break;
break;
}

if (AssetSystem.HandleReset) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void CollectNeedAll()
var operation = asset.CreateResourceDownloader();
if (operation is null) continue;
if (operation.TotalDownloadCount <= 0) continue;
ResourceDownloaderOperations[string.Concat("ALL-", name)] = operation;
ResourceDownloaderOperations[string.Concat("ALL-", name, '-', DateTime.Now.Ticks)] = operation;
}

OpenDownloadAll = true;
Expand All @@ -246,7 +246,6 @@ private void CollectNeedTagBegin(params string[] tags)
if (tags is null || tags.Length == 0) return;
foreach (var name in ManifestOperations.Keys)
{
AssetSystem.Log($"CollectNeedTagBegin -> {name}");
if (!Packages.TryGetValue(name, out var asset)) continue;
Tags[name] = 1;
var operation =
Expand All @@ -269,6 +268,9 @@ public void CollectNeedTag(params string[] tags)

protected override async Task OnWaitAsync()
{
CurrentValueDict.Clear();
TotalValueDict.Clear();

foreach (var pair in ResourceDownloaderOperations)
{
CurrentValueDict[pair.Key] = pair.Value.CurrentDownloadBytes;
Expand All @@ -277,7 +279,7 @@ protected override async Task OnWaitAsync()

TotalValue = TotalValueDict.Sum(pair => pair.Value);
CurrentValue = CurrentValueDict.Sum(pair => pair.Value);
if (AssetSystem.GetAvailableDiskSpace() < TotalValue) // 检查磁盘空间是否足够
if (AssetSystem.GetAvailableDiskSpace() < TotalValue - CurrentValue) // 检查磁盘空间是否足够
{
State = EProgressState.Fail;
if (OnDiskSpaceNotEnough is null)
Expand Down Expand Up @@ -340,7 +342,9 @@ void OnUpdateProgress(int _, int __, long totalDownloadBytes, long currentDownlo
break;
}

CurrentValueDict[pair.Key] = pair.Value.CurrentDownloadBytes + currentDownloadBytes;
TotalValueDict[pair.Key] = totalDownloadBytes;
TotalValue = TotalValueDict.Sum(item => item.Value);
CurrentValueDict[pair.Key] = currentDownloadBytes;
CurrentValue = CurrentValueDict.Sum(item => item.Value);
}
}
Expand All @@ -353,27 +357,30 @@ void OnUpdateProgress(int _, int __, long totalDownloadBytes, long currentDownlo

protected override IEnumerator OnWaitCo()
{
CurrentValueDict.Clear();
TotalValueDict.Clear();

foreach (var pair in ResourceDownloaderOperations)
{
CurrentValueDict[pair.Key] = pair.Value.CurrentDownloadBytes;
TotalValueDict[pair.Key] = pair.Value.TotalDownloadBytes;
CurrentValueDict[pair.Key] = pair.Value.CurrentDownloadBytes;
}

if (AssetSystem.GetAvailableDiskSpace() < TotalValue) // 检查磁盘空间是否足够
TotalValue = TotalValueDict.Sum(pair => pair.Value);
CurrentValue = CurrentValueDict.Sum(pair => pair.Value);

if (AssetSystem.GetAvailableDiskSpace() < TotalValue - CurrentValue) // 检查磁盘空间是否足够
{
State = EProgressState.Fail;
if (OnDiskSpaceNotEnough is null)
throw new Exception(
throw new SystemException(
$"磁盘空间 {AssetSystem.GetAvailableDiskSpace().ToConverseStringFileSize()} < {TotalValue.ToConverseStringFileSize()}");
OnDiskSpaceNotEnough.Invoke(Report);
AssetSystem.LogException(
$"磁盘空间 {AssetSystem.GetAvailableDiskSpace().ToConverseStringFileSize()} < {TotalValue.ToConverseStringFileSize()}");
OnDiskSpaceNotEnough.Invoke(Report);
yield break;
}

TotalValue = TotalValueDict.Sum(pair => pair.Value);
CurrentValue = CurrentValueDict.Sum(pair => pair.Value);

foreach (var pair in ResourceDownloaderOperations)
{
CurrentInfo = $"Resource Download -> [{pair.Key}]";
Expand All @@ -400,10 +407,11 @@ protected override IEnumerator OnWaitCo()
yield return pair.Value;

if (pair.Value.Status == EOperationStatus.Succeed) continue;

State = EProgressState.Fail;
yield break;

void OnUpdateProgress(int _, int __, long ___, long currentDownloadBytes)
void OnUpdateProgress(int _, int __, long totalDownloadBytes, long currentDownloadBytes)
{
if (State != EProgressState.Running) return;
switch (Application.internetReachability)
Expand All @@ -426,6 +434,8 @@ void OnUpdateProgress(int _, int __, long ___, long currentDownloadBytes)
break;
}

TotalValueDict[pair.Key] = totalDownloadBytes;
TotalValue = TotalValueDict.Sum(item => item.Value);
CurrentValueDict[pair.Key] = currentDownloadBytes;
CurrentValue = CurrentValueDict.Sum(item => item.Value);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.aio.cli.asset",
"displayName": "AIO Unity CLI Asset",
"description": "AIO Unity CLI Asset",
"version": "1.0.30-preview",
"version": "1.0.31-preview",
"unity": "2019.4",
"unityRelease": "0f1",
"license": "MIT",
Expand Down

0 comments on commit e544bb1

Please sign in to comment.