forked from UrFriendKen/PlateUpDecorOnDemand
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStripRequestSystem.cs
More file actions
64 lines (63 loc) · 2.11 KB
/
StripRequestSystem.cs
File metadata and controls
64 lines (63 loc) · 2.11 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 Kitchen;
using KitchenData;
using KitchenMods;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Entities;
namespace KitchenApplianceShop
{
public class StripRequest
{
public bool ReturnDecor;
}
public class StripRequestSystem : GenericSystemBase, IModSystem
{
static Queue<StripRequest> requests = new Queue<StripRequest>();
EntityQuery DecorEvents;
protected override void Initialise()
{
base.Initialise();
DecorEvents = GetEntityQuery(typeof(CChangeDecorEvent));
}
protected override void OnUpdate()
{
using NativeArray<Entity> entities = DecorEvents.ToEntityArray(Allocator.Temp);
using NativeArray<CChangeDecorEvent> decorEvents = DecorEvents.ToComponentDataArray<CChangeDecorEvent>(Allocator.Temp);
if (requests.Count > 0)
{
StripRequest request = requests.Dequeue();
for (int i = 0; i < entities.Length; i++)
{
Entity entity = entities[i];
CChangeDecorEvent decorEvent = decorEvents[i];
if (request.ReturnDecor)
{
SpawnRequestSystem.Request<Decor>(decorEvent.DecorID, SpawnPositionType.Door);
}
decorEvent.DecorID = 0;
Set(entity, decorEvent);
}
return;
}
for (int i = entities.Length - 1; i > -1; i--)
{
Entity entity = entities[i];
CChangeDecorEvent decorEvent = decorEvents[i];
if (decorEvent.DecorID == 0)
{
EntityManager.DestroyEntity(entity);
}
}
}
public static void Request(bool returnDecor = true)
{
if (GameInfo.CurrentScene == SceneType.Kitchen)
{
requests.Enqueue(new StripRequest()
{
ReturnDecor = returnDecor
});
}
}
}
}