forked from Unity-Technologies/ECS-Network-Racing-Sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadingScreenSystem.cs
More file actions
73 lines (65 loc) · 2.67 KB
/
Copy pathLoadingScreenSystem.cs
File metadata and controls
73 lines (65 loc) · 2.67 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
66
67
68
69
70
71
72
73
using Unity.Burst;
using Unity.Scenes;
using Unity.Entities.Racing.Common;
namespace Unity.Entities.Racing.Gameplay
{
/// <summary>
/// Update the GameLoadInfo singleton with loaded sections number
/// </summary>
[BurstCompile]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ServerSimulation)]
public partial struct LoadingScreenSystem : ISystem
{
private EntityQuery m_SceneSections;
private Entity m_GameLoadInfoEntity;
private bool m_ShouldShowLoadingScreen;
public void OnCreate(ref SystemState state)
{
// Query only scene sections that are requested to load or loaded
m_SceneSections = state.GetEntityQuery(
ComponentType.ReadOnly<SceneSectionData>(),
ComponentType.ReadOnly<RequestSceneLoaded>());
m_GameLoadInfoEntity = state.EntityManager.CreateEntity(typeof(GameLoadInfo));
state.RequireForUpdate<GameLoadInfo>();
m_ShouldShowLoadingScreen = true;
}
public void OnDestroy(ref SystemState state)
{
}
public void OnUpdate(ref SystemState state)
{
var sceneSectionEntities = m_SceneSections.ToEntityArray(state.WorldUpdateAllocator);
var loadedSceneSections = 0;
foreach (var entity in sceneSectionEntities)
{
if (SceneSystem.IsSectionLoaded(state.WorldUnmanaged, entity))
{
loadedSceneSections++;
}
}
var gameLoadInfo = new GameLoadInfo
{
TotalSceneSections = sceneSectionEntities.Length,
LoadedSceneSections = loadedSceneSections
};
state.EntityManager.SetComponentData(m_GameLoadInfoEntity, gameLoadInfo);
sceneSectionEntities.Dispose(state.Dependency);
if (gameLoadInfo.IsLoaded)
{
// Create EnableGoInGame Entity when all the sub-scenes are loaded
state.EntityManager.SetComponentEnabled<GameLoadInfo>(m_GameLoadInfoEntity, false);
}
else if (LoadingScreen.Instance != null && m_ShouldShowLoadingScreen)
{
LoadingScreen.Instance.ShowLoadingScreen(true);
}
// Disable the system when everything is loaded
if (gameLoadInfo.IsLoaded && LoadingScreen.Instance != null && m_ShouldShowLoadingScreen)
{
// Disable Loading Screen
m_ShouldShowLoadingScreen = false;
LoadingScreen.Instance.ShowLoadingScreen(false);
}
}
}
}