示例#1
0
 protected override EntityComponent CreateComponentFromAsset(EntityHierarchyItemViewModel parent, UIPageViewModel asset)
 {
     return(new UIComponent
     {
         Page = ContentReferenceHelper.CreateReference <UIPage>(asset)
     });
 }
示例#2
0
        /// <summary>
        /// Select the given material in the asset view.
        /// </summary>
        /// <param name="entity">The entity referencing the material, via its model component.</param>
        /// <param name="materialIndex">The index of the material to select in the model component, or in the model itself.</param>
        private void SelectMaterialInAssetView(Entity entity, int materialIndex)
        {
            var partId    = editor.Controller.GetAbsoluteId(entity);
            var viewModel = (EntityViewModel)editor.FindPartViewModel(partId);
            var modelComp = viewModel.AssetSideEntity.Get <ModelComponent>();

            if (modelComp == null)
            {
                return;
            }

            var material = modelComp.Materials.SafeGet(materialIndex);

            if (material == null)
            {
                var modelViewModel = ContentReferenceHelper.GetReferenceTarget(viewModel.Editor.Session, modelComp.Model);
                var model          = modelViewModel?.AssetItem.Asset as IModelAsset;
                if (model != null && model.Materials.Count > materialIndex)
                {
                    material = model.Materials[materialIndex].MaterialInstance.Material;
                }
            }

            if (material == null)
            {
                return;
            }

            var materialAsset = ContentReferenceHelper.GetReferenceTarget(viewModel.Editor.Session, material);

            editor.Session.ActiveAssetView.SelectAssetCommand.Execute(materialAsset);
        }
示例#3
0
        private async void CreateSkeleton()
        {
            var source = Asset.Source;

            if (UPath.IsNullOrEmpty(source))
            {
                return;
            }

            using (var transaction = UndoRedoService.CreateTransaction())
            {
                var template = Session.FindTemplates(TemplateScope.Asset).SingleOrDefault(x => x.Id == SkeletonFromFileTemplateGenerator.Id);
                if (template != null)
                {
                    var viewModel = new TemplateDescriptionViewModel(ServiceProvider, template);
                    var skeleton  = (await Session.ActiveAssetView.RunAssetTemplate(viewModel, new[] { source })).SingleOrDefault();
                    if (skeleton == null)
                    {
                        return;
                    }

                    var skeletonNode = AssetRootNode[nameof(ModelAsset.Skeleton)];
                    var reference    = ContentReferenceHelper.CreateReference <Skeleton>(skeleton);
                    skeletonNode.Update(reference);
                }
                UndoRedoService.SetName(transaction, "Create Skeleton");
            }
        }
示例#4
0
 protected override EntityComponent CreateComponentFromAsset(EntityHierarchyItemViewModel parent, AssetViewModel <TModelAsset> asset)
 {
     return(new ModelComponent
     {
         Model = ContentReferenceHelper.CreateReference <Model>(asset)
     });
 }
示例#5
0
 protected override EntityComponent CreateComponentFromAsset(EntityHierarchyItemViewModel parent, SpriteStudioModelViewModel asset)
 {
     return(new SpriteStudioComponent
     {
         Sheet = ContentReferenceHelper.CreateReference <SpriteStudioSheet>(asset),
     });
 }
示例#6
0
 protected override EntityComponent CreateComponentFromAsset(EntityHierarchyItemViewModel parent, AssetViewModel <VideoAsset> asset)
 {
     return(new VideoComponent
     {
         Source = ContentReferenceHelper.CreateReference <Video.Video>(asset)
     });
 }
