4 using System.Collections.Generic;
5 using System.Diagnostics;
8 using System.Threading;
9 using SiliconStudio.Assets.Analysis;
10 using SiliconStudio.Assets.Diff;
11 using SiliconStudio.Assets.Visitors;
12 using SiliconStudio.Core;
13 using SiliconStudio.Core.Diagnostics;
14 using SiliconStudio.Core.Extensions;
15 using SiliconStudio.Core.IO;
16 using SiliconStudio.Core.Serialization;
18 namespace SiliconStudio.Assets
59 private readonly List<AssetToImport> imports;
62 private readonly Dictionary<AssetLocationTyped, HashSet<AssetItem>> sourceFileToAssets =
new Dictionary<AssetLocationTyped, HashSet<AssetItem>>();
67 public event EventHandler<AssetImportSessionEvent>
Progress;
76 if (session == null)
throw new ArgumentNullException(
"session");
77 this.session = session;
78 imports =
new List<AssetToImport>();
85 public List<AssetToImport> Imports
101 return Imports.SelectMany(
import => import.ByImporters).
Any(step => step.HasErrors);
113 if (file == null)
throw new ArgumentNullException(
"file");
116 if (!
File.Exists(file))
return false;
137 if (file == null)
throw new ArgumentNullException(
"file");
138 if (package == null)
throw new ArgumentNullException(
"package");
139 if (directory == null)
throw new ArgumentNullException(
"directory");
140 if (!IsFileSupported(file))
142 throw new ArgumentException(
"File [{0}] does not exist or is not an absolute path".ToFormat(file));
146 var importerList = AssetRegistry.FindImporterByExtension(file.GetFileExtension()).ToList();
147 importerList.Sort((left, right) => -left.DisplayRank.CompareTo(right.DisplayRank));
150 foreach (var importer
in importerList)
152 assetToImport = AddFile(file, importer, package, directory);
154 return assetToImport;
172 if (files == null)
throw new ArgumentNullException(
"files");
173 if (package == null)
throw new ArgumentNullException(
"package");
174 if (directory == null)
throw new ArgumentNullException(
"directory");
175 var result =
new List<AssetToImport>();
176 foreach (var file
in files)
178 var assetToImport = AddFile(file, package, directory);
179 if (assetToImport != null && !result.Contains(assetToImport))
180 result.Add(assetToImport);
207 if (file == null)
throw new ArgumentNullException(
"file");
208 if (importer == null)
throw new ArgumentNullException(
"importer");
209 if (package == null)
throw new ArgumentNullException(
"package");
210 if (directory == null)
throw new ArgumentNullException(
"directory");
212 if (!IsFileSupported(file))
214 throw new ArgumentException(
"File [{0}] does not exist or is not an absolute path".ToFormat(file));
217 if (!importer.IsSupportingFile(file))
throw new ArgumentNullException(
"importer [{0}] is not supporting file [{1}]".ToFormat(importer.
Name, file));
219 if (!session.Packages.Contains(package))
221 throw new InvalidOperationException(
"Current session does not contain package");
224 return RegisterImporter(file, package, directory, importer);
235 if (assetItem == null)
throw new ArgumentNullException(
"assetItem");
236 if (assetItem.
Package == null)
return false;
240 if (asset == null)
return false;
241 if (asset.Base == null)
return false;
242 if (asset.Source == null)
return false;
244 var baseAsset = asset.Base.Asset as AssetImportTracked;
245 if (baseAsset == null)
return false;
247 if (baseAsset.ImporterId.HasValue)
249 var importer = AssetRegistry.FindImporterById(baseAsset.ImporterId.Value);
250 if (importer == null)
264 if (assetItem == null)
throw new ArgumentNullException(
"assetItem");
265 if (assetItem.
Package == null)
throw new ArgumentException(
"AssetItem is not attached to a package");
266 if (assetItem.
Package.
Session != session)
throw new ArgumentException(
"AssetItem is not attached to the same session of this importItem");
269 if (asset == null)
throw new ArgumentException(
"The asset is not an existing importable asset");
270 if (asset.Base == null)
throw new ArgumentException(
"The asset to importItem must have a base to reimport");
271 if (asset.Source == null)
throw new ArgumentException(
"The asset to importItem has no source/location to an existing raw asset");
273 var baseAsset = asset.Base.Asset as AssetImportTracked;
274 if (baseAsset == null)
throw new ArgumentException(
"The base asset to importItem is invalid");
278 if (baseAsset.ImporterId.HasValue)
280 importer = AssetRegistry.FindImporterById(baseAsset.ImporterId.Value);
284 if (importer == null)
286 importer = AssetRegistry.FindImporterByExtension(asset.Source.GetFileExtension()).FirstOrDefault();
289 if (importer == null)
291 throw new ArgumentException(
"No importer found for this asset item");
305 public bool Stage(CancellationToken? cancelToken = null)
307 bool isImportOk =
true;
308 var ids =
new HashSet<Guid>();
311 foreach (var fileToImport
in Imports)
313 foreach (var toImportByImporter
in fileToImport.ByImporters)
315 toImportByImporter.Items.Clear();
316 toImportByImporter.Log.Clear();
321 foreach (var fileToImport
in Imports)
323 if (!fileToImport.Enabled)
328 foreach (var toImportByImporter
in fileToImport.ByImporters)
331 if (!toImportByImporter.Enabled || !toImportByImporter.ImporterParameters.HasSelectedOutputTypes)
336 if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
338 toImportByImporter.Log.Warning(
"Cancellation requested before importing asset [{0}] with importer [{1}]",
fileToImport.File, toImportByImporter.Importer.Name);
346 var itemsToImport = toImportByImporter.Importer.Import(
fileToImport.File, toImportByImporter.ImporterParameters).ToList();
347 CheckAssetsToImport(itemsToImport, ids);
349 foreach (var itemToImport
in itemsToImport)
351 if (itemToImport == null)
354 itemToImport.SourceFolder = fileToImport.Package.GetDefaultAssetFolder();
357 toImportByImporter.Items.Add(assetToImport);
360 toImportByImporter.Log.Info(
"Successfully processed file [{0}]",
fileToImport.File);
364 toImportByImporter.Log.Error(
"Unexpected exception while importing file [{0}]", ex,
fileToImport.File);
375 ComputeAssetHash(cancelToken);
378 PrepareMerge(cancelToken);
387 public void Merge(CancellationToken? cancelToken = null)
389 var idRemapping =
new Dictionary<Guid, AssetItem>();
393 foreach (var fileToImport
in Imports.Where(it => it.Enabled))
395 foreach (var toImportByImporter
in fileToImport.ByImporters.Where(it => it.Enabled))
397 foreach (var toImport
in toImportByImporter.Items)
399 if (toImport.SelectedItem != null)
401 if (toImport.Item.Id != toImport.SelectedItem.Id)
403 idRemapping.Add(toImport.Item.Id, toImport.SelectedItem);
406 else if (toImport.Enabled)
409 toImport.SelectedItem = toImport.Item;
415 if (idRemapping.Count == 0)
421 foreach (var fileToImport
in Imports.Where(it => it.Enabled))
423 foreach (var toImportByImporter
in fileToImport.ByImporters.Where(it => it.Enabled))
425 foreach (var toImport
in toImportByImporter.Items.Where(it => it.Enabled))
429 if (toImport.SelectedItem == null || toImport.Item.Id == toImport.SelectedItem.Id)
431 FixAssetReferences(toImport, idRemapping);
435 var selectedItem = toImport.SelectedItem;
436 var selectedMerge = toImport.Merges.FirstOrDefault(merge => merge.PreviousItem == selectedItem);
438 if (selectedMerge == null)
440 toImport.Log.Error(
"Selected item [{0}] does not exist in the merge");
444 if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
446 toImport.Log.Warning(
"Cancellation requested before merging asset from [{0}] to location [{1}] ",
fileToImport.File, selectedItem.Location);
453 MergeAsset(toImport, selectedMerge, idRemapping);
457 toImport.Log.Error(
"Unexpected error while merging asset [{0}]", ex, toImport.Item);
478 private static void FixAssetReferences(
AssetToImportMergeGroup toImport, Dictionary<Guid, AssetItem> idRemapping)
480 var asset = (toImport.SelectedItem ?? toImport.Item).
Asset;
483 var referencesToUpdate = AssetReferenceAnalysis.Visit(asset);
484 foreach (var assetReferenceLink
in referencesToUpdate)
487 if (refToUpdate == null || refToUpdate.Id == Guid.Empty || !idRemapping.ContainsKey(refToUpdate.Id))
492 var realItem = idRemapping[refToUpdate.Id];
493 assetReferenceLink.UpdateReference(realItem.Id, realItem.Location);
497 private static void MergeAsset(AssetToImportMergeGroup toImport, AssetToImportMerge selectedMerge, Dictionary<Guid, AssetItem> idRemapping)
500 var result = AssetMerge.Merge(selectedMerge.Diff, node =>
507 if (node.Asset2Node != null)
513 if (idRemapping.TryGetValue(instance.Id, out realItem))
515 var newReference = AssetReference.New(instance.GetType(), realItem.Id, realItem.Location);
516 node.ReplaceValue(newReference, diff3Node => diff3Node.Asset2Node,
false);
519 return Diff3ChangeType.MergeFromAsset2;
522 if (node.Asset1Node != null)
524 return Diff3ChangeType.MergeFromAsset1;
527 return AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1(node);
530 toImport.MergedResult = result;
531 if (result.HasErrors)
533 toImport.Log.Error(
"Error while trying to merge asset [{0}]", toImport.Item);
534 result.CopyTo(toImport.Log);
538 var finalAsset = result.Asset;
539 finalAsset.Base =
new AssetBase(selectedMerge.Diff.Asset2);
542 toImport.MergedItem =
new AssetItem(toImport.SelectedItem.Location, finalAsset) { SourceFolder = toImport.SelectedItem.SourceFolder };
566 var usedNames =
new HashSet<string>(StringComparer.OrdinalIgnoreCase);
569 var mergedAssets =
new HashSet<Guid>();
570 foreach (var toImport
in AllImports())
572 if (toImport.MergedItem != null)
574 mergedAssets.Add(toImport.MergedItem.Id);
577 if (toImport.MergedResult.HasErrors)
579 result.Error(
"Cannot select a merge asset [{0}] that has the following merge errors:", toImport.MergedItem);
580 toImport.MergedResult.CopyTo(result);
586 foreach (var fileToImport
in Imports.Where(it => it.Enabled))
588 var assetPackage = fileToImport.Package;
589 var assetResolver = AssetResolver.FromPackage(assetPackage);
591 foreach (var toImportByImporter
in fileToImport.ByImporters.Where(it => it.Enabled))
594 toImportByImporter.Log.CopyTo(result);
597 if (toImportByImporter.HasErrors)
599 result.Warning(
"Unexpected errors while importing source [{0}] with importer [{1}]. Check the details errors log",
fileToImport.File, toImportByImporter.Importer.Name);
602 foreach (var toImport
in toImportByImporter.Items.Where(it => it.Enabled))
605 toImport.Log.CopyTo(result);
608 if (toImport.HasErrors)
610 result.Warning(
"Unexpected errors while importing asset [{0}/{1}]. Check the details errors log", toImport.Item.Location, toImport.Item.Id);
615 if (toImportByImporter.HasErrors)
617 result.Warning(
"Disable importing asset [{0}/{1}] while other assets in same group are in errors. Check the details errors log", toImport.Item.Location, toImport.Item.Id);
627 if (toImport.MergedItem != null)
629 item = toImport.MergedItem;
631 var existingItem = session.FindAsset(item.Id);
632 if (existingItem != null && existingItem.Package != null)
634 assetPackage = existingItem.Package;
638 if (assetPackage.Assets.RemoveById(item.
Id))
640 result.RemovedAssets.Add(item.Id);
641 result.AddedAssets.RemoveWhere(x => x.Id == item.Id);
647 item = toImport.SelectedItem ?? toImport.Item;
651 if (mergedAssets.Contains(item.
Id))
658 FixAssetLocation(item, fileToImport.Directory, assetResolver);
661 assetPackage.Assets.Add(item);
662 result.AddedAssets.Add(item);
679 sourceFileToAssets.Clear();
688 private List<AssetToImportMergeGroup> ComputeToImportListSorted()
690 var toImportListSorted =
new List<AssetToImportMergeGroup>();
692 var registeredTypes =
new HashSet<Type>();
693 var typeDependencies =
new Dictionary<AssetToImportMergeGroup, HashSet<Type>>();
694 foreach (var toImport
in AllImports())
696 var references = AssetReferenceAnalysis.Visit(toImport.Item.Asset);
697 var refTypes =
new HashSet<Type>(references.Select(assetLink => assetLink.Reference).OfType<AssetReference>().Select(assetRef => assetRef.Type));
699 if (refTypes.Count == 0)
701 toImportListSorted.Add(toImport);
702 registeredTypes.Add(toImport.Item.Asset.GetType());
706 typeDependencies[toImport] = refTypes;
710 var typeToRegisters =
new HashSet<Type>();
713 typeToRegisters.Clear();
714 var toImportTempList = typeDependencies.ToList();
715 foreach (var toImportWithTypes
in toImportTempList)
717 var toImport = toImportWithTypes.Key;
719 var areDependenciesResolved = toImportWithTypes.Value.All(registeredTypes.Contains);
720 if (areDependenciesResolved)
722 typeDependencies.Remove(toImport);
723 toImportListSorted.Add(toImport);
724 typeToRegisters.Add(toImport.Item.Asset.GetType());
729 if (typeToRegisters.Count == 0)
734 foreach (var newType
in typeToRegisters)
736 registeredTypes.Add(newType);
744 toImportListSorted.Reverse();
746 return toImportListSorted;
753 private void PrepareMerge(CancellationToken? cancelToken = null)
765 var toImportListSorted = ComputeToImportListSorted();
770 foreach (var toImport
in toImportListSorted)
772 var toImportByImporter = toImport.Parent;
773 var fileToImport = toImportByImporter.Parent;
777 var assetItem = toImport.Item;
778 var assetImport = assetItem.Asset as AssetImport;
779 if (assetImport == null || toImport.Merges.Count > 0)
784 if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
786 toImport.Log.Warning(
"Cancellation requested before matching asset [{0}] with location [{1}] ",
fileToImport.File, assetItem.Location);
790 var assetType = assetImport.GetType();
795 if (toImportByImporter.PreviousItem != null && toImportByImporter.PreviousItem.Asset.GetType() == assetType)
797 possibleMatches =
new List<AssetItem> { toImportByImporter.PreviousItem };
802 possibleMatches = GetOrCreateAssetsPerInput(assetImport.Source, assetType).Where(item => item.Asset.GetType() == assetType && item != assetItem).ToList();
805 foreach (var possibleMatchItem
in possibleMatches)
808 RecursiveCalculateMatchAndPrepareMerge(toImportByImporter, toImport, possibleMatchItem);
812 if (toImport.Merges.Count == 0)
814 toImport.SelectedItem = toImport.Item;
819 foreach (var toImport
in toImportListSorted)
821 toImport.Merges.Sort((left, right) =>
823 if ((left.PreviousItem.Package == null && right.PreviousItem.Package != null)
824 || (left.PreviousItem.Package != null && right.PreviousItem.Package == null))
826 return left.PreviousItem.Package == null ? 1 : -1;
829 return -left.MatchingFactor.CompareTo(right.MatchingFactor);
838 return from fileToImport in Imports.Where(it => it.Enabled) from toImportByImporter in fileToImport.ByImporters.Where(it => it.Enabled) from toImport in toImportByImporter.Items.Where(it => it.Enabled) select toImport;
841 private AssetToImport RegisterImporter(
UFile file, Package package,
UDirectory directory, IAssetImporter importer, AssetItem previousItem = null)
843 var previousEntry = Imports.FirstOrDefault(item => item.File == file);
844 if (previousEntry == null)
846 previousEntry =
new AssetToImport(file) {
Package = package, Directory = directory};
847 Imports.Add(previousEntry);
850 if (previousEntry.ByImporters.All(byImporter => byImporter.Importer != importer))
852 int index = 1 + previousEntry.ByImporters.LastIndexOf(x => x.Importer.DisplayRank > importer.DisplayRank);
853 previousEntry.ByImporters.Insert(index,
new AssetToImportByImporter(previousEntry, importer, previousItem));
856 return previousEntry;
861 var path =
new UFile(targetDirectory, item.Location.GetFileName(), null);
863 assetResolver.RegisterLocation(path, out newLocation);
864 item.Location = newLocation;
867 private void FreezeAssetImport(IAssetImporter importer, AssetItem assetItem, Package package)
870 var baseAsset = (Asset)AssetCloner.Clone(assetItem.Asset);
871 var assetImport = assetItem.Asset as AssetImport;
872 baseAsset.Id = Guid.Empty;
875 if (assetImport != null)
877 var baseAssetImport = (AssetImport)baseAsset;
878 baseAssetImport.SetAsRootImport();
880 baseAssetImport.ImporterId = importer.Id;
881 var assetImportTracked = assetImport as AssetImportTracked;
882 if (assetImportTracked != null)
884 assetImportTracked.SourceHash = FileVersionManager.Instance.ComputeFileHash(assetImport.Source);
887 assetItem.Asset.Base =
new AssetBase(baseAsset);
890 private void ComputeAssetHash(CancellationToken? cancelToken = null)
892 sourceFileToAssets.Clear();
893 var usedNames =
new HashSet<string>(StringComparer.OrdinalIgnoreCase);
898 foreach (var fileToImport
in Imports.Where(it => it.Enabled))
900 var assetPackage = fileToImport.Package;
901 var assetResolver = AssetResolver.FromPackage(assetPackage);
903 foreach (var
import in fileToImport.ByImporters.Where(it => it.Enabled))
905 foreach (var assetToImport
in import.Items.Where(it => it.Enabled))
907 if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
909 assetToImport.Log.Warning(
"Cancellation requested before computing hash for asset [{0}] with location [{1}] ",
fileToImport.File, assetToImport.Item.Location);
916 var assetItem = assetToImport.Item;
919 FixAssetLocation(assetItem, fileToImport.Directory, assetResolver);
922 FreezeAssetImport(
import.Importer, assetItem, fileToImport.Package);
925 var assetImport = assetItem.Asset as AssetImport;
926 if (assetImport != null)
929 RegisterAssetPerInput(assetImport.Source, assetItem);
932 foreach (var existingAssetItem
in session.DependencyManager.FindAssetItemsByInput(assetImport.Source))
935 if (existingAssetItem.Asset.Base == null || !existingAssetItem.Asset.Base.IsRootImport)
940 RegisterAssetPerInput(assetImport.Source, existingAssetItem);
977 private void RecursiveCalculateMatchAndPrepareMerge(AssetToImportByImporter toImport, AssetToImportMergeGroup toImportMergeGroup, AssetItem previous)
979 var newAssetBase = toImportMergeGroup.Item.Asset.Base.Asset;
980 var previousAsset = previous.Asset;
981 var previousBase = previous.Asset.Base == null || previous.Asset.Base.Asset == null ? newAssetBase : previous.Asset.Base.Asset;
984 if (toImportMergeGroup.Merges.Any(matching => matching.PreviousItem.Id == previous.Id))
990 var newAsset = (Asset)AssetCloner.Clone(previousAsset);
991 var newAssetImport = newAsset as AssetImportTracked;
992 if (newAssetImport != null)
994 var originAssetImport = (AssetImportTracked)toImportMergeGroup.Item.Asset;
995 newAssetImport.SourceHash = originAssetImport.SourceHash;
999 var assetDiff =
new AssetDiff(previousBase, newAsset, newAssetBase);
1002 var result = AssetMerge.Merge(assetDiff, MergeImportPolicy,
true);
1005 var diff3 = assetDiff.Compute();
1007 var totalChildren = diff3.CountChildren();
1008 var diffList = diff3.FindDifferences().ToList();
1010 var conflictCount = diffList.Count(node => node.HasConflict);
1013 var assetReferencesDiffs = diffList.Where(node => typeof(
IContentReference).IsAssignableFrom(node.InstanceType)).ToList();
1017 var assetMatching =
new AssetToImportMerge(previous, assetDiff, result);
1020 var subReferenceCount = assetReferencesDiffs.Count;
1023 var subReferenceMatch = 0;
1026 foreach (var referenceDiff
in assetReferencesDiffs)
1031 if (base1 != null && newRef != null)
1034 var baseItem1 = session.FindAsset(base1.Id);
1035 if (baseItem1 != null)
1038 var subImport1 = toImport.Items.Where(it => it.Enabled).FirstOrDefault(importList => importList.Item.Id == newRef.Id);
1039 if (subImport1 != null && baseItem1.Asset.GetType() == subImport1.Item.Asset.GetType())
1041 RecursiveCalculateMatchAndPrepareMerge(toImport, subImport1, baseItem1);
1044 assetMatching.DependencyGroups.Add(subImport1);
1045 subReferenceMatch++;
1049 else if (base1 == null && newRef != null)
1051 subReferenceMatch++;
1057 assetMatching.MatchingFactor = 1.0 - (double)(conflictCount + subReferenceCount - subReferenceMatch)/totalChildren;
1059 toImportMergeGroup.Merges.Add(assetMatching);
1071 return Diff3ChangeType.MergeFromAsset1;
1076 return Diff3ChangeType.MergeFromAsset2;
1079 return AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1(node);
1082 private void RegisterAssetPerInput(
string rawSourcePath, AssetItem assetItem)
1084 GetOrCreateAssetsPerInput(rawSourcePath, assetItem.Asset.GetType()).
Add(assetItem);
1087 private HashSet<AssetItem> GetOrCreateAssetsPerInput(
string rawSourcePath, Type assetType)
1089 var assetKey =
new AssetLocationTyped(rawSourcePath, assetType);
1091 if (!sourceFileToAssets.TryGetValue(assetKey, out assetsPerFile))
1094 sourceFileToAssets.Add(assetKey, assetsPerFile);
1096 return assetsPerFile;
1109 bool hasAssetImport =
false;
1110 foreach (var assetItem
in assets)
1112 if (assetItem.Id == Guid.Empty)
1114 log.Error(
"Invalid arguments while importing asset [{0}]. Requiring an asset Id not empty", assetItem);
1116 else if (ids.Contains(assetItem.Id))
1118 log.Error(
"Invalid arguments while importing asset [{0}]. An asset is already being imported with the same id", assetItem);
1122 var existingAssetItem = session.FindAsset(assetItem.Id);
1123 if (existingAssetItem != null)
1125 log.Error(
"Invalid arguments while importing asset [{0}]. An asset is already used by the package [{1}/{2}] in the current session", assetItem, existingAssetItem.Package.Id, existingAssetItem.Package.FullPath);
1129 if (assetItem.Asset.Base != null)
1131 log.Error(
"Invalid arguments while importing asset [{0}]. Base must be null", assetItem);
1134 var assetImport = assetItem.Asset as AssetImport;
1135 if (assetImport != null)
1137 hasAssetImport =
true;
1138 if (assetImport.Source == null || !assetImport.Source.IsAbsolute)
1140 log.Error(
"Invalid arguments while importing asset [{0}]. Type [{1}] cannot be null and must be an absolute location", assetItem, assetImport.Source);
1144 ids.Add(assetItem.Id);
1148 if (!hasAssetImport)
1150 log.Error(
"Error expecting at least one AssetImport while importing assets to a package");
1157 throw new InvalidOperationException(
"Unexpected error while processing items to importItem: " + log.ToText());
1161 [DebuggerDisplay(
"Location: {location}")]
1162 private struct AssetLocationTyped : IEquatable<AssetLocationTyped>
1164 public AssetLocationTyped(
string location, Type assetType)
1166 this.location = location;
1167 this.assetType = assetType;
1170 private readonly
string location;
1172 private readonly
Type assetType;
1174 public bool Equals(AssetLocationTyped other)
1176 return string.Equals(location, other.location, StringComparison.OrdinalIgnoreCase) && assetType == other.assetType;
1179 public override bool Equals(
object obj)
1181 if (ReferenceEquals(null, obj))
return false;
1182 return obj is AssetLocationTyped && Equals((AssetLocationTyped)obj);
1185 public override int GetHashCode()
1189 return (location.GetHashCode()*397) ^ assetType.GetHashCode();
1196 EventHandler<AssetImportSessionEvent> handler = Progress;
1197 if (handler != null) handler(
this,
new AssetImportSessionEvent(step, type, toImportByImporter));
1202 EventHandler<AssetImportSessionEvent> handler = Progress;
1203 if (handler != null) handler(
this,
new AssetImportSessionEvent(step, type, toImportMergeGroup));
AssetImportSessionEventType
The type of event begin or end published by AssetImportSession.Progress
Type InstanceType
Gets or sets the type of the instance. Null if instance type is different between the nodes...
Helper to find available new asset locations and identifiers.
SiliconStudio.Core.Diagnostics.LoggerResult LoggerResult
Guid Id
Gets the unique identifier of this asset.
bool IsExistingAssetForReImportSupported(AssetItem assetItem)
Determines whether the specified asset is supporting re-import.
bool Stage(CancellationToken?cancelToken=null)
Analyze files for preparing them for the merge and import steps. This must be called first after call...
The template can be applied to an existing Assets.Package.
AssetImportSession(PackageSession session)
Initializes a new instance of the AssetImportSession class.
An asset item part of a Package accessible through SiliconStudio.Assets.Package.Assets.
AssetToImport AddFile(UFile file, IAssetImporter importer, Package package, UDirectory directory)
Adds a file to import.
Describes an asset to import associated with possible existing assets, mergeable or not...
string GetFileExtension()
Gets the extension of the file. Can be null.
Let the emitter choose the style.
A session for editing a package.
Package Package
Gets the package where this asset is stored.
AssetToImport AddExistingAssetForReImport(AssetItem assetItem)
Adds an existing asset for reimport
EventHandler< AssetImportSessionEvent > Progress
Occurs when this import session is making progress.
void Merge(CancellationToken?cancelToken=null)
Merges each asset with the selected asset specified in AssetToImportMergeGroup.SelectedItem ...
Defines a normalized directory path. See UPath for details. This class cannot be inherited.
A raw asset being imported that will generate possibly multiple AssetItem
PackageSession Session
Gets the session.
bool IsAbsolute
Determines whether this instance is absolute.
string Name
Gets the name of this importer.
A logger that stores added and removed assets of an import operation.
AssetToImport AddFile(UFile file, Package package, UDirectory directory)
Adds a file to import.
The type of the serialized type will be passed as a generic arguments of the serializer. Example: serializer of A becomes instantiated as Serializer{A}.
An importable asset with a content that need to be tracked if original asset is changing.
UFile Location
Gets the location of this asset.
void Reset()
Resets the current importItem session.
string GetDirectory()
Gets the directory. Can be null.
void Import(ImportResult result)
Imports all assets
IEnumerable< AssetToImport > AddFiles(IEnumerable< UFile > files, Package package, UDirectory directory)
Adds files to import.
This class is handling importItem of assets into a session. See remarks for usage.
bool IsFileSupported(UFile file)
Determines whether the specified file is supported
ImportResult Import()
Imports all assets
Imports a raw asset into the asset system.
Class AssetDiff. This class cannot be inherited.
A package managing assets.
An interface that provides a reference to an asset.
AssetImportSessionStepType
The step being processed by the AssetImportSession
Defines a normalized file path. See UPath for details. This class cannot be inherited.