-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathLoadingRemoteCatalogSystem.cs
More file actions
64 lines (56 loc) · 2.92 KB
/
LoadingRemoteCatalogSystem.cs
File metadata and controls
64 lines (56 loc) · 2.92 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
using System.IO;
using Unity.Entities;
using Unity.Entities.Content;
using UnityEngine;
namespace ContentManagement.Sample
{
/// <summary>
/// Enables the Content Management API to retrieve content from a remote source,
/// load it into memory, and then connect all references.
/// </summary>
[UpdateBefore(typeof(WeakSceneLoadingSystem))]
public partial struct LoadingRemoteCatalogSystem : ISystem
{
private bool initialized;
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)
{
if (!initialized)
{
var settings = SystemAPI.GetSingleton<RemoteContent>();
initialized = true;
var contentPath = Path.Combine( settings.URL.ToString(), WeakSceneListScriptableObject.ContentDir) + "/";
Debug.Log($"<color=green>Loading Content Delivery From Remote source:</color>{contentPath}");
// When the ENABLE_CONTENT_DELIVERY scriptable define is set (https://docs.unity3d.com/6000.2/Documentation/Manual/custom-scripting-symbols.html),
// the content catalog must be initialized before any assets are loaded.
// We specify the remote content path, the local cache path (for storing downloaded content),
// and prevent unnecessary downloads by only fetching content if needed.
// The content set name refers to the specific content bundle defined during the build process.
RuntimeContentSystem.LoadContentCatalog(contentPath, WeakSceneListScriptableObject.CachePath,
WeakSceneListScriptableObject.ContentSetName, true);
}
var entityQuery = SystemAPI.QueryBuilder().WithAll<ContentIsReady>().Build();
if (entityQuery.CalculateEntityCount() < 1 &&
ContentDeliveryGlobalState.CurrentContentUpdateState >=
ContentDeliveryGlobalState.ContentUpdateState.ContentReady)
{
Debug.Log($"Content Delivery is <color=green>Ready From Remote</color> source");
state.EntityManager.CreateEntity(typeof(ContentIsReady));
}
}
}
}