| | 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.ScenesUiSystem; |
| | 10 | | using ECSSystems.VisibilitySystem; |
| | 11 | | using UnityEngine; |
| | 12 | | using UnityEngine.UIElements; |
| | 13 | | using ECS7System = System.Action; |
| | 14 | | using Environment = DCL.Environment; |
| | 15 | | using Object = UnityEngine.Object; |
| | 16 | |
|
| | 17 | | public class ECSSystemsController : IDisposable |
| | 18 | | { |
| | 19 | | private readonly IList<ECS7System> updateSystems; |
| | 20 | | private readonly IList<ECS7System> lateUpdateSystems; |
| | 21 | | private readonly IUpdateEventHandler updateEventHandler; |
| | 22 | | private readonly ECS7System componentWriteSystem; |
| | 23 | | private readonly ECS7System internalComponentWriteSystem; |
| | 24 | | private readonly ECSScenesUiSystem uiSystem; |
| | 25 | | private readonly GameObject hoverCanvas; |
| | 26 | | private readonly GameObject scenesUi; |
| | 27 | |
|
| 1 | 28 | | public ECSSystemsController(ECS7System componentWriteSystem, SystemsContext context) |
| | 29 | | { |
| 1 | 30 | | this.updateEventHandler = Environment.i.platform.updateEventHandler; |
| 1 | 31 | | this.componentWriteSystem = componentWriteSystem; |
| 1 | 32 | | this.internalComponentWriteSystem = context.internalEcsComponents.WriteSystemUpdate; |
| | 33 | |
|
| 1 | 34 | | var canvas = Resources.Load<GameObject>("ECSInteractionHoverCanvas"); |
| 1 | 35 | | hoverCanvas = Object.Instantiate(canvas); |
| 1 | 36 | | hoverCanvas.name = "_ECSInteractionHoverCanvas"; |
| 1 | 37 | | IECSInteractionHoverCanvas interactionHoverCanvas = hoverCanvas.GetComponent<IECSInteractionHoverCanvas>(); |
| | 38 | |
|
| 1 | 39 | | var scenesUiResource = Resources.Load<UIDocument>("ScenesUI"); |
| 1 | 40 | | var scenesUiDocument = Object.Instantiate(scenesUiResource); |
| 1 | 41 | | scenesUiDocument.name = "_ECSScenesUI"; |
| 1 | 42 | | scenesUi = scenesUiDocument.gameObject; |
| | 43 | |
|
| 1 | 44 | | uiSystem = new ECSScenesUiSystem(scenesUiDocument, |
| | 45 | | context.internalEcsComponents.uiContainerComponent, |
| | 46 | | DataStore.i.ecs7.scenes, Environment.i.world.state); |
| | 47 | |
|
| 1 | 48 | | updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, Update); |
| 1 | 49 | | updateEventHandler.AddListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate); |
| | 50 | |
|
| 1 | 51 | | updateSystems = new ECS7System[] |
| | 52 | | { |
| | 53 | | ECSTransformParentingSystem.Update, |
| | 54 | | ECSMaterialSystem.CreateSystem(context.componentGroups.texturizableGroup, |
| | 55 | | context.internalEcsComponents.texturizableComponent, context.internalEcsComponents.materialComponent), |
| | 56 | | ECSVisibilitySystem.CreateSystem(context.componentGroups.visibilityGroup, |
| | 57 | | context.internalEcsComponents.renderersComponent, context.internalEcsComponents.visibilityComponent), |
| | 58 | | ECSPointerInputSystem.CreateSystem( |
| | 59 | | context.internalEcsComponents.onPointerColliderComponent, |
| | 60 | | context.internalEcsComponents.inputEventResultsComponent, |
| | 61 | | context.pointerEvents, |
| | 62 | | interactionHoverCanvas, |
| | 63 | | Environment.i.world.state, |
| | 64 | | DataStore.i.ecs7), |
| | 65 | | ECSInputSenderSystem.CreateSystem(context.internalEcsComponents.inputEventResultsComponent, context.componen |
| | 66 | | uiSystem.Update |
| | 67 | | }; |
| | 68 | |
|
| 1 | 69 | | lateUpdateSystems = new ECS7System[] |
| | 70 | | { |
| | 71 | | ECSCameraEntitySystem.CreateSystem(context.componentWriter), |
| | 72 | | ECSPlayerTransformSystem.CreateSystem(context.componentWriter) |
| | 73 | | }; |
| 1 | 74 | | } |
| | 75 | |
|
| | 76 | | public void Dispose() |
| | 77 | | { |
| 1 | 78 | | updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, Update); |
| 1 | 79 | | updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate); |
| 1 | 80 | | uiSystem.Dispose(); |
| 1 | 81 | | Object.Destroy(hoverCanvas); |
| 1 | 82 | | Object.Destroy(scenesUi); |
| 1 | 83 | | } |
| | 84 | |
|
| | 85 | | private void Update() |
| | 86 | | { |
| 0 | 87 | | componentWriteSystem.Invoke(); |
| | 88 | |
|
| 0 | 89 | | int count = updateSystems.Count; |
| 0 | 90 | | for (int i = 0; i < count; i++) |
| | 91 | | { |
| 0 | 92 | | updateSystems[i].Invoke(); |
| | 93 | | } |
| | 94 | |
|
| 0 | 95 | | internalComponentWriteSystem.Invoke(); |
| 0 | 96 | | } |
| | 97 | |
|
| | 98 | | private void LateUpdate() |
| | 99 | | { |
| 0 | 100 | | int count = lateUpdateSystems.Count; |
| 0 | 101 | | for (int i = 0; i < count; i++) |
| | 102 | | { |
| 0 | 103 | | lateUpdateSystems[i].Invoke(); |
| | 104 | | } |
| 0 | 105 | | } |
| | 106 | | } |