예제 #1
0
        public void OnEntityAdded(Entity entity)
        {
            var treeItem = new EntityTreeItem(entity);

            if (entity.Transform.Parent != null)
            {
                var parentEntity = entity.GetParent();
                var parent       = FindEntityInTree(Entities, parentEntity);
                if (parent == null)
                {
                    OnEntityAdded(parentEntity); //add non existent parent(s)
                }
                //add child to now exiting parent
                parent = FindEntityInTree(Entities, parentEntity);
                if (!parent.Children.Any(ti => ti.Entity == entity))
                {
                    parent.Children.Add(treeItem);
                }
            }
            else
            {
                if (!Entities.Any(ti => ti.Entity == entity))
                {
                    Entities.Add(treeItem);
                }
            }
        }
예제 #2
0
        public SceneItem(EntityTreeItem sceneRoot)
        {
            Entities = sceneRoot.Children;
            TreeRoot = sceneRoot;

            this.scene = (Scene)sceneRoot.Entity;
        }
        private void entityTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            selectedEntity = null;
            ClearComponentView();

            if (e == null || e.NewValue == null)
            {
                return;
            }

            var entity = e.NewValue as EntityTreeItem;

            if (entity == null)
            {
                return;
            }

            selectedEntity = entity;

            // Build component view and add components changed event handling.
            // Spin up watcher thread to watch for component value changes.

            if (entity.Entity.GetType() == typeof(Entity))
            {
                Entity actualEntity = (Entity)entity.Entity;
                foreach (var component in actualEntity.Components)
                {
                    OnComponentAdded(component);
                }
            }

            componentsInitialized = true;
        }
        public void BuildTree()
        {
            Entities.Clear();
            Scenes.Clear();

            //Add in the root scene
            EntityTreeItem treeRoot = new EntityTreeItem(sceneInstance.RootScene);

            Scenes.Add(new SceneItem(treeRoot));
            Entities.Add(treeRoot);

            //Loop through any children
            foreach (var s in sceneInstance.RootScene.Children)
            {
                Children_CollectionChanged(null,
                                           new Stride.Core.Collections.TrackingCollectionChangedEventArgs(
                                               System.Collections.Specialized.NotifyCollectionChangedAction.Add, s, null, 0, false)
                                           );
            }

            //Then add the entities of the root scene
            foreach (var entity in sceneInstance.RootScene.Entities)
            {
                OnEntityAdded(entity);
            }

            //Expand the root of the tree to open it
            //TODO: Work out how the hell to do this
        }
        private void Children_CollectionChanged(object sender, Stride.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 Stride.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;
            }
        }