public void UpdateOutliner(CHierarchyEntry root)
        {
            void AddOutlinerEntity(CHierarchyEntry entity, COutlinerEntityViewModel parent)
            {
                COutlinerEntityViewModel viewModel = new COutlinerEntityViewModel(this, new SEntityId(entity.EntityId), entity.Label, parent, -1);

                parent.Children.Add(viewModel);

                foreach (var child in entity.Children)
                {
                    AddOutlinerEntity(child, viewModel);
                }
            }

            m_entities.Clear();

            for (int i = 0, count = root.Children.Count; i < count; i++)
            {
                CHierarchyEntry child = root.Children[i];

                COutlinerEntityViewModel rootEntity = new COutlinerEntityViewModel(this, new SEntityId(child.EntityId), child.Label, null, i);
                foreach (var hierarchyChild in child.Children)
                {
                    AddOutlinerEntity(hierarchyChild, rootEntity);
                }
                m_entities.Add(rootEntity);
            }

            CWorkspace.Instance.SetSelectedObject(CWorkspace.Instance.SelectedEditableObject, true);
        }
        public override void PostWorldLoad()
        {
            base.PostWorldLoad();

            CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
            {
                Action <CEntity> callback = (entity) =>
                {
                    CHierarchyEntry root = EditorHelpers.FillLevelHierarchy();
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        UpdateOutliner(root);
                    });
                };

                Action <CAssetReference <CLevelAsset>, CLevel> levelChanged = (levelAsset, level) =>
                {
                    CHierarchyEntry root           = EditorHelpers.FillLevelHierarchy();
                    SEntityComponentId newPickerId = SpawnScenePicker_EngineThread(CEngine.Instance.CurrentWorld);
                    CWorkspace.Instance.PostLevelLoad(levelAsset);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        PickingComponentId = newPickerId;
                        UpdateOutliner(root);
                    });
                };

                CWorld currentWorld              = CEngine.Instance.CurrentWorld;
                currentWorld.OnEntitySpawned    += callback;
                currentWorld.OnEntityDestroyed  += callback;
                currentWorld.OnEntityRevived    += callback;
                currentWorld.OnLevelChanged     += levelChanged;
                currentWorld.OnHierarchyChanged += (child, oldParent, newParent) =>
                {
                    if (child == child.Owner?.RootComponent)
                    {
                        callback(null);
                    }
                };
                SEntityComponentId pickerId = SpawnScenePicker_EngineThread(currentWorld);
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { PickingComponentId = pickerId; }));

                CScenePickingComponent.OnComponentPicked += (component) =>
                {
                    if (component == null)
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            CWorkspace.Instance.SetSelectedObject(null);
                        });
                    }
                    else
                    {
                        CEntity entity          = component.Owner;
                        CEditableObject editObj = null;

                        if (entity.RootComponent == null)
                        {
                            editObj = new CEditableObject(new SEntityId(entity.Id));
                        }
                        else
                        {
                            editObj = new CEditableObject(new SEntityComponentId(entity.RootComponent));
                        }

                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                        {
                            CWorkspace.Instance.SetSelectedObject(editObj);
                        }));
                    }
                };

                callback(null);
            });
        }