private void OnEntityRemoved(Entity entity) { Log($"Entity {entity.Name} removed."); SceneItem sceneUpdated = FindSceneInTree(Scenes, entity.Scene); if (sceneUpdated != null) { sceneUpdated.OnEntityRemoved(entity); } }
private void Children_CollectionChanged(object sender, Xenko.Core.Collections.TrackingCollectionChangedEventArgs e) { switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: Scene scene = (Scene)e.Item; Scene parentScene = scene.Parent; if (parentScene != null) { SceneItem parentInTree = FindSceneInTree(Scenes, parentScene); if (parentInTree != null) { //Add in the scene into the tree EntityTreeItem newSceneInTree = new EntityTreeItem(scene); Scenes.Add(new SceneItem(newSceneInTree)); parentInTree.Entities.Add(newSceneInTree); foreach (var entity in scene.Entities) { OnEntityAdded(entity); } //In the unlikely event that additional child scenes have been added before XLE //pickup up the event, loop recruisevly foreach (var s in scene.Children) { Children_CollectionChanged(null, new Xenko.Core.Collections.TrackingCollectionChangedEventArgs( System.Collections.Specialized.NotifyCollectionChangedAction.Add, s, null, 0, false) ); } } } break; case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: //Trigger a rebuild of the tree //Bit of task trickery here as the this even fires well before actual unloading var t = Task.Factory.StartNew(() => { Task.Delay(500).Wait(); //TODO: 500 is totally a magic number here BuildTree(); }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext() ); break; case System.Collections.Specialized.NotifyCollectionChangedAction.Replace: break; case System.Collections.Specialized.NotifyCollectionChangedAction.Move: break; case System.Collections.Specialized.NotifyCollectionChangedAction.Reset: break; default: break; } }