| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.ECS7.InternalComponents; |
| | 3 | | using DCL.ECSComponents; |
| | 4 | | using DCL.ECSRuntime; |
| | 5 | | using DCL.Models; |
| | 6 | |
|
| | 7 | | namespace DCLPlugins.ECSComponents.Raycast |
| | 8 | | { |
| | 9 | | public class RaycastComponentHandler : IECSComponentHandler<PBRaycast> |
| | 10 | | { |
| | 11 | | private IInternalECSComponent<InternalRaycast> internalRaycastComponent; |
| | 12 | | private InternalRaycast internalRaycastModel = new InternalRaycast(); |
| | 13 | | private PBRaycast previousModel; |
| | 14 | |
|
| 28 | 15 | | public RaycastComponentHandler(IInternalECSComponent<InternalRaycast> internalRaycastComponent) |
| | 16 | | { |
| 28 | 17 | | this.internalRaycastComponent = internalRaycastComponent; |
| 28 | 18 | | } |
| | 19 | |
|
| | 20 | | public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) |
| | 21 | | { |
| 28 | 22 | | } |
| | 23 | |
|
| | 24 | | public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity) |
| | 25 | | { |
| 0 | 26 | | internalRaycastComponent.RemoveFor(scene, entity); |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBRaycast model) |
| | 30 | | { |
| 32 | 31 | | if (!model.Continuous && previousModel != null && !previousModel.Continuous |
| | 32 | | && previousModel.Timestamp == model.Timestamp) |
| 1 | 33 | | return; |
| | 34 | |
|
| 31 | 35 | | internalRaycastModel.raycastModel = model; |
| | 36 | |
|
| | 37 | | // Ray casting is done in ECSRaycastSystem for all entities with the InternalRaycast component |
| 31 | 38 | | internalRaycastComponent.PutFor(scene, entity, internalRaycastModel); |
| | 39 | |
|
| 31 | 40 | | previousModel = model; |
| 31 | 41 | | } |
| | 42 | | } |
| | 43 | | } |