forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIInteropSystem.cs
More file actions
56 lines (49 loc) · 1.69 KB
/
Copy pathUIInteropSystem.cs
File metadata and controls
56 lines (49 loc) · 1.69 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
using Unity.Collections;
using Unity.Entities;
using UnityEditor.Rendering;
using UnityEngine;
namespace Streaming.AssetManagement
{
public partial struct UIInteropSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<References>();
state.EntityManager.AddComponent<UIInterop>(state.SystemHandle);
state.EntityManager.SetComponentData(state.SystemHandle, new UIInterop());
}
public void OnUpdate(ref SystemState state)
{
var ui = state.EntityManager.GetComponentData<UIInterop>(state.SystemHandle);
if (ui.LoadButton == null)
{
ui.LoadButton = GameObject.FindObjectOfType<LoadButton>();
if (ui.LoadButton == null)
{
return;
}
}
if (!ui.LoadButton.Toggle)
{
return;
}
ui.LoadButton.Toggle = false;
var unloadQuery = SystemAPI.QueryBuilder().WithAll<References, Loading>().WithNone<RequestUnload>().Build();
var loadQuery = SystemAPI.QueryBuilder().WithAll<References, RequestUnload>().WithNone<Loading>().Build();
if (ui.LoadButton.Loaded)
{
state.EntityManager.AddComponent<RequestUnload>(unloadQuery);
ui.LoadButton.Loaded = false;
}
else
{
state.EntityManager.RemoveComponent<RequestUnload>(loadQuery);
ui.LoadButton.Loaded = true;
}
}
}
public class UIInterop : IComponentData
{
public LoadButton LoadButton;
}
}