| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL; |
| | 4 | | using ECSSystems.CameraSystem; |
| | 5 | | using ECSSystems.InputSenderSystem; |
| | 6 | | using ECSSystems.MaterialSystem; |
| | 7 | | using ECSSystems.PlayerSystem; |
| | 8 | | using ECSSystems.PointerInputSystem; |
| | 9 | | using ECSSystems.VisibilitySystem; |
| | 10 | | using UnityEngine; |
| | 11 | | using ECS7System = System.Action; |
| | 12 | | using Environment = DCL.Environment; |
| | 13 | | using Object = UnityEngine.Object; |
| | 14 | |
|
| | 15 | | public class ECSSystemsController : IDisposable |
| | 16 | | { |
| | 17 | | private readonly IList<ECS7System> updateSystems; |
| | 18 | | private readonly IList<ECS7System> lateUpdateSystems; |
| | 19 | | private readonly IUpdateEventHandler updateEventHandler; |
| | 20 | | private readonly ECS7System componentWriteSystem; |
| | 21 | | private readonly ECS7System internalComponentWriteSystem; |
| | 22 | | private readonly GameObject hoverCanvas; |
| | 23 | |
|
| 1 | 24 | | public ECSSystemsController(ECS7System componentWriteSystem, SystemsContext context) |
| | 25 | | { |
| 1 | 26 | | this.updateEventHandler = Environment.i.platform.updateEventHandler; |
| 1 | 27 | | this.componentWriteSystem = componentWriteSystem; |
| 1 | 28 | | this.internalComponentWriteSystem = context.internalEcsComponents.WriteSystemUpdate; |
| | 29 | |
|
| 1 | 30 | | var canvas = Resources.Load<GameObject>("ECSInteractionHoverCanvas"); |
| 1 | 31 | | hoverCanvas = Object.Instantiate(canvas); |
| 1 | 32 | | hoverCanvas.name = "_ECSInteractionHoverCanvas"; |
| 1 | 33 | | IECSInteractionHoverCanvas interactionHoverCanvas = hoverCanvas.GetComponent<IECSInteractionHoverCanvas>(); |
| | 34 | |
|
| 1 | 35 | | updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, Update); |
| 1 | 36 | | updateEventHandler.AddListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate); |
| | 37 | |
|
| 1 | 38 | | updateSystems = new ECS7System[] |
| | 39 | | { |
| | 40 | | ECSTransformParentingSystem.Update, |
| | 41 | | ECSMaterialSystem.CreateSystem(context.componentGroups.texturizableGroup, |
| | 42 | | context.internalEcsComponents.texturizableComponent, context.internalEcsComponents.materialComponent), |
| | 43 | | ECSVisibilitySystem.CreateSystem(context.componentGroups.visibilityGroup, |
| | 44 | | context.internalEcsComponents.renderersComponent, context.internalEcsComponents.visibilityComponent), |
| | 45 | | ECSPointerInputSystem.CreateSystem( |
| | 46 | | context.internalEcsComponents.onPointerColliderComponent, |
| | 47 | | context.internalEcsComponents.inputEventResultsComponent, |
| | 48 | | context.pointerEvents, |
| | 49 | | interactionHoverCanvas, |
| | 50 | | Environment.i.world.state, |
| | 51 | | DataStore.i.ecs7), |
| | 52 | | ECSInputSenderSystem.CreateSystem(context.internalEcsComponents.inputEventResultsComponent, context.componen |
| | 53 | | }; |
| | 54 | |
|
| 1 | 55 | | lateUpdateSystems = new ECS7System[] |
| | 56 | | { |
| | 57 | | ECSCameraEntitySystem.CreateSystem(context.componentWriter), |
| | 58 | | ECSPlayerTransformSystem.CreateSystem(context.componentWriter) |
| | 59 | | }; |
| 1 | 60 | | } |
| | 61 | |
|
| | 62 | | public void Dispose() |
| | 63 | | { |
| 1 | 64 | | updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, Update); |
| 1 | 65 | | updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate); |
| 1 | 66 | | Object.Destroy(hoverCanvas); |
| 1 | 67 | | } |
| | 68 | |
|
| | 69 | | private void Update() |
| | 70 | | { |
| 0 | 71 | | componentWriteSystem.Invoke(); |
| | 72 | |
|
| 0 | 73 | | int count = updateSystems.Count; |
| 0 | 74 | | for (int i = 0; i < count; i++) |
| | 75 | | { |
| 0 | 76 | | updateSystems[i].Invoke(); |
| | 77 | | } |
| | 78 | |
|
| 0 | 79 | | internalComponentWriteSystem.Invoke(); |
| 0 | 80 | | } |
| | 81 | |
|
| | 82 | | private void LateUpdate() |
| | 83 | | { |
| 0 | 84 | | int count = lateUpdateSystems.Count; |
| 0 | 85 | | for (int i = 0; i < count; i++) |
| | 86 | | { |
| 0 | 87 | | lateUpdateSystems[i].Invoke(); |
| | 88 | | } |
| 0 | 89 | | } |
| | 90 | | } |