4 using System.Collections.Generic;
5 using System.Collections.Specialized;
6 using System.Diagnostics;
9 using System.Threading;
10 using System.Threading.Tasks;
11 using SiliconStudio.Assets.Visitors;
12 using SiliconStudio.Core;
13 using SiliconStudio.Core.Diagnostics;
14 using SiliconStudio.Core.IO;
15 using SiliconStudio.Core.Reflection;
16 using SiliconStudio.Core.Serialization;
17 using SiliconStudio.Core.Storage;
19 namespace SiliconStudio.Assets.Analysis
37 internal readonly
object ThisLock =
new object();
38 internal readonly HashSet<Package> Packages;
39 internal readonly Dictionary<Guid, AssetDependencySet> Dependencies;
40 internal readonly Dictionary<Guid, AssetDependencySet> AssetsWithMissingReferences;
41 internal readonly Dictionary<Guid, HashSet<AssetDependencySet>> MissingReferencesToParent;
45 private readonly Dictionary<Package, string> packagePathsTracked =
new Dictionary<Package, string>();
46 private readonly Dictionary<Guid, HashSet<UFile>> mapAssetToInputDependencies =
new Dictionary<Guid, HashSet<UFile>>();
47 private readonly Dictionary<string, HashSet<Guid>> mapInputDependencyToAssets =
new Dictionary<string, HashSet<Guid>>(StringComparer.OrdinalIgnoreCase);
48 private readonly List<FileEvent> fileEvents =
new List<FileEvent>();
49 private readonly List<FileEvent> fileEventsWorkingCopy =
new List<FileEvent>();
50 private readonly ManualResetEvent threadWatcherEvent;
51 private readonly List<AssetFileChangedEvent> currentAssetFileChangedEvents =
new List<AssetFileChangedEvent>();
52 private readonly CancellationTokenSource tokenSourceForImportHash;
53 private readonly List<AssetFileChangedEvent> sourceImportFileChangedEventsToAdd =
new List<AssetFileChangedEvent>();
54 private Thread fileEventThreadHandler;
55 private int trackingSleepTime;
56 private bool isDisposed;
57 private bool isDisposing;
58 private bool isTrackingPaused;
59 private bool isSessionSaving;
60 private readonly HashSet<string> assetsBeingSaved =
new HashSet<string>(StringComparer.OrdinalIgnoreCase);
61 private readonly AssetFileChangedEventSquasher assetFileChangedEventSquasher =
new AssetFileChangedEventSquasher();
62 private bool isInitialized;
78 if (session == null)
throw new ArgumentNullException(
"session");
79 this.session = session;
80 this.session.Packages.CollectionChanged += Packages_CollectionChanged;
81 session.AssetDirtyChanged += Session_AssetDirtyChanged;
82 AssetsWithMissingReferences =
new Dictionary<Guid, AssetDependencySet>();
83 MissingReferencesToParent =
new Dictionary<Guid, HashSet<AssetDependencySet>>();
84 Packages =
new HashSet<Package>();
85 Dependencies =
new Dictionary<Guid, AssetDependencySet>();
86 TrackingSleepTime = 1000;
87 tokenSourceForImportHash =
new CancellationTokenSource();
88 threadWatcherEvent =
new ManualResetEvent(
false);
106 public bool EnableTracking
110 return fileEventThreadHandler != null;
116 throw new InvalidOperationException(
"Cannot enable tracking when this instance is disposed");
123 bool activateTracking =
false;
127 DirectoryWatcher.Modified += directoryWatcher_Modified;
128 activateTracking =
true;
131 if (fileEventThreadHandler == null)
133 fileEventThreadHandler =
new Thread(
SafeAction.
Wrap(RunChangeWatcher)) { IsBackground =
true, Name =
"RunChangeWatcher thread" };
134 fileEventThreadHandler.Start();
137 if (activateTracking)
146 DirectoryWatcher.Dispose();
150 if (fileEventThreadHandler != null)
152 threadWatcherEvent.Set();
153 fileEventThreadHandler.Join();
154 fileEventThreadHandler = null;
168 public bool IsInitialized
172 return isInitialized;
180 public bool IsTrackingPaused
184 return isTrackingPaused;
191 isTrackingPaused = value;
199 public int TrackingSleepTime
203 return trackingSleepTime;
209 throw new ArgumentOutOfRangeException(
"value",
"TrackingSleepTime must be > 0");
211 trackingSleepTime = value;
224 tokenSourceForImportHash.Cancel();
225 EnableTracking =
false;
229 DirectoryWatcher.Dispose();
246 var eventsCopy = assetFileChangedEventSquasher.Squash(currentAssetFileChangedEvents);
247 currentAssetFileChangedEvents.Clear();
262 if (Dependencies.TryGetValue(assetId, out dependencySet))
268 return dependencySet;
282 if (Dependencies.TryGetValue(assetId, out dependencySet))
284 list.AddRange(dependencySet.Parents.Where(parent => parent.Asset.Base != null && parent.Asset.Base.Id == assetId).Select(item => item.Clone(
true)));
298 if (importFile == null)
throw new ArgumentNullException(
"importFile");
301 HashSet<Guid> assets;
302 if (mapInputDependencyToAssets.TryGetValue(importFile, out assets))
304 return new HashSet<Guid>(assets);
306 return new HashSet<Guid>();
318 if (importFile == null)
throw new ArgumentNullException(
"importFile");
321 var ids = FindAssetIdsByInput(importFile);
323 foreach (var
id in ids)
325 items.Add(Dependencies[id].Item.Clone(
true));
339 if (assetItem == null)
throw new ArgumentNullException(
"assetItem");
340 bool recursive = (dependenciesOptions & AssetDependencySearchOptions.Recursive) != 0;
341 if (visited == null && recursive)
342 visited =
new HashSet<Guid>();
350 int inCount = 0, outCount = 0;
354 CollectInputReferences(dependencySet, assetItem, visited, recursive, ref inCount);
363 CollectOutputReferences(dependencySet, assetItem, visited, recursive, ref outCount);
368 return dependencySet;
377 public bool HasMissingReferences
383 return AssetsWithMissingReferences.Count > 0;
396 return AssetsWithMissingReferences.Keys.ToList();
411 if (AssetsWithMissingReferences.TryGetValue(assetId, out dependencySet))
413 return dependencySet.MissingReferences.ToList();
420 private object Initialize()
437 foreach (var package
in session.Packages)
446 TrackPackage(package);
449 isInitialized =
true;
461 private static void CollectDynamicOutReferences(AssetDependencySet result, PackageSession packageSession,
bool isRecursive,
bool keepParents)
463 if (packageSession == null)
throw new ArgumentNullException(
"packageSession");
464 CollectDynamicOutReferences(result, packageSession.FindAsset, isRecursive, keepParents);
478 private static void CollectDynamicOutReferences(AssetDependencySet result, Func<Guid, AssetItem> assetResolver,
bool isRecursive,
bool keepParents)
480 if (result == null)
throw new ArgumentNullException(
"result");
481 if (assetResolver == null)
throw new ArgumentNullException(
"assetResolver");
483 var addedReferences =
new HashSet<Guid>();
484 var itemsToAnalyze =
new Queue<AssetItem>();
485 var referenceCollector =
new DependenciesCollector();
487 result.Reset(keepParents);
489 var assetItem = result.Item;
492 addedReferences.Add(assetItem.Id);
493 itemsToAnalyze.Enqueue(assetItem);
495 while (itemsToAnalyze.Count > 0)
497 var item = itemsToAnalyze.Dequeue();
499 foreach (var contentReference
in referenceCollector.GetDependencies(item))
501 if (addedReferences.Contains(contentReference.Id))
505 addedReferences.Add(contentReference.Id);
508 var nextItem = assetResolver(contentReference.Id);
509 if (nextItem != null)
511 result.Add(nextItem);
516 itemsToAnalyze.Enqueue(nextItem);
521 result.AddMissingReference(contentReference);
532 private AssetItem FindAssetFromDependencyOrSession(Guid guid)
536 var item = session.FindAsset(guid);
539 var dependencies = TrackAsset(guid);
540 return dependencies.Item;
550 isSessionSaving =
true;
558 internal void AddFileBeingSaveDuringSessionSave(
UFile file)
560 if (file == null)
throw new ArgumentNullException(
"file");
561 if (!isSessionSaving)
throw new InvalidOperationException(
"Cannot call this method outside a BeginSavingSession/EndSavingSession");
565 assetsBeingSaved.Add(file);
574 isSessionSaving =
false;
579 foreach (var package
in Packages)
581 UpdatePackagePathTracked(package,
true);
595 if (!Dependencies.TryGetValue(assetItem.
Id, out dependencySet))
600 CollectDynamicOutReferences(dependencySet, FindAssetFromDependencyOrSession,
false,
false);
602 return dependencySet;
609 private void TrackPackage(Package package)
613 if (Packages.Contains(package))
616 Packages.Add(package);
618 foreach (var asset
in package.Assets)
630 package.Assets.CollectionChanged += Assets_CollectionChanged;
631 UpdatePackagePathTracked(package,
true);
639 private void UnTrackPackage(Package package)
643 if (!Packages.Contains(package))
646 package.Assets.CollectionChanged -= Assets_CollectionChanged;
648 foreach (var asset
in package.Assets)
653 Packages.Remove(package);
654 UpdatePackagePathTracked(package,
false);
663 private AssetDependencySet TrackAsset(AssetItem assetItemSource)
665 return TrackAsset(assetItemSource.Id);
672 private AssetDependencySet TrackAsset(Guid assetId)
676 AssetDependencySet dependencies;
677 if (Dependencies.TryGetValue(assetId, out dependencies))
683 var assetItem = session.FindAsset(assetId);
684 if (assetItem == null)
694 var assetItemCloned = assetItem.Package.IsSystem
696 :
new AssetItem(assetItem.Location, (Asset)AssetCloner.Clone(assetItem.Asset))
699 SourceFolder = assetItem.SourceFolder
702 dependencies =
new AssetDependencySet(assetItemCloned);
705 Dependencies.Add(assetId, dependencies);
708 UpdateAssetDependencies(dependencies);
709 CheckAllDependencies();
715 private void CheckAllDependencies()
733 private void UnTrackAsset(AssetItem assetItemSource)
737 var assetId = assetItemSource.Id;
738 AssetDependencySet dependencySet;
739 if (!Dependencies.TryGetValue(assetId, out dependencySet))
743 Dependencies.Remove(assetId);
746 RemoveMissingDependencies(dependencySet);
749 foreach (var childItem
in dependencySet)
751 AssetDependencySet childDependencyItem;
752 if (Dependencies.TryGetValue(childItem.Id, out childDependencyItem))
754 childDependencyItem.Parents.Remove(dependencySet.Item);
759 var missingReference = dependencySet.Item.ToReference();
760 foreach (var parentItem
in dependencySet.Parents)
762 var parentDependencySet = Dependencies[parentItem.Id];
763 parentDependencySet.Remove(dependencySet.Item);
764 parentDependencySet.AddMissingReference(missingReference);
766 UpdateMissingDependencies(parentDependencySet);
770 UpdateAssetImportPathsTracked(dependencySet.Item,
false);
773 CheckAllDependencies();
776 private void UpdateAssetDependencies(AssetDependencySet dependencySet)
781 UpdateAssetImportPathsTracked(dependencySet.Item,
true);
784 RemoveMissingDependencies(dependencySet);
787 foreach (var referenceAsset
in dependencySet)
789 var childDependencyItem = TrackAsset(referenceAsset);
790 if (childDependencyItem != null)
792 childDependencyItem.Parents.Remove(dependencySet.Item);
797 CollectDynamicOutReferences(dependencySet, FindAssetFromDependencyOrSession,
false,
true);
800 foreach (var referenceAsset
in dependencySet)
802 var childDependencyItem = TrackAsset(referenceAsset);
803 if (childDependencyItem != null)
805 childDependencyItem.Parents.Add(dependencySet.Item);
810 UpdateMissingDependencies(dependencySet);
814 private void RemoveMissingDependencies(AssetDependencySet dependencySet)
816 if (AssetsWithMissingReferences.ContainsKey(dependencySet.Item.Id))
818 AssetsWithMissingReferences.Remove(dependencySet.Item.Id);
819 foreach (var reference
in dependencySet.MissingReferences)
821 var list = MissingReferencesToParent[reference.Id];
822 list.Remove(dependencySet);
825 MissingReferencesToParent.Remove(reference.Id);
831 private void UpdateMissingDependencies(AssetDependencySet dependencySet)
833 HashSet<AssetDependencySet> parentDependencyItems;
835 if (dependencySet.HasMissingReferences)
837 AssetsWithMissingReferences[dependencySet.Item.Id] = dependencySet;
839 foreach (var reference
in dependencySet.MissingReferences)
841 if (!MissingReferencesToParent.TryGetValue(reference.Id, out parentDependencyItems))
843 parentDependencyItems =
new HashSet<AssetDependencySet>();
844 MissingReferencesToParent.Add(reference.Id, parentDependencyItems);
847 parentDependencyItems.Add(dependencySet);
851 var item = dependencySet.Item;
854 if (MissingReferencesToParent.TryGetValue(item.Id, out parentDependencyItems))
856 MissingReferencesToParent.Remove(item.Id);
857 foreach (var dependency
in parentDependencyItems)
860 dependency.RemoveMissingReference(item.Id);
863 dependency.Add(item);
866 dependencySet.Parents.Add(dependency.Item);
869 if (!dependency.HasMissingReferences)
871 AssetsWithMissingReferences.Remove(dependency.Item.Id);
877 private void UpdatePackagePathTracked(Package package,
bool isTracking)
880 if (package.IsSystem)
889 string previousLocation;
890 packagePathsTracked.TryGetValue(package, out previousLocation);
892 string newLocation = package.RootDirectory;
893 bool trackNewLocation = newLocation != null && Directory.Exists(newLocation);
894 if (previousLocation != null)
896 bool unTrackPreviousLocation =
false;
898 if (package.RootDirectory == null)
900 unTrackPreviousLocation =
true;
901 trackNewLocation =
false;
905 newLocation = package.RootDirectory;
906 if (
string.Compare(previousLocation, newLocation, StringComparison.OrdinalIgnoreCase) != 0)
908 unTrackPreviousLocation =
true;
913 trackNewLocation =
false;
918 if (unTrackPreviousLocation)
920 packagePathsTracked.Remove(package);
923 DirectoryWatcher.UnTrack(previousLocation);
928 if (trackNewLocation)
931 packagePathsTracked[package] = newLocation;
934 DirectoryWatcher.Track(newLocation);
940 string previousLocation;
941 if (packagePathsTracked.TryGetValue(package, out previousLocation))
946 DirectoryWatcher.UnTrack(previousLocation);
948 packagePathsTracked.Remove(package);
954 private void TrackAssetImportInput(AssetItem assetItem,
string inputPath)
958 HashSet<Guid> assetsTrackedByPath;
959 if (!mapInputDependencyToAssets.TryGetValue(inputPath, out assetsTrackedByPath))
961 assetsTrackedByPath =
new HashSet<Guid>();
962 mapInputDependencyToAssets.Add(inputPath, assetsTrackedByPath);
965 DirectoryWatcher.Track(inputPath);
968 assetsTrackedByPath.Add(assetItem.Id);
972 FileVersionManager.Instance.ComputeFileHashAsync(inputPath, SourceImportFileHashCallback, tokenSourceForImportHash.Token);
975 private void ActivateTracking()
980 files = mapInputDependencyToAssets.Keys.ToList();
982 foreach (var inputPath
in files)
984 DirectoryWatcher.Track(inputPath);
985 FileVersionManager.Instance.ComputeFileHashAsync(inputPath, SourceImportFileHashCallback, tokenSourceForImportHash.Token);
989 private void UnTrackAssetImportInput(AssetItem assetItem,
string inputPath)
993 HashSet<Guid> assetsTrackedByPath;
994 if (mapInputDependencyToAssets.TryGetValue(inputPath, out assetsTrackedByPath))
996 assetsTrackedByPath.Remove(assetItem.Id);
997 if (assetsTrackedByPath.Count == 0)
999 mapInputDependencyToAssets.Remove(inputPath);
1002 DirectoryWatcher.UnTrack(inputPath);
1009 private void UpdateAssetImportPathsTracked(AssetItem assetItem,
bool isTracking)
1012 var assetImport = assetItem.Asset as AssetImport;
1013 if (assetImport == null)
1021 var newInputPathDependencies =
new HashSet<UFile>();
1022 if (assetImport.Base != null && assetImport.Base.IsRootImport)
1024 var pathToSourceRawAsset = assetImport.Source;
1025 if (pathToSourceRawAsset == null)
1029 if (!pathToSourceRawAsset.IsAbsolute)
1031 pathToSourceRawAsset = UPath.Combine(assetItem.FullPath.GetParent(), pathToSourceRawAsset);
1034 newInputPathDependencies.Add(pathToSourceRawAsset);
1037 HashSet<UFile> inputPaths;
1038 if (mapAssetToInputDependencies.TryGetValue(assetItem.Id, out inputPaths))
1041 foreach (var inputPath
in inputPaths)
1043 if (!newInputPathDependencies.Contains(inputPath))
1045 UnTrackAssetImportInput(assetItem, inputPath);
1050 foreach (var inputPath
in newInputPathDependencies)
1052 if (!inputPaths.Contains(inputPath))
1054 TrackAssetImportInput(assetItem, inputPath);
1061 foreach (var inputPath
in newInputPathDependencies)
1063 TrackAssetImportInput(assetItem, inputPath);
1067 mapAssetToInputDependencies[assetItem.Id] = newInputPathDependencies;
1071 HashSet<UFile> inputPaths;
1072 if (mapAssetToInputDependencies.TryGetValue(assetItem.Id, out inputPaths))
1074 mapAssetToInputDependencies.Remove(assetItem.Id);
1075 foreach (var inputPath
in inputPaths)
1077 UnTrackAssetImportInput(assetItem, inputPath);
1083 private void directoryWatcher_Modified(
object sender,
FileEvent e)
1086 if (!EnableTracking)
1096 private void Session_AssetDirtyChanged(Asset asset)
1101 if (isSessionSaving)
1108 AssetDependencySet dependencySet;
1109 if (Dependencies.TryGetValue(asset.Id, out dependencySet))
1111 dependencySet.Item.Asset = (Asset)AssetCloner.Clone(asset);
1112 UpdateAssetDependencies(dependencySet);
1115 OnAssetChanged(dependencySet.Item);
1119 var
package = asset as Package;
1120 if (package != null)
1122 UpdatePackagePathTracked(package,
true);
1127 CheckAllDependencies();
1130 private void Packages_CollectionChanged(
object sender, NotifyCollectionChangedEventArgs e)
1134 case NotifyCollectionChangedAction.Add:
1135 TrackPackage((Package)e.NewItems[0]);
1137 case NotifyCollectionChangedAction.Remove:
1138 UnTrackPackage((Package)e.OldItems[0]);
1141 case NotifyCollectionChangedAction.Replace:
1142 foreach (var oldPackage
in e.OldItems.OfType<Package>())
1144 UnTrackPackage(oldPackage);
1147 foreach (var packageToCopy
in session.Packages)
1149 TrackPackage(packageToCopy);
1155 private void Assets_CollectionChanged(
object sender, NotifyCollectionChangedEventArgs e)
1159 case NotifyCollectionChangedAction.Add:
1160 TrackAsset(((AssetItem)e.NewItems[0]));
1162 case NotifyCollectionChangedAction.Remove:
1163 UnTrackAsset(((AssetItem)e.OldItems[0]));
1166 case NotifyCollectionChangedAction.Reset:
1167 var collection = (PackageAssetCollection)sender;
1169 var items = Dependencies.Values.Where(item => ReferenceEquals(item.Item.Package, collection.Package)).ToList();
1170 foreach (var assetItem
in items)
1172 UnTrackAsset(assetItem.Item);
1174 foreach (var assetItem
in collection)
1176 TrackAsset(assetItem);
1186 private void RunChangeWatcher()
1191 if (threadWatcherEvent.WaitOne(TrackingSleepTime))
1195 fileEventsWorkingCopy.Clear();
1198 fileEventsWorkingCopy.AddRange(fileEvents);
1202 if (fileEventsWorkingCopy.Count == 0 || isTrackingPaused)
1205 var assetEvents =
new List<AssetFileChangedEvent>();
1210 var packages = Packages;
1213 foreach (var fileEvent
in fileEventsWorkingCopy)
1215 var file =
new UFile(fileEvent.FullPath);
1219 if (assetsBeingSaved.Contains(file.FullPath))
1227 if (mapInputDependencyToAssets.ContainsKey(file.FullPath))
1230 FileVersionManager.Instance.ComputeFileHashAsync(file.FullPath, SourceImportFileHashCallback, tokenSourceForImportHash.Token);
1235 if (!AssetRegistry.IsAssetFileExtension(file.GetFileExtension()))
1243 foreach (var package
in packages)
1245 var rootDirectory = package.RootDirectory;
1246 if (rootDirectory == null)
1249 if (rootDirectory.Contains(file) && (parentPackagePath == null || parentPackagePath.FullPath.Length < rootDirectory.FullPath.Length))
1251 parentPackagePath = rootDirectory;
1252 parentPackage = package;
1257 if (parentPackage != null)
1259 var relativeLocation = file.MakeRelative(parentPackagePath);
1261 var item = parentPackage.Assets.Find(relativeLocation);
1262 AssetFileChangedEvent evt = null;
1263 switch (fileEvent.ChangeType)
1265 case FileEventChangeType.Created:
1268 case FileEventChangeType.Deleted:
1269 evt =
new AssetFileChangedEvent(parentPackage,
AssetFileChangedType.Deleted, relativeLocation);
1271 case FileEventChangeType.Changed:
1272 evt =
new AssetFileChangedEvent(parentPackage,
AssetFileChangedType.Updated, relativeLocation);
1279 evt.AssetId = item.Id;
1281 assetEvents.Add(evt);
1289 foreach (var fileEvent
in fileEventsWorkingCopy)
1291 var file =
new UFile(fileEvent.FullPath);
1295 if (assetsBeingSaved.Remove(file))
1297 if (assetsBeingSaved.Count == 0)
1306 if (assetEvents.Count > 0 && !isTrackingPaused)
1308 currentAssetFileChangedEvents.AddRange(assetEvents);
1320 private void SourceImportFileHashCallback(
UFile sourceFile,
ObjectId hash)
1324 HashSet<Guid> items;
1325 if (!mapInputDependencyToAssets.TryGetValue(sourceFile, out items))
1329 foreach (var itemId
in items)
1331 AssetDependencySet dependencySet;
1332 Dependencies.TryGetValue(itemId, out dependencySet);
1333 if (dependencySet == null)
1338 var item = dependencySet.Item;
1340 var assetImport = item.Asset as AssetImportTracked;
1341 if (assetImport != null && assetImport.Base != null && assetImport.Base.IsRootImport && assetImport.SourceHash != hash)
1348 sourceImportFileChangedEventsToAdd.Add(
new AssetFileChangedEvent(item.Package, changeType, item.Location) { AssetId = assetImport.Id, Hash = hash });
1352 if (sourceImportFileChangedEventsToAdd.Count > 0 && !isTrackingPaused)
1354 currentAssetFileChangedEvents.AddRange(sourceImportFileChangedEventsToAdd);
1356 sourceImportFileChangedEventsToAdd.Clear();
1360 private void CollectInputReferences(AssetDependencySet dependencyRoot, AssetItem assetItem, HashSet<Guid> visited,
bool recursive, ref
int count)
1362 var assetId = assetItem.Id;
1363 if (visited != null)
1365 if (visited.Contains(assetId))
1368 visited.Add(assetId);
1373 AssetDependencySet dependencies;
1374 Dependencies.TryGetValue(assetId, out dependencies);
1375 if (dependencies != null)
1377 foreach (var parentItem
in dependencies.Parents)
1379 dependencyRoot.Parents.Add(parentItem.Clone(
true));
1381 if (visited != null && recursive)
1383 CollectInputReferences(dependencyRoot, parentItem, visited, recursive, ref count);
1389 private void CollectOutputReferences(AssetDependencySet dependencyRoot, AssetItem assetItem, HashSet<Guid> visited,
bool recursive, ref
int count)
1391 var assetId = assetItem.Id;
1392 if (visited != null)
1394 if (visited.Contains(assetId))
1397 visited.Add(assetId);
1402 var dependencies = CalculateDependencies(assetItem);
1405 foreach (var missingRef
in dependencies.MissingReferences)
1407 dependencyRoot.AddMissingReference(missingRef);
1411 foreach (var child
in dependencies)
1413 dependencyRoot.Add(child.Clone(
true));
1415 if (visited != null && recursive)
1417 CollectOutputReferences(dependencyRoot, child, visited, recursive, ref count);
1425 private interface IDependenciesCollector
1438 private class DependenciesCollector :
AssetVisitorBase, IDependenciesCollector
1440 private readonly HashSet<IContentReference> collectedReferences =
new HashSet<IContentReference>();
1444 collectedReferences.Clear();
1448 return collectedReferences;
1450 public override void VisitObject(
object obj,
ObjectDescriptor descriptor,
bool visitMembers)
1453 if (reference != null)
1456 if (reference is AssetBase && ((AssetBase)reference).IsRootImport)
1461 collectedReferences.Add(reference);
1465 base.VisitObject(obj, descriptor, visitMembers);
1470 private void OnAssetChanged(AssetItem obj)
1472 Action<AssetItem> handler = AssetChanged;
1476 if (handler != null) handler(obj.Clone(
true));
IEnumerable< Package > LocalPackages
Gets the user packages (excluding system packages).
void EndSavingSession()
This methods is called when a session has been saved.
Guid Id
Gets the unique identifier of this asset.
Default implementation of a ITypeDescriptor.
void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resourc...
static ThreadStart Wrap(ThreadStart action, [CallerFilePath] string sourceFilePath="", [CallerMemberName] string memberName="", [CallerLineNumber] int sourceLineNumber=0)
The template can be applied to an existing Assets.Package.
An asset item part of a Package accessible through SiliconStudio.Assets.Package.Assets.
IEnumerable< AssetFileChangedEvent > FindAssetFileChangedEvents()
Finds the changed events that have occured, only valid if EnableTracking is set to true...
void BeginSavingSession()
This methods is called when a session is about to being saved.
HashSet< AssetItem > FindAssetItemsByInput(string importFile)
Finds the asset items by their input/import file.
A session for editing a package.
Describes dependencies (in/out/miss) for a specific asset.
AssetDependencySet FindDependencySet(Guid assetId)
Finds the dependencies for the specified asset.
Defines a normalized directory path. See UPath for details. This class cannot be inherited.
List< AssetItem > FindAssetsInheritingFrom(Guid assetId)
Finds the assets inheriting from the specified asset id (this is a direct inheritance, not indirect).
HashSet< Guid > FindAssetIdsByInput(string importFile)
Finds the asset items by their input/import file.
Track file system events from several directories.
A class responsible for providing asset dependencies for a PackageSession and file tracking dependenc...
AssetFileChangedType
Type of a change event for an asset.
A hash to uniquely identify data.
An interface that provides a reference to an asset.
IEnumerable< Guid > FindAssetsWithMissingReferences()
Finds the assets with missing references.
Ä file event used notified by DirectoryWatcher
AssetDependencySearchOptions
Options used when searching asset dependencies.
Action< AssetItem > AssetChanged
Occurs when a asset changed. This event is called in the critical section of the dependency manager...
AssetDependencySet ComputeDependencies(AssetItem assetItem, AssetDependencySearchOptions dependenciesOptions=AssetDependencySearchOptions.All, HashSet< Guid > visited=null)
Computes the dependencies for the specified asset.
Defines a normalized file path. See UPath for details. This class cannot be inherited.
IEnumerable< IContentReference > FindMissingReferences(Guid assetId)
Finds the missing references for a particular asset.