/// <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); }
/// <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); }
protected virtual AssetViewModel GetCurrentTarget(object currentValue) { return(ContentReferenceHelper.GetReferenceTarget(Session, currentValue)); }