forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUISystem.cs
More file actions
59 lines (53 loc) · 2.22 KB
/
Copy pathUISystem.cs
File metadata and controls
59 lines (53 loc) · 2.22 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
using Streaming.SceneManagement.SceneState;
using Unity.Collections;
using Unity.Entities;
using Unity.Scenes;
using SceneReference = Unity.Entities.SceneReference;
namespace Streaming.SceneManagement.SectionLoading
{
public partial struct UISystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<SceneReference>();
}
public void OnUpdate(ref SystemState state)
{
if (SectionUI.Singleton == null)
{
return;
}
var ui = SectionUI.Singleton;
var sectionQuery = SystemAPI.QueryBuilder().WithAll<ResolvedSectionEntity>().Build();
var entities = sectionQuery.ToEntityArray(Allocator.Temp);
if (entities.Length <= 0 || !state.EntityManager.HasBuffer<ResolvedSectionEntity>(entities[0]))
{
return;
}
var sectionEntities = state.EntityManager.GetBuffer<ResolvedSectionEntity>(entities[0]);
ui.CreateRows(sectionEntities.Length);
// Update the information for each scene UI
for (int index = 0; index < sectionEntities.Length; ++index)
{
var entity = sectionEntities[index].SectionEntity;
var sectionState = SceneSystem.GetSectionStreamingState(state.WorldUnmanaged, entity);
bool disabled = state.EntityManager.HasComponent<DisableSceneResolveAndLoad>(entity);
ui.UpdateRow(index, disabled, sectionState);
}
if (ui.GetAction(out var rowIndex))
{
var entity = sectionEntities[rowIndex].SectionEntity;
var sectionState = SceneSystem.GetSectionStreamingState(state.WorldUnmanaged, entity);
if (sectionState != SceneSystem.SectionStreamingState.Unloaded &&
sectionState != SceneSystem.SectionStreamingState.UnloadRequested)
{
state.EntityManager.RemoveComponent<RequestSceneLoaded>(entity);
}
else
{
state.EntityManager.AddComponent<RequestSceneLoaded>(entity);
}
}
}
}
}