| | 1 | | using System; |
| | 2 | | using DCL.Controllers; |
| | 3 | | using DCL.Models; |
| | 4 | |
|
| | 5 | | namespace DCLPlugins.DebugPlugins.Commons |
| | 6 | | { |
| | 7 | | public class WatchSceneHandler : IDisposable |
| | 8 | | { |
| | 9 | | private readonly IParcelScene scene; |
| | 10 | | private readonly ISceneListener sceneListener; |
| | 11 | |
|
| 14 | 12 | | public WatchSceneHandler(IParcelScene scene, ISceneListener sceneListener) |
| | 13 | | { |
| 14 | 14 | | this.scene = scene; |
| 14 | 15 | | this.sceneListener = sceneListener; |
| | 16 | |
|
| 14 | 17 | | scene.OnEntityAdded += SceneOnOnEntityAdded; |
| 14 | 18 | | scene.OnEntityRemoved += SceneOnOnEntityRemoved; |
| | 19 | |
|
| 14 | 20 | | if (scene.entities?.Values != null) |
| | 21 | | { |
| 24 | 22 | | foreach (IDCLEntity entity in scene.entities.Values) |
| | 23 | | { |
| 1 | 24 | | sceneListener.OnEntityAdded(entity); |
| | 25 | | } |
| | 26 | | } |
| 14 | 27 | | } |
| | 28 | |
|
| | 29 | | public void Dispose() |
| | 30 | | { |
| 14 | 31 | | scene.OnEntityAdded -= SceneOnOnEntityAdded; |
| 14 | 32 | | scene.OnEntityRemoved -= SceneOnOnEntityRemoved; |
| | 33 | |
|
| 14 | 34 | | sceneListener.Dispose(); |
| 14 | 35 | | } |
| | 36 | |
|
| | 37 | | private void SceneOnOnEntityAdded(IDCLEntity entity) |
| | 38 | | { |
| 17 | 39 | | sceneListener.OnEntityAdded(entity); |
| 17 | 40 | | } |
| | 41 | |
|
| | 42 | | private void SceneOnOnEntityRemoved(IDCLEntity entity) |
| | 43 | | { |
| 6 | 44 | | sceneListener.OnEntityRemoved(entity); |
| 6 | 45 | | } |
| | 46 | | } |
| | 47 | | } |