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