示例#7
0
        /// <summary>
        /// Fetches the entity corresponding to the given content.
        /// </summary>
        /// <param name="session">The current session.</param>
        /// <param name="content">The proxy object corresponding to the asset to fetch.</param>
        public static async Task Fetch(SessionViewModel session, object content)
        {
            var asset = ContentReferenceHelper.GetReferenceTarget(session, content);

            if (asset != null)
            {
                await session.Dispatcher.InvokeAsync(() => session.ActiveAssetView.SelectAssetCommand.Execute(asset));
            }
        }
        protected override IEnumerable <ReferenceReplacementViewModel <AssetViewModel> > GetReplacementsForReferencer(AssetViewModel referencer, object referencedMember)
        {
            var rootNode = SessionViewModel.Instance.AssetNodeContainer.GetNode(referencer.Asset);
            var visitor  = new GraphVisitorBase {
                SkipRootNode = true
            };
            var result = new List <ReferenceReplacementViewModel <AssetViewModel> >();

            visitor.Visiting += (node, path) =>
            {
                var memberNode = node as IAssetMemberNode;
                if (memberNode != null)
                {
                    if (AssetRegistry.IsContentType(memberNode.Descriptor.GetInnerCollectionType()))
                    {
                        if (memberNode.Target?.IsEnumerable ?? false)
                        {
                            foreach (var index in memberNode.Target.Indices)
                            {
                                // If this property is inherited it will be updated by the standard propagation
                                if (memberNode.Target.IsItemInherited(index))
                                {
                                    continue;
                                }

                                var target = ContentReferenceHelper.GetReferenceTarget(referencer.Session, memberNode.Target.Retrieve(index));
                                if (target == CurrentObjectToReplace)
                                {
                                    // If so, prepare a replacement for it.
                                    var viewModel = new AssetReferenceReplacementViewModel(this, CurrentObjectToReplace, referencer, referencedMember, memberNode.Target, index);
                                    result.Add(viewModel);
                                }
                            }
                        }
                        else
                        {
                            // If this property is inherited it will be updated by the standard propagation
                            if (memberNode.IsContentInherited())
                            {
                                return;
                            }

                            var target = ContentReferenceHelper.GetReferenceTarget(referencer.Session, memberNode.Retrieve());
                            if (target == CurrentObjectToReplace)
                            {
                                // If so, prepare a replacement for it.
                                var viewModel = new AssetReferenceReplacementViewModel(this, CurrentObjectToReplace, referencer, referencedMember, memberNode, NodeIndex.Empty);
                                result.Add(viewModel);
                            }
                        }
                    }
                }
            };
            visitor.Visit(rootNode);
            return(result);
        }
示例#9
0
 protected override EntityComponent CreateComponentFromAsset(EntityHierarchyItemViewModel parent, SpriteSheetViewModel asset)
 {
     return(new SpriteComponent
     {
         SpriteProvider = new SpriteFromSheet
         {
             Sheet = ContentReferenceHelper.CreateReference <SpriteSheet>(asset)
         }
     });
 }
示例#10
0
 protected override EntityComponent CreateComponentFromAsset(EntityHierarchyItemViewModel parent, AssetViewModel <TextureAsset> asset)
 {
     return(new SpriteComponent
     {
         SpriteProvider = new SpriteFromTexture
         {
             Texture = ContentReferenceHelper.CreateReference <Texture>(asset)
         }
     });
 }
