Adding Loading bar sample by julianunity · Pull Request #306 · Unity-Technologies/EntityComponentSystemSamples · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ public void OnCreate(ref SystemState state)
state.RequireForUpdate<RemoteContent>();
state.RequireForUpdate<HighLowWeakScene>();
initialized = false;
ContentDeliveryGlobalState.RegisterForContentUpdateCompletion(UpdateStateCallback);
}

private void UpdateStateCallback(ContentDeliveryGlobalState.ContentUpdateState contentUpdateState)
{
Debug.Log($"<color=green>Content Delivery Global State:</color> {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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<engine:Label text="Follow these step-by-step instructions to understand how this scene works:&#10;&#10;&lt;b&gt;&lt;color=magenta&gt;1.&lt;/color&gt;&lt;/b&gt; Search &lt;b&gt;&lt;color=#A4A449&gt;WeakSceneList&lt;/color&gt;&lt;/b&gt; for more details &#10; about how to make the content.&#10;&lt;b&gt;&lt;color=magenta&gt;2.&lt;/color&gt;&lt;/b&gt; Check &lt;b&gt;&lt;color=#A4A449&gt;WeakSceneAuthoring&lt;/color&gt;&lt;/b&gt; or&#10; &lt;b&gt;&lt;color=#A4A449&gt;WeakSceneLoading System&lt;/color&gt;&lt;/b&gt; to inspect how &#10; to assign references to an entity.&#10;&lt;b&gt;&lt;color=magenta&gt;3.&lt;/color&gt;&lt;/b&gt; Switch to &lt;b&gt;&lt;color=#A4A449&gt;[Platform] WeakSceneLoading &#10; profile&lt;/color&gt;&lt;/b&gt; before building the player. " style="-unity-font-definition: url(&quot;project://database/Assets/Art/Fonts/ShareTechMono-Regular/ShareTechMono-Regular.ttf?fileID=12800000&amp;guid=ba952712555b503458be5a0ebcad7e60&amp;type=3#ShareTechMono-Regular&quot;); color: rgb(255, 255, 255); font-size: 20px; white-space: pre-wrap; width: 530px; padding-bottom: 12px; margin-bottom: 10px; border-bottom-width: 1px; border-bottom-color: rgba(133, 133, 133, 0.5);" />
<engine:Label text="&lt;b&gt;&lt;color=#A4A449&gt;Note:&lt;/color&gt;&lt;/b&gt; Content management relies on subscenes to bake content references into entities. You’ll find scenes that contain only subscenes; this pattern allows for direct scene loading without runtime entity creation, as everything is pre-built during content catalog export." style="-unity-font-definition: url(&quot;project://database/Assets/Art/Fonts/ShareTechMono-Regular/ShareTechMono-Regular.ttf?fileID=12800000&amp;guid=ba952712555b503458be5a0ebcad7e60&amp;type=3#ShareTechMono-Regular&quot;); color: rgb(255, 255, 255); font-size: 20px; white-space: pre-wrap; width: 518px;" />
</engine:VisualElement>
<engine:VisualElement style="flex-grow: 1; justify-content: center; flex-direction: row;">
<engine:ProgressBar value="0" high-value="1" name="progress-bar" style="width: 500px; align-self: center; display: none;" />
</engine:VisualElement>
</engine:UXML>
43 changes: 41 additions & 2 deletions Dots101/ContentManagement101/Assets/Art/UI/Style.uss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion Dots101/ContentManagement101/README.md