示例#1
0
        private void UpdateEntityInformation_EditorThread(CInspectorSceneComponentViewModel sceneComponentRoot, List <CInspectorEntityComponentViewModel> entityComponents, CInspectorEntityViewModel entity)
        {
            SceneComponents.Clear();
            EntityComponents.Clear();
            EntityInfo.Clear();

            if (sceneComponentRoot != null)
            {
                SceneComponents.Add(sceneComponentRoot);
            }

            if (entityComponents != null)
            {
                EntityComponents = new ObservableCollection <CInspectorEntityComponentViewModel>(entityComponents);
            }

            if (entity != null)
            {
                EntityInfo.Add(entity);
            }
        }
示例#2
0
        private void UpdateEntityInformation_EngineThread(SEntityId entityId, bool bReselectTarget = false)
        {
            void CreateViewModel(CSceneComponent component, CInspectorSceneComponentViewModel parent, CEntity owner)
            {
                if (component.Owner != owner || !component.ShowInInspector || component.MarkedForDestruction)
                {
                    return;
                }

                SEntityComponentId id = new SEntityComponentId(component, false);

                CInspectorSceneComponentViewModel vm = new CInspectorSceneComponentViewModel(this, component.Name, id, "sceneComponent");

                parent.Children.Add(vm);

                foreach (var child in component.Children)
                {
                    CreateViewModel(child, vm, owner);
                }
            }

            CEntity entity = entityId.GetEntity();

            if (entity != null)
            {
                CInspectorEntityViewModel                 entityInfo           = null;
                CInspectorSceneComponentViewModel         sceneComponentsInfo  = null;
                List <CInspectorEntityComponentViewModel> entityComponentsInfo = null;

                sceneComponentsInfo = null;
                if (entity.RootComponent != null)
                {
                    sceneComponentsInfo = new CInspectorSceneComponentViewModel(this, entity.RootComponent.Name, new SEntityComponentId(entity.RootComponent, false), "sceneComponent");
                    foreach (var child in entity.RootComponent.Children)
                    {
                        CreateViewModel(child, sceneComponentsInfo, entity);
                    }
                }

                List <CEntityComponent> components = new List <CEntityComponent>(8);
                entityComponentsInfo = new List <CInspectorEntityComponentViewModel>(4);
                entity.GetComponents(components);

                for (int i = components.Count - 1; i >= 0; i--)
                {
                    if (!(components[i] is CSceneComponent) && components[i].ShowInInspector && !components[i].MarkedForDestruction)
                    {
                        entityComponentsInfo.Add(new CInspectorEntityComponentViewModel(this, components[i].Name, new SEntityComponentId(components[i], false)));
                    }
                }

                entityInfo = new CInspectorEntityViewModel(this, entity.Name, new SEntityId(entity.Id));

                string entityName = entity.Name;

                Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
                {
                    m_view?.LockInspector(false);
                    UpdateEntityInformation_EditorThread(sceneComponentsInfo, entityComponentsInfo, entityInfo);

                    m_entityName = entityName;
                    RaisePropertyChanged(nameof(EntityName));
                    m_view.SetEntityName(entityName);

                    if (bReselectTarget)
                    {
                        CWorkspace.Instance.SetSelectedObject(m_selectedObject, true);
                    }
                }));
            }
            else
            {
                //Clear component list when selecting invalid entity
                Application.Current.Dispatcher.BeginInvoke((Action)(() =>
                {
                    UpdateEntityInformation_EditorThread(null, null, null);
                }));
            }
        }