-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathUpdateLoadingBarSystem.cs
More file actions
65 lines (59 loc) · 2.52 KB
/
UpdateLoadingBarSystem.cs
File metadata and controls
65 lines (59 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using UnityEngine;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine.UIElements;
using Unity.Entities.Content;
namespace ContentManagement.Sample
{
[UpdateBefore(typeof(LoadingRemoteCatalogSystem))]
public partial class UpdateLoadingBarSystem : SystemBase
{
private ProgressBar m_ProgressBar;
private bool isInitialized;
protected override void OnCreate()
{
isInitialized = false;
RequireForUpdate<HighLowWeakScene>();
}
protected override void OnUpdate()
{
#region InitializingUI
if (!isInitialized)
{
var progressBarUI = Object.FindAnyObjectByType<LoadingBarUI>();
if (progressBarUI == null)
return;
isInitialized = true;
m_ProgressBar = progressBarUI.ProgressBar;
m_ProgressBar.style.display = DisplayStyle.Flex;
}
#endregion
#region ReadingLoadedBytesFromContentManagementAPI
// Displays the loading bar used during the following loading and download steps:
// - DownloadingCatalogInfo
// - DownloadingCatalogs (catalog.bin)
// - DownloadingLocalCatalogs (catalog.bin from StreamingAssets)
// - DownloadingContentSet (artifacts folders/files)
if (ContentDeliveryGlobalState.CurrentContentUpdateState < ContentDeliveryGlobalState.ContentUpdateState.ContentReady)
{
if (ContentDeliveryGlobalState.DeliveryService != null && ContentDeliveryGlobalState.DeliveryService.DownloadServices != null)
{
foreach (var downloadService in ContentDeliveryGlobalState.DeliveryService.DownloadServices)
{
if(downloadService.TotalBytes <= 0)
continue;
float progress = (float) downloadService.TotalDownloadedBytes / downloadService.TotalBytes;
float normalizedProgress = math.clamp(progress, 0f, 1f);
m_ProgressBar.value = normalizedProgress;
m_ProgressBar.title = $"[{ContentDeliveryGlobalState.CurrentContentUpdateState}]: {downloadService.Name} - {normalizedProgress*100}% ";
}
}
}
else
{
m_ProgressBar.style.display = DisplayStyle.None;
}
#endregion
}
}
}