/// <summary> /// Initialize a new instance of <see cref="PrefabAssetMerge"/> /// </summary> /// <param name="baseAsset">The base asset used for merge (can be null).</param> /// <param name="newAsset">The new asset (cannot be null)</param> /// <param name="newBaseAsset">The new base asset (can be null)</param> /// <param name="newBaseParts">The new base parts (can be null)</param> /// <param name="debugLocation">The location of the asset being merged, used only for debug/log purpose</param> public PrefabAssetMerge(EntityHierarchyAssetBase baseAsset, EntityHierarchyAssetBase newAsset, EntityHierarchyAssetBase newBaseAsset, List <AssetBase> newBaseParts, UFile debugLocation = null) { if (newAsset == null) { throw new ArgumentNullException(nameof(newAsset)); } // We expect to have at least a baseAsset+newBaseAsset or newBaseParts if (baseAsset == null && newBaseAsset == null && (newBaseParts == null || newBaseParts.Count == 0)) { throw new InvalidOperationException("Cannot merge from base. No bases found"); } this.newAsset = newAsset; this.newBaseAsset = newBaseAsset; this.newBaseParts = newBaseParts; this.debugLocation = debugLocation; this.baseAsset = baseAsset; baseEntities = new Dictionary <GroupPartKey, BaseEntityEntry>(); newEntities = new Dictionary <GroupPartKey, NewEntityEntry>(); newBaseEntities = new Dictionary <GroupPartKey, BaseEntityEntry>(); entitiesRemovedInNewBase = new HashSet <Guid>(); entitiesToRemoveFromNew = new HashSet <Guid>(); entitiesInHierarchy = new HashSet <Guid>(); rootEntitiesToAdd = new List <Guid>(); }
/// <summary> /// Creates a instance of this prefab that can be added to another <see cref="EntityHierarchyAssetBase"/>. /// </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="instanceId">The identifier of the created instance.</param> /// <returns>An <see cref="EntityHierarchyData"/> containing the cloned entities of </returns> /// <remarks>This method will update the <see cref="Asset.BaseParts"/> property of the <see paramref="targetContainer"/>.</remarks> public EntityHierarchyData CreatePrefabInstance(EntityHierarchyAssetBase targetContainer, string targetLocation, out Guid instanceId) { var instance = (PrefabAsset)CreateChildAsset(targetLocation); targetContainer.AddBasePart(instance.Base); instanceId = Guid.NewGuid(); foreach (var entityEntry in instance.Hierarchy.Entities) { entityEntry.Design.BasePartInstanceId = instanceId; } return(instance.Hierarchy); }
/// <summary> /// Creates a instance of this prefab that can be added to another <see cref="EntityHierarchyAssetBase"/>. /// </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="instanceId">The identifier of the created instance.</param> /// <returns>An <see cref="AssetCompositeHierarchyData{EntityDesign, Entity}"/> containing the cloned entities of </returns> /// <remarks>This method will update the <see cref="Asset.BaseParts"/> property of the <see paramref="targetContainer"/>.</remarks> public AssetCompositeHierarchyData <EntityDesign, Entity> CreatePrefabInstance(EntityHierarchyAssetBase targetContainer, string targetLocation, out Guid instanceId) { var instance = (PrefabAsset)CreateDerivedAsset(targetLocation); instanceId = instance.Hierarchy.Parts.FirstOrDefault()?.Base.InstanceId ?? Guid.NewGuid(); return(instance.Hierarchy); }
/// <summary> /// Creates a instance of this prefab that can be added to another <see cref="EntityHierarchyAssetBase"/>. /// </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> /// <returns>An <see cref="AssetCompositeHierarchyData{EntityDesign, Entity}"/> containing the cloned entities of </returns> /// <remarks>This method will update the <see cref="Asset.BaseParts"/> property of the <see paramref="targetContainer"/>.</remarks> public AssetCompositeHierarchyData <EntityDesign, Entity> CreatePrefabInstance(EntityHierarchyAssetBase targetContainer, string targetLocation) { Guid unused; return(CreatePrefabInstance(targetContainer, targetLocation, out unused)); }
/// <summary> /// Creates a instance of this prefab that can be added to another <see cref="EntityHierarchyAssetBase"/>. /// </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> /// <returns>An <see cref="EntityHierarchyData"/> containing the cloned entities of </returns> /// <remarks>This method will update the <see cref="Asset.BaseParts"/> property of the <see paramref="targetContainer"/>.</remarks> public EntityHierarchyData CreatePrefabInstance(EntityHierarchyAssetBase targetContainer, string targetLocation) { Guid unused; return(CreatePrefabInstance(targetContainer, targetLocation, out unused)); }
/// <summary> /// Fixups the entity references, by clearing invalid <see cref="EntityReference.Id"/>, and updating <see cref="EntityReference.Value"/> (same for components). /// </summary> /// <param name="entityAssetBase">The entity asset.</param> public static void FixupEntityReferences(EntityHierarchyAssetBase entityAssetBase) { FixupEntityReferences(entityAssetBase, entityAssetBase.Hierarchy); }