| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.ECS7; |
| | 3 | | using DCL.ECS7.ComponentWrapper.Generic; |
| | 4 | | using DCL.ECS7.InternalComponents; |
| | 5 | | using DCL.ECSComponents; |
| | 6 | | using DCL.Models; |
| | 7 | | using System.Collections.Generic; |
| | 8 | |
|
| | 9 | | namespace ECSSystems.GltfContainerLoadingStateSystem |
| | 10 | | { |
| | 11 | | public class GltfContainerLoadingStateSystem |
| | 12 | | { |
| | 13 | | private readonly IInternalECSComponent<InternalGltfContainerLoadingState> gltfContainerLoadingStateComponent; |
| | 14 | | private readonly IReadOnlyDictionary<int, ComponentWriter> componentsWriter; |
| | 15 | | private readonly WrappedComponentPool<IWrappedComponent<PBGltfContainerLoadingState>> componentPool; |
| | 16 | |
|
| 7 | 17 | | public GltfContainerLoadingStateSystem(IReadOnlyDictionary<int, ComponentWriter> componentsWriter, |
| | 18 | | WrappedComponentPool<IWrappedComponent<PBGltfContainerLoadingState>> componentPool, |
| | 19 | | IInternalECSComponent<InternalGltfContainerLoadingState> gltfContainerLoadingStateComponent) |
| | 20 | | { |
| 7 | 21 | | this.componentsWriter = componentsWriter; |
| 7 | 22 | | this.gltfContainerLoadingStateComponent = gltfContainerLoadingStateComponent; |
| 7 | 23 | | this.componentPool = componentPool; |
| 7 | 24 | | } |
| | 25 | |
|
| | 26 | | public void Update() |
| | 27 | | { |
| 6 | 28 | | var components = gltfContainerLoadingStateComponent.GetForAll(); |
| | 29 | |
|
| 24 | 30 | | for (int i = 0; i < components.Count; i++) |
| | 31 | | { |
| 6 | 32 | | var model = components[i].value.model; |
| | 33 | |
|
| 6 | 34 | | if (!model.dirty) |
| | 35 | | continue; |
| | 36 | |
|
| 6 | 37 | | IParcelScene scene = components[i].value.scene; |
| 6 | 38 | | IDCLEntity entity = components[i].value.entity; |
| | 39 | |
|
| 6 | 40 | | if (!componentsWriter.TryGetValue(scene.sceneData.sceneNumber, out var writer)) |
| | 41 | | continue; |
| | 42 | |
|
| 6 | 43 | | if (model.GltfContainerRemoved) |
| | 44 | | { |
| 1 | 45 | | writer.Remove(entity.entityId, ComponentID.GLTF_CONTAINER_LOADING_STATE); |
| | 46 | | } |
| | 47 | | else |
| | 48 | | { |
| 5 | 49 | | var componentPooled = componentPool.Get(); |
| 5 | 50 | | var componentModel = componentPooled.WrappedComponent.Model; |
| 5 | 51 | | componentModel.CurrentState = model.LoadingState; |
| | 52 | |
|
| 5 | 53 | | writer.Put(entity.entityId, ComponentID.GLTF_CONTAINER_LOADING_STATE, componentPooled); |
| | 54 | | } |
| | 55 | | } |
| 6 | 56 | | } |
| | 57 | | } |
| | 58 | | } |