| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.ECS7.InternalComponents; |
| | 4 | | using DCL.ECSRuntime; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace ECSSystems.VisibilitySystem |
| | 8 | | { |
| | 9 | | public static class ECSVisibilitySystem |
| | 10 | | { |
| | 11 | | private class State |
| | 12 | | { |
| | 13 | | public IECSReadOnlyComponentsGroup<InternalRenderers, InternalVisibility> componentsGroup; |
| | 14 | | public IInternalECSComponent<InternalRenderers> renderersComponent; |
| | 15 | | public IInternalECSComponent<InternalVisibility> visibilityComponent; |
| | 16 | |
|
| | 17 | | } |
| | 18 | |
|
| | 19 | | public static Action CreateSystem(IECSReadOnlyComponentsGroup<InternalRenderers, InternalVisibility> componentsG |
| | 20 | | IInternalECSComponent<InternalRenderers> renderersComponent, |
| | 21 | | IInternalECSComponent<InternalVisibility> visibilityComponent) |
| | 22 | | { |
| 2 | 23 | | var state = new State() |
| | 24 | | { |
| | 25 | | componentsGroup = componentsGroup, |
| | 26 | | renderersComponent = renderersComponent, |
| | 27 | | visibilityComponent = visibilityComponent |
| | 28 | | }; |
| 6 | 29 | | return () => Update(state); |
| | 30 | | } |
| | 31 | |
|
| | 32 | | private static void Update(State state) |
| | 33 | | { |
| 4 | 34 | | var componentGroup = state.componentsGroup.group; |
| | 35 | |
|
| 24 | 36 | | for (int i = 0; i < componentGroup.Count; i++) |
| | 37 | | { |
| 8 | 38 | | var entityData = componentGroup[i]; |
| 8 | 39 | | InternalRenderers renderersModel = entityData.componentData1.model; |
| 8 | 40 | | InternalVisibility visibilityModel = entityData.componentData2.model; |
| | 41 | |
|
| | 42 | |
|
| | 43 | | // if neither component has changed then we skip this entity |
| 8 | 44 | | if (!renderersModel.dirty && !visibilityModel.dirty) |
| | 45 | | continue; |
| | 46 | |
|
| 4 | 47 | | IList<Renderer> renderers = renderersModel.renderers; |
| | 48 | |
|
| 16 | 49 | | for (int j = 0; j < renderers.Count; j++) |
| | 50 | | { |
| 4 | 51 | | Renderer renderer = renderers[j]; |
| 4 | 52 | | renderer.enabled = visibilityModel.visible; |
| | 53 | | } |
| | 54 | | } |
| 4 | 55 | | } |
| | 56 | | } |
| | 57 | | } |