示例#11
0
        protected override void ReplaceReference()
        {
            var referenceType = node.Descriptor.GetInnerCollectionType();
            var newReference  = ContentReferenceHelper.CreateReference(ReplacementObject, referenceType);

            if (node is IMemberNode)
            {
                ((IMemberNode)node).Update(newReference);
            }
            else
            {
                ((IObjectNode)node).Update(newReference, index);
            }
        }
        protected override async Task <bool> PrepareAssetCreation(AssetTemplateGeneratorParameters parameters)
        {
            if (!await base.PrepareAssetCreation(parameters))
            {
                return(false);
            }

            var modelViewModel = await BrowseForAsset(parameters.Package, new[] { typeof(IModelAsset) }, new UFile(parameters.Name).GetFullDirectory(), "Select a model to use to generate the hull - _cancel to leave the model empty_");

            var model = ContentReferenceHelper.CreateReference <Model>(modelViewModel);

            parameters.SetTag(ModelKey, model);
            return(true);
        }
        protected override async Task <bool> PrepareAssetCreation(AssetTemplateGeneratorParameters parameters)
        {
            if (!await base.PrepareAssetCreation(parameters))
            {
                return(false);
            }

            var acceptedTypes    = AssetRegistry.GetAssetTypes(typeof(Texture));
            var textureViewModel = await BrowseForAsset(parameters.Package, acceptedTypes, new UFile(parameters.Name).GetFullDirectory(), "Select a cubemap texture to use for this skybox - _cancel to leave the texture empty_");

            var texture = ContentReferenceHelper.CreateReference <Texture>(textureViewModel);

            parameters.SetTag(TextureKey, texture);
            return(true);
        }
        protected override async Task <bool> PrepareAssetCreation(AssetTemplateGeneratorParameters parameters)
        {
            if (!await base.PrepareAssetCreation(parameters))
            {
                return(false);
            }

            var acceptedTypes     = AssetRegistry.GetAssetTypes(typeof(Material));
            var materialViewModel = await BrowseForAsset(parameters.Package, acceptedTypes, new UFile(parameters.Name).GetFullDirectory(), "Select a material to use for this model - _cancel to leave the material empty_");

            var material = ContentReferenceHelper.CreateReference <Material>(materialViewModel);

            parameters.SetTag(MaterialKey, material);
            return(true);
        }
示例#15
0
        public override async Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent)
        {
            var model = await PickupAsset(parent.Editor.Session, new [] { typeof(IModelAsset) });

            if (model == null)
            {
                return(null);
            }

            var name      = ComputeNewName(parent, model.Name);
            var component = new ModelComponent {
                Model = ContentReferenceHelper.CreateReference <Model>(model)
            };

            return(await CreateEntityWithComponent(name, component));
        }
示例#16
0
        protected override void UpdateNode(IAssetNodePresenter node)
        {
            if (!(node.PropertyProvider is AssetViewModel) || node.Asset == null)
            {
                return;
            }

            // Add a link to the archetype in the root node, if there is an archetype for this asset.
            if (typeof(Asset).IsAssignableFrom(node.Type) && node.Asset.Asset.Archetype != null)
            {
                var session        = node.Asset.Session;
                var archetype      = session.GetAssetById(node.Asset.Asset.Archetype.Id);
                var assetReference = ContentReferenceHelper.CreateReference <AssetReference>(archetype);
                var archetypeNode  = node.Factory.CreateVirtualNodePresenter(node, ArchetypeNodeName, typeof(AssetReference), int.MinValue, () => assetReference);
                archetypeNode.DisplayName = nameof(Asset.Archetype);
                archetypeNode.IsReadOnly  = true;
            }
        }
示例#17
0
        public override async Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent)
        {
            var skybox = await PickupAsset(parent.Editor.Session, new[] { typeof(SkyboxAsset) });

            if (skybox == null)
            {
                return(null);
            }
            var skyboxAsset = (SkyboxAsset)skybox.Asset;

            var name           = ComputeNewName(parent, "Skybox light");
            var lightComponent = new LightComponent {
                Type = new LightSkybox {
                    Skybox = ContentReferenceHelper.CreateReference <Skybox>(skybox)
                }
            };
            var skyboxComponent = new BackgroundComponent {
                Texture = skyboxAsset.CubeMap
            };

            return(await CreateEntityWithComponent(name, lightComponent, skyboxComponent));
        }
示例#18
0
 /// <summary>
 /// Creates the content reference corresponding to the given asset.
 /// </summary>
 /// <param name="asset">The asset for which to create a content reference.</param>
 /// <param name="referenceType">The type of content reference to create.</param>
 /// <returns>A content reference corresponding to the given asset.</returns>
 protected virtual object CreateReference(AssetViewModel asset, Type referenceType)
 {
     return(ContentReferenceHelper.CreateReference(asset, referenceType));
 }
示例#19
0
 /// <inheritdoc />
 public override bool CanAttach(INodePresenter nodePresenter)
 {
     return(ContentReferenceHelper.ContainsReferenceType(nodePresenter.Descriptor));
 }
