From 3d0c02149f42dddf732e842517cfbd3762d835cf Mon Sep 17 00:00:00 2001 From: Julian Cruz Date: Fri, 21 Nov 2025 16:45:42 +0100 Subject: [PATCH 1/7] adding loading bar --- .../2. WeakSceneLoading/LoadingBarUI.cs | 24 +++++++ .../2. WeakSceneLoading/LoadingBarUI.cs.meta | 2 + .../LoadingRemoteCatalogSystem.cs | 10 --- .../UpdateLoadingBarSystem.cs | 67 +++++++++++++++++++ .../UpdateLoadingBarSystem.cs.meta | 3 + .../WeakSceneLoading.unity | 13 ++++ .../Art/UI/SceneLoadingInstructions.uxml | 3 + .../Assets/Art/UI/Style.uss | 43 +++++++++++- 8 files changed, 153 insertions(+), 12 deletions(-) create mode 100644 Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingBarUI.cs create mode 100644 Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingBarUI.cs.meta create mode 100644 Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs create mode 100644 Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs.meta diff --git a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingBarUI.cs b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingBarUI.cs new file mode 100644 index 000000000..8eccb31fc --- /dev/null +++ b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingBarUI.cs @@ -0,0 +1,24 @@ +using UnityEngine; +using UnityEngine.UIElements; + +namespace ContentManagement.Sample +{ + public class LoadingBarUI : MonoBehaviour + { + private ProgressBar m_ProgressBar; + public ProgressBar ProgressBar + { + get + { + if (m_ProgressBar == null) + { + var document = GetComponent(); + var root = document.rootVisualElement; + m_ProgressBar = root.Query("progress-bar"); + } + + return m_ProgressBar; + } + } + } +} \ No newline at end of file diff --git a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingBarUI.cs.meta b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingBarUI.cs.meta new file mode 100644 index 000000000..40482d7f3 --- /dev/null +++ b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingBarUI.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 8f60424fd5439c64abe7ddfd4277b99d \ No newline at end of file diff --git a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingRemoteCatalogSystem.cs b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingRemoteCatalogSystem.cs index c5e8b619a..76a55a831 100644 --- a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingRemoteCatalogSystem.cs +++ b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/LoadingRemoteCatalogSystem.cs @@ -19,16 +19,6 @@ public void OnCreate(ref SystemState state) state.RequireForUpdate(); state.RequireForUpdate(); initialized = false; - ContentDeliveryGlobalState.RegisterForContentUpdateCompletion(UpdateStateCallback); - } - - private void UpdateStateCallback(ContentDeliveryGlobalState.ContentUpdateState contentUpdateState) - { - Debug.Log($"Content Delivery Global State: {contentUpdateState}"); - if (contentUpdateState >= ContentDeliveryGlobalState.ContentUpdateState.ContentReady) - { - // Track the state of your content and set when your content is ready to use - } } public void OnUpdate(ref SystemState state) diff --git a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs new file mode 100644 index 000000000..c097ff0af --- /dev/null +++ b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs @@ -0,0 +1,67 @@ +using Unity.Entities; +using Unity.Entities.Content; +using Unity.Mathematics; +using UnityEngine; +using UnityEngine.UIElements; + +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(); + } + + private void UpdateStateCallback(ContentDeliveryGlobalState.ContentUpdateState contentUpdateState) + { + if (contentUpdateState >= ContentDeliveryGlobalState.ContentUpdateState.ContentReady) + { + // Track the state of your content and set when your content is ready to use + m_ProgressBar.style.display = DisplayStyle.None; + } + } + + protected override void OnUpdate() + { + var progressBarUI = Object.FindAnyObjectByType(); + if (progressBarUI == null) + return; + + if (!isInitialized) + { + isInitialized = true; + m_ProgressBar = progressBarUI.ProgressBar; + m_ProgressBar.style.display = DisplayStyle.Flex; + ContentDeliveryGlobalState.RegisterForContentUpdateCompletion(UpdateStateCallback); + } + + // Displays the loading bar used during the following loading and download steps: + // - DownloadingCatalogInfo + // - DownloadingCatalogs + // - DownloadingLocalCatalogs + // - DownloadingContentSet + 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.max(0f, math.min(1f, progress)); + m_ProgressBar.value = normalizedProgress; + m_ProgressBar.title = $"[{ContentDeliveryGlobalState.CurrentContentUpdateState}]: {downloadService.Name} - {normalizedProgress*100}% "; + } + } + } + } + } +} \ No newline at end of file diff --git a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs.meta b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs.meta new file mode 100644 index 000000000..56f636d4e --- /dev/null +++ b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0a200ae2fcfd4f80b3f34887d096ead9 +timeCreated: 1763730029 \ No newline at end of file diff --git a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/WeakSceneLoading.unity b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/WeakSceneLoading.unity index cbe81f22a..8b54748f8 100644 --- a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/WeakSceneLoading.unity +++ b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/WeakSceneLoading.unity @@ -5331,6 +5331,7 @@ GameObject: m_Component: - component: {fileID: 1865683012} - component: {fileID: 1865683011} + - component: {fileID: 1865683013} m_Layer: 0 m_Name: UI m_TagString: Untagged @@ -5377,6 +5378,18 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1865683013 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1865683010} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8f60424fd5439c64abe7ddfd4277b99d, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::LoadingBarUI --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 diff --git a/Dots101/ContentManagement101/Assets/Art/UI/SceneLoadingInstructions.uxml b/Dots101/ContentManagement101/Assets/Art/UI/SceneLoadingInstructions.uxml index 2a0dde5ce..a73b2778f 100644 --- a/Dots101/ContentManagement101/Assets/Art/UI/SceneLoadingInstructions.uxml +++ b/Dots101/ContentManagement101/Assets/Art/UI/SceneLoadingInstructions.uxml @@ -6,4 +6,7 @@ + + + diff --git a/Dots101/ContentManagement101/Assets/Art/UI/Style.uss b/Dots101/ContentManagement101/Assets/Art/UI/Style.uss index f7f63740b..ab518c511 100644 --- a/Dots101/ContentManagement101/Assets/Art/UI/Style.uss +++ b/Dots101/ContentManagement101/Assets/Art/UI/Style.uss @@ -7,6 +7,45 @@ -unity-text-align: upper-center; } +.unity-progress-bar__title { + -unity-font-definition: url("project://database/Assets/Art/Fonts/ShareTechMono-Regular/ShareTechMono-Regular.ttf?fileID=12800000&guid=ba952712555b503458be5a0ebcad7e60&type=3#ShareTechMono-Regular"); + font-size: 18px; + top: -10px; + -unity-font-style: bold; + color: rgb(164, 164, 73); + text-shadow: 2px 2px 0 rgba(255, 1, 86, 0.47); + -unity-text-align: upper-center; +} + +.unity-progress-bar__background { + background-color: rgb(51, 51, 51); + border-left-color: rgb(0, 254, 254); + border-right-color: rgb(0, 254, 254); + border-top-color: rgb(0, 254, 254); + border-bottom-color: rgb(0, 254, 254); + border-top-width: 1px; + border-right-width: 1px; + border-bottom-width: 1px; + border-left-width: 1px; + border-top-left-radius: 2px; + border-top-right-radius: 2px; + border-bottom-right-radius: 2px; + border-bottom-left-radius: 2px; +} + +.unity-progress-bar__progress { + background-color: rgb(65, 65, 65); + border-bottom-width: 1px; + border-bottom-color: rgb(0, 254, 254); + border-right-color: rgb(255, 255, 0); + border-right-width: 1px; + border-top-color: rgb(255, 0, 255); + border-top-width: 1px; + border-left-color: rgb(255, 255, 0); + border-left-width: 1px; + border-top-left-radius: 0; +} + .container { width: 30%; position: absolute; @@ -44,7 +83,7 @@ } .hover { - cursor: url("project://database/Assets/Art/Texture/pointer.png?fileID=2800000&guid=53954a4289b154ebdaf8f055996168eb&type=3#pointer"); + cursor: url("project://database/Assets/Art/Texture/pointer.png?fileID=2800000&guid=7e6c249b1dae14f918e70b7fd01d98c1&type=3#pointer"); border-left-color: rgba(0, 0, 0, 0.5); border-right-color: rgba(0, 0, 0, 0.5); border-top-color: rgba(0, 0, 0, 0.5); @@ -57,7 +96,7 @@ } .button:hover { - cursor: url("project://database/Assets/Art/Texture/pointer.png?fileID=2800000&guid=53954a4289b154ebdaf8f055996168eb&type=3#pointer"); + cursor: url("project://database/Assets/Art/Texture/pointer.png?fileID=2800000&guid=7e6c249b1dae14f918e70b7fd01d98c1&type=3#pointer"); border-left-color: rgba(0, 0, 0, 0.5); border-right-color: rgba(0, 0, 0, 0.5); border-top-color: rgba(0, 0, 0, 0.5); From 4cb9e3cb388793fae9ba41a48966efbc8590f4a9 Mon Sep 17 00:00:00 2001 From: Julian Cruz Date: Fri, 21 Nov 2025 16:47:26 +0100 Subject: [PATCH 2/7] hidding loading bar --- .../Assets/Art/UI/SceneLoadingInstructions.uxml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dots101/ContentManagement101/Assets/Art/UI/SceneLoadingInstructions.uxml b/Dots101/ContentManagement101/Assets/Art/UI/SceneLoadingInstructions.uxml index a73b2778f..357109ca7 100644 --- a/Dots101/ContentManagement101/Assets/Art/UI/SceneLoadingInstructions.uxml +++ b/Dots101/ContentManagement101/Assets/Art/UI/SceneLoadingInstructions.uxml @@ -7,6 +7,6 @@ - + From c96eb3bfeacc7ff12bc50191bda0bd579dc497e3 Mon Sep 17 00:00:00 2001 From: Julian Date: Mon, 24 Nov 2025 12:59:40 +0100 Subject: [PATCH 3/7] updating loading bar --- .../UpdateLoadingBarSystem.cs | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs index c097ff0af..6d3af630f 100644 --- a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs +++ b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs @@ -1,8 +1,8 @@ -using Unity.Entities; -using Unity.Entities.Content; +using UnityEngine; +using Unity.Entities; using Unity.Mathematics; -using UnityEngine; using UnityEngine.UIElements; +using Unity.Entities.Content; namespace ContentManagement.Sample { @@ -17,28 +17,18 @@ protected override void OnCreate() isInitialized = false; RequireForUpdate(); } - - private void UpdateStateCallback(ContentDeliveryGlobalState.ContentUpdateState contentUpdateState) - { - if (contentUpdateState >= ContentDeliveryGlobalState.ContentUpdateState.ContentReady) - { - // Track the state of your content and set when your content is ready to use - m_ProgressBar.style.display = DisplayStyle.None; - } - } protected override void OnUpdate() { - var progressBarUI = Object.FindAnyObjectByType(); - if (progressBarUI == null) - return; - if (!isInitialized) { + var progressBarUI = Object.FindAnyObjectByType(); + if (progressBarUI == null) + return; + isInitialized = true; m_ProgressBar = progressBarUI.ProgressBar; - m_ProgressBar.style.display = DisplayStyle.Flex; - ContentDeliveryGlobalState.RegisterForContentUpdateCompletion(UpdateStateCallback); + m_ProgressBar.style.display = DisplayStyle.Flex; } // Displays the loading bar used during the following loading and download steps: @@ -62,6 +52,10 @@ protected override void OnUpdate() } } } + else + { + m_ProgressBar.style.display = DisplayStyle.None; + } } } } \ No newline at end of file From 7a19f0b0f4916297f9ab95ba0bb4c322913e253f Mon Sep 17 00:00:00 2001 From: Julian Date: Mon, 24 Nov 2025 13:02:54 +0100 Subject: [PATCH 4/7] adding comments --- .../Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs index 6d3af630f..0e0478264 100644 --- a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs +++ b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs @@ -33,9 +33,9 @@ protected override void OnUpdate() // Displays the loading bar used during the following loading and download steps: // - DownloadingCatalogInfo - // - DownloadingCatalogs - // - DownloadingLocalCatalogs - // - DownloadingContentSet + // - 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) From f381a84affd3a2dca5448fef3ae1cd962acf5097 Mon Sep 17 00:00:00 2001 From: Julian Date: Mon, 24 Nov 2025 15:06:57 +0100 Subject: [PATCH 5/7] Clarifying readme file --- Dots101/ContentManagement101/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Dots101/ContentManagement101/README.md b/Dots101/ContentManagement101/README.md index 7caf43cb4..1cc48f903 100644 --- a/Dots101/ContentManagement101/README.md +++ b/Dots101/ContentManagement101/README.md @@ -196,7 +196,12 @@ When a scene is weakly referenced in a build, the original GameObject scene and ### Building the Player -When building the player, make sure to include subscene references. +For local workflows, please complete the following steps before building: +- Identify the subscenes whose archives need to be packaged. +- Add a scene to the **Build Profile** that references each required subscene, if they are not already referenced by another subscene in the Build Profile. +- Build the player. + +> This ensures that all necessary subscene data is included in the final output.
In the sample, there is a scene named `ContainerScene` which references both `LowFidelitySubscene` and `HighFidelitySubscene`. During the build process, Unity includes these references and packs them into the **StreamingAssets** folder for the player. From fa655897c9c6a20f44c6f10c9a253ffdeb42497d Mon Sep 17 00:00:00 2001 From: Julian Date: Mon, 24 Nov 2025 15:11:24 +0100 Subject: [PATCH 6/7] adding regions --- .../Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs index 0e0478264..c4ad5ef6c 100644 --- a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs +++ b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs @@ -20,6 +20,7 @@ protected override void OnCreate() protected override void OnUpdate() { +#region InitializingUI if (!isInitialized) { var progressBarUI = Object.FindAnyObjectByType(); @@ -30,7 +31,9 @@ protected override void OnUpdate() 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) @@ -44,7 +47,7 @@ protected override void OnUpdate() { if(downloadService.TotalBytes <= 0) continue; - + float progress = (float) downloadService.TotalDownloadedBytes / downloadService.TotalBytes; float normalizedProgress = math.max(0f, math.min(1f, progress)); m_ProgressBar.value = normalizedProgress; @@ -56,6 +59,7 @@ protected override void OnUpdate() { m_ProgressBar.style.display = DisplayStyle.None; } +#endregion } } } \ No newline at end of file From 501625b65ca3f8728f71cf35a0de6566f0f23c28 Mon Sep 17 00:00:00 2001 From: Julian Date: Mon, 24 Nov 2025 15:15:06 +0100 Subject: [PATCH 7/7] using clamp instead of manually clamping it --- .../Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs index c4ad5ef6c..b8f2fe4f5 100644 --- a/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs +++ b/Dots101/ContentManagement101/Assets/2. WeakSceneLoading/UpdateLoadingBarSystem.cs @@ -49,7 +49,7 @@ protected override void OnUpdate() continue; float progress = (float) downloadService.TotalDownloadedBytes / downloadService.TotalBytes; - float normalizedProgress = math.max(0f, math.min(1f, progress)); + float normalizedProgress = math.clamp(progress, 0f, 1f); m_ProgressBar.value = normalizedProgress; m_ProgressBar.title = $"[{ContentDeliveryGlobalState.CurrentContentUpdateState}]: {downloadService.Name} - {normalizedProgress*100}% "; }