/// <summary> /// Initializes a new instance of the <see cref="EntityHierarchyEditorViewModel"/> class. /// </summary> /// <param name="asset">The asset related to this editor.</param> /// <param name="controllerFactory">A factory to create the associated <see cref="IEditorGameController"/>.</param> protected EntityHierarchyEditorViewModel([NotNull] EntityHierarchyViewModel asset, [NotNull] Func <GameEditorViewModel, IEditorGameController> controllerFactory) : base(asset, controllerFactory) { Controller.Loader.AssetLoading += (s, e) => asset.Dispatcher.InvokeAsync(() => CompilingAssets = e.ContentLoadingCount > 0); Controller.Loader.AssetLoaded += (s, e) => asset.Dispatcher.InvokeAsync(() => CompilingAssets = e.ContentLoadingCount > 0); Camera = new EditorCameraViewModel(ServiceProvider, Controller); Transform = new EntityTransformationViewModel(ServiceProvider, Controller); Grid = new EditorGridViewModel(ServiceProvider, Controller); Navigation = new EditorNavigationViewModel(ServiceProvider, Controller, this); Lighting = new EditorLightingViewModel(ServiceProvider, Controller, this); Rendering = new EditorRenderingViewModel(ServiceProvider, Controller); EntityGizmos = new EntityGizmosViewModel(ServiceProvider, Controller); CreateEntityCommand = new AnonymousTaskCommand <IEntityFactory>(ServiceProvider, x => CreateEntity(true, x, ActiveRoot ?? HierarchyRoot)); CreateEntityInRootCommand = new AnonymousTaskCommand <IEntityFactory>(ServiceProvider, x => CreateEntity(false, x, ActiveRoot ?? HierarchyRoot)); CreateFolderInRootCommand = new AnonymousCommand <IEntityFactory>(ServiceProvider, x => CreateFolder(HierarchyRoot.Asset, ActiveRoot ?? HierarchyRoot, true)); CreateEntityInSelectionCommand = new AnonymousTaskCommand <IEntityFactory>(ServiceProvider, x => CreateEntity(false, x, (EntityHierarchyItemViewModel)SelectedContent.FirstOrDefault() ?? ActiveRoot ?? HierarchyRoot)); CreateFolderInSelectionCommand = new AnonymousCommand <IEntityFactory>(ServiceProvider, x => { var element = (EntityHierarchyItemViewModel)SelectedContent.FirstOrDefault() ?? ActiveRoot ?? HierarchyRoot; CreateFolder(element.Asset, element, true); }); OpenPrefabEditorCommand = new AnonymousCommand(ServiceProvider, OpenPrefabEditor); SelectPrefabCommand = new AnonymousCommand(ServiceProvider, SelectPrefab); SetActiveRootCommand = new AnonymousCommand(ServiceProvider, SetActiveRoot); BreakLinkToPrefabCommand = new AnonymousCommand(ServiceProvider, BreakLinkToPrefab); CreatePrefabFromSelectionCommand = new AnonymousCommand(ServiceProvider, CreatePrefabFromSelection); UpdateCommands(); debugPage = new DebugEntityHierarchyEditorUserControl(this); EditorDebugTools.RegisterDebugPage(debugPage); }
/// <summary> /// Fetches the entity corresponding to the given content. /// </summary> /// <param name="scene">The scene owning the entity to fetch.</param> /// <param name="content">The entity to fetch, or one of its components.</param> public static void Fetch(EntityHierarchyViewModel scene, object content) { Entity entity; var component = content as EntityComponent; if (component != null) { entity = component.Entity; } else { entity = content as Entity; } if (entity == null) { return; } var editor = scene.Editor; var partId = new AbsoluteId(scene.Id, entity.Id); var viewModel = editor.FindPartViewModel(partId) as EntityViewModel; if (viewModel == null) { return; } editor.SelectedItems.Clear(); editor.SelectedItems.Add(viewModel); editor.Controller.GetService <IEditorGameEntityCameraViewModelService>().CenterOnEntity(viewModel); }
public EntityViewModel([NotNull] EntityHierarchyEditorViewModel editor, [NotNull] EntityHierarchyViewModel asset, [NotNull] EntityDesign entityDesign) : base(editor, asset, GetOrCreateChildPartDesigns((EntityHierarchyAssetBase)asset.Asset, entityDesign), entityDesign.Entity) { if (entityDesign.Entity == null) { throw new ArgumentException(@"entity must contain a non-null asset entity.", nameof(entityDesign)); } EntityDesign = entityDesign; var assetNode = Editor.NodeContainer.GetOrCreateNode(entityDesign.Entity); nameNodeBinding = new MemberGraphNodeBinding <string>(assetNode[nameof(Entity.Name)], nameof(Name), OnPropertyChanging, OnPropertyChanged, Editor.UndoRedoService); componentsNodeBinding = new ObjectGraphNodeBinding <EntityComponentCollection>(assetNode[nameof(Entity.Components)].Target, nameof(Components), OnPropertyChanging, OnPropertyChanged, Editor.UndoRedoService, false); modelComponent = new ModelComponentViewModel(ServiceProvider, this); particleComponent = new ParticleSystemComponentViewModel(ServiceProvider, this); cameraComponent = new CameraComponentViewModel(ServiceProvider, this); transformationNode = Editor.NodeContainer.GetNode(AssetSideEntity.Transform)[nameof(TransformComponent.Children)].Target; transformationNode.ItemChanging += TransformChildrenChanging; transformationNode.ItemChanged += TransformChildrenChanged; RenameCommand = new AnonymousCommand(ServiceProvider, () => IsEditing = true); FocusOnEntityCommand = new AnonymousCommand(ServiceProvider, FocusOnEntity); UpdateSourcePrefab(); var basePrefabNode = Editor.NodeContainer.GetNode(EntityDesign)[nameof(EntityDesign.Base)]; basePrefabNode.ValueChanged += BasePrefabChanged; }
public EntityFolderOperation([NotNull] EntityHierarchyViewModel asset, Action action, [NotNull] string folderPath, AbsoluteId ownerId) : this(action, folderPath, ownerId, asset.SafeArgument(nameof(asset)).Dirtiables) { if (action != Action.FolderCreated && action != Action.FolderDeleted) { throw new ArgumentException(@"The action must be FolderCreated or FolderDeleted when using this constructor.", nameof(action)); } this.asset = asset; }
protected EntityHierarchyElementViewModel([NotNull] EntityHierarchyEditorViewModel editor, [NotNull] EntityHierarchyViewModel asset, [NotNull] IEnumerable <EntityDesign> childEntities, object assetSideInstance) : base(editor, asset, childEntities) { this.assetSideInstance = assetSideInstance; LoadCommand = new AnonymousTaskCommand <bool>(ServiceProvider, recursive => RequestLoading(!IsLoaded, recursive)); LockCommand = new AnonymousTaskCommand <bool>(ServiceProvider, recursive => RequestLocking(!IsLocked, recursive)); DependentProperties.Add(nameof(IsLoaded), new[] { nameof(IsSelectable) }); DependentProperties.Add(nameof(IsLocked), new[] { nameof(IsSelectable) }); }
/// <inheritdoc/> protected override void FreezeContent() { asset = null; }
public EntityFolderViewModel([NotNull] EntityHierarchyEditorViewModel editor, [NotNull] EntityHierarchyViewModel asset, string name, [NotNull] IEnumerable <EntityDesign> entities) : base(editor, asset, entities) { this.name = name; Id = new AbsoluteId(Asset.Id, Guid.NewGuid()); RenameCommand = new AnonymousCommand(ServiceProvider, () => IsEditing = true); }
protected EntityHierarchyRootViewModel([NotNull] EntityHierarchyEditorViewModel editor, [NotNull] EntityHierarchyViewModel asset, [NotNull] string name) : base(editor, asset, asset.Asset.Hierarchy.EnumerateRootPartDesigns(), null) { this.name = name ?? throw new ArgumentNullException(nameof(name)); rootEntitiesNode = Editor.Session.AssetNodeContainer.GetNode(EntityHierarchy.Hierarchy)[nameof(AssetCompositeHierarchyData <EntityDesign, Entity> .RootParts)].Target; rootEntitiesNode.ItemChanging += RootEntitiesChanging; rootEntitiesNode.ItemChanged += RootEntitiesChanged; entitiesNode = Editor.Session.AssetNodeContainer.GetNode(EntityHierarchy.Hierarchy)[nameof(AssetCompositeHierarchyData <EntityDesign, Entity> .Parts)].Target; entitiesNode.ItemChanged += EntitiesChanged; }