| | 1 | | using DCL.Models; |
| | 2 | |
|
| | 3 | | namespace DCLPlugins.DebugPlugins.Commons |
| | 4 | | { |
| | 5 | | public class WatchEntityShapeHandler |
| | 6 | | { |
| | 7 | | private readonly IDCLEntity entity; |
| | 8 | | private readonly IShapeListener listener; |
| | 9 | |
|
| 20 | 10 | | public WatchEntityShapeHandler(IDCLEntity entity, IShapeListener listener) |
| | 11 | | { |
| 20 | 12 | | this.entity = entity; |
| 20 | 13 | | this.listener = listener; |
| | 14 | |
|
| 20 | 15 | | if (entity.meshesInfo.currentShape != null) |
| | 16 | | { |
| 17 | 17 | | OnShapeUpdated(entity); |
| | 18 | | } |
| | 19 | |
|
| 20 | 20 | | entity.OnMeshesInfoUpdated += OnShapeUpdated; |
| 20 | 21 | | entity.OnMeshesInfoCleaned += OnShapeCleaned; |
| 20 | 22 | | } |
| | 23 | |
|
| | 24 | | public void Dispose() |
| | 25 | | { |
| 20 | 26 | | entity.OnMeshesInfoUpdated -= OnShapeUpdated; |
| 20 | 27 | | entity.OnMeshesInfoCleaned -= OnShapeCleaned; |
| | 28 | |
|
| 20 | 29 | | listener.Dispose(); |
| 20 | 30 | | } |
| | 31 | |
|
| | 32 | | private void OnShapeUpdated(IDCLEntity entity) |
| | 33 | | { |
| 19 | 34 | | if (entity.meshesInfo.currentShape != null |
| | 35 | | && entity.meshesInfo.meshRootGameObject != null) |
| | 36 | | { |
| 18 | 37 | | listener.OnShapeUpdated(entity); |
| | 38 | | } |
| 19 | 39 | | } |
| | 40 | |
|
| | 41 | | private void OnShapeCleaned(IDCLEntity entity) |
| | 42 | | { |
| 2 | 43 | | listener.OnShapeCleaned(entity); |
| 2 | 44 | | } |
| | 45 | | } |
| | 46 | | } |