| | 1 | | using System; |
| | 2 | | using DCL.Controllers; |
| | 3 | | using DCL.ECS7.InternalComponents; |
| | 4 | | using DCL.ECSRuntime; |
| | 5 | | using DCL.Models; |
| | 6 | |
|
| | 7 | | public class RemoveOnConditionHandler<T> : IECSComponentHandler<T> where T : InternalComponent |
| | 8 | | { |
| | 9 | |
|
| | 10 | | private readonly IInternalECSComponent<T> thisComponent; |
| | 11 | | private readonly Func<T, bool> condition; |
| | 12 | |
|
| 106 | 13 | | public RemoveOnConditionHandler(Func<IInternalECSComponent<T>> componentGet, Func<T, bool> condition) |
| | 14 | | { |
| 106 | 15 | | this.thisComponent = componentGet(); |
| 106 | 16 | | this.condition = condition; |
| 106 | 17 | | } |
| | 18 | |
|
| 104 | 19 | | public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { } |
| | 20 | |
|
| 62 | 21 | | public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity) { } |
| | 22 | |
|
| | 23 | | public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, T model) |
| | 24 | | { |
| 158 | 25 | | if (condition(model)) |
| | 26 | | { |
| 8 | 27 | | thisComponent.RemoveFor(scene, entity); |
| | 28 | | } |
| 158 | 29 | | } |
| | 30 | | } |