/// <summary> /// Creates a instance of the given control that can be added to another <see cref="UIAssetBase"/>. /// </summary> /// <param name="targetContainer">The container in which the instance will be added.</param> /// <param name="targetLocation">The location of the <see paramref="targetContainer"/> asset.</param> /// <param name="elementId">The id of the element to instantiate.</param> /// <returns>An <see cref="AssetCompositeHierarchyData{UIElementDesign, UIElement}"/> containing the cloned elements of </returns> /// <remarks>This method will update the <see cref="Asset.BaseParts"/> property of the <see paramref="targetContainer"/>.</remarks> public AssetCompositeHierarchyData <UIElementDesign, UIElement> CreateElementInstance(UIAssetBase targetContainer, string targetLocation, Guid elementId) { Guid unused; return(CreateElementInstance(targetContainer, targetLocation, elementId, out unused)); }
/// <summary> /// Creates a instance of the given control that can be added to another <see cref="UIAssetBase"/>. /// </summary> /// <param name="targetContainer">The container in which the instance will be added.</param> /// <param name="targetLocation">The location of this asset.</param> /// <param name="elementId">The id of the element to instantiate.</param> /// <param name="instanceId">The identifier of the created instance.</param> /// <returns>An <see cref="AssetCompositeHierarchyData{UIElementDesign, UIElement}"/> containing the cloned elements of </returns> /// <remarks>This method will update the <see cref="Asset.BaseParts"/> property of the <see paramref="targetContainer"/>.</remarks> public AssetCompositeHierarchyData <UIElementDesign, UIElement> CreateElementInstance(UIAssetBase targetContainer, string targetLocation, Guid elementId, out Guid instanceId) { // TODO: make a common base method in AssetCompositeHierarchy - the beginning of the method is similar to CreatePrefabInstance var idRemapping = new Dictionary <Guid, Guid>(); var instance = (UILibraryAsset)CreateChildAsset(targetLocation, idRemapping); var rootElementId = idRemapping[elementId]; if (!instance.Hierarchy.RootPartIds.Contains(rootElementId)) { throw new ArgumentException(@"The given id cannot be found in the root parts of this library.", nameof(elementId)); } targetContainer.AddBasePart(instance.Base); instanceId = Guid.NewGuid(); foreach (var elementEntry in instance.Hierarchy.Parts) { elementEntry.BasePartInstanceId = instanceId; } var result = new AssetCompositeHierarchyData <UIElementDesign, UIElement>(); result.RootPartIds.Add(rootElementId); result.Parts.Add(instance.Hierarchy.Parts[rootElementId]); foreach (var element in EnumerateChildParts(instance.Hierarchy.Parts[rootElementId], instance.Hierarchy, true)) { result.Parts.Add(element); } return(result); }
public AssetCompositeHierarchyData <UIElementDesign, UIElement> CreateElementInstance(UIAssetBase targetContainer, [NotNull] string targetLocation, Guid elementId, out Guid instanceId) { // TODO: make a common base method in AssetCompositeHierarchy - the beginning of the method is similar to CreatePrefabInstance var idRemapping = new Dictionary <Guid, Guid>(); var instance = (UILibraryAsset)CreateDerivedAsset(targetLocation, out idRemapping); var rootElementId = idRemapping[elementId]; if (instance.Hierarchy.RootParts.All(x => x.Id != rootElementId)) { throw new ArgumentException(@"The given id cannot be found in the root parts of this library.", nameof(elementId)); } instanceId = instance.Hierarchy.Parts.Values.FirstOrDefault()?.Base?.InstanceId ?? Guid.NewGuid(); var result = new AssetCompositeHierarchyData <UIElementDesign, UIElement>(); result.RootParts.Add(instance.Hierarchy.Parts[rootElementId].UIElement); result.Parts.Add(instance.Hierarchy.Parts[rootElementId]); foreach (var element in this.EnumerateChildPartDesigns(instance.Hierarchy.Parts[rootElementId], instance.Hierarchy, true)) { result.Parts.Add(element); } return(result); }