示例#20
0
 protected virtual AssetViewModel GetCurrentTarget(object currentValue)
 {
     return(ContentReferenceHelper.GetReferenceTarget(Session, currentValue));
 }
        protected override async Task <bool> PrepareAssetCreation(AssetTemplateGeneratorParameters parameters)
        {
            var result = await base.PrepareAssetCreation(parameters);

            if (!result)
            {
                return(false);
            }

            var files = parameters.Tags.Get(SourceFilesPathKey);

            if (files is null)
            {
                return(true);
            }

            var showDeduplicateMaterialsCheckBox = files.Any(x => ImportAssimpCommand.IsSupportingExtensions(x.GetFileExtension()));
            var showFbxDedupeNotSupportedWarning = showDeduplicateMaterialsCheckBox && files.Any(x => ImportFbxCommand.IsSupportingExtensions(x.GetFileExtension()));
            // Load settings from the last time this template was used for this project
            var profile = parameters.Package.UserSettings.Profile;
            var window  = new ModelAssetTemplateWindow
            {
                Parameters =
                {
                    ImportMaterials                  = ModelFromFileTemplateSettings.ImportMaterials.GetValue(profile,      true),
                    ShowDeduplicateMaterialsCheckBox = showDeduplicateMaterialsCheckBox,
                    ShowFbxDedupeNotSupportedWarning = showFbxDedupeNotSupportedWarning,
                    DeduplicateMaterials             = ModelFromFileTemplateSettings.DeduplicateMaterials.GetValue(profile, true),
                    ImportTextures = ModelFromFileTemplateSettings.ImportTextures.GetValue(profile,       true),
                    ImportSkeleton = ModelFromFileTemplateSettings.ImportSkeleton.GetValue(profile,       true)
                }
            };

            var skeletonId = ModelFromFileTemplateSettings.DefaultSkeleton.GetValue();
            var skeleton   = SessionViewModel.Instance?.GetAssetById(skeletonId);

            if (skeleton != null)
            {
                window.Parameters.ReuseSkeleton   = true;
                window.Parameters.SkeletonToReuse = ContentReferenceHelper.CreateReference <Skeleton>(skeleton);
            }

            await window.ShowModal();

            if (window.Result == DialogResult.Cancel)
            {
                return(false);
            }

            // Apply settings
            var skeletonToReuse = window.Parameters.ReuseSkeleton ? window.Parameters.SkeletonToReuse : null;

            parameters.Tags.Set(ImportMaterialsKey, window.Parameters.ImportMaterials);
            parameters.Tags.Set(DeduplicateMaterialsKey, window.Parameters.DeduplicateMaterials);
            parameters.Tags.Set(ImportTexturesKey, window.Parameters.ImportTextures);
            parameters.Tags.Set(ImportSkeletonKey, window.Parameters.ImportSkeleton);
            parameters.Tags.Set(SkeletonToUseKey, skeletonToReuse);

            // Save settings
            ModelFromFileTemplateSettings.ImportMaterials.SetValue(window.Parameters.ImportMaterials, profile);
            ModelFromFileTemplateSettings.DeduplicateMaterials.SetValue(window.Parameters.DeduplicateMaterials, profile);
            ModelFromFileTemplateSettings.ImportTextures.SetValue(window.Parameters.ImportTextures, profile);
            ModelFromFileTemplateSettings.ImportSkeleton.SetValue(window.Parameters.ImportSkeleton, profile);
            skeletonId = AttachedReferenceManager.GetAttachedReference(skeletonToReuse)?.Id ?? AssetId.Empty;
            ModelFromFileTemplateSettings.DefaultSkeleton.SetValue(skeletonId, profile);
            parameters.Package.UserSettings.Save();

            return(true);
        }
示例#22
0
 private void UpdateGameSettings(SceneViewModel scene)
 {
     Asset.DefaultScene = ContentReferenceHelper.CreateReference <Scene>(scene);
 }