6 using System.Threading.Tasks;
8 using SiliconStudio.BuildEngine;
9 using SiliconStudio.Core.IO;
10 using SiliconStudio.Core.Serialization.Assets;
11 using SiliconStudio.Core.Storage;
13 namespace SiliconStudio.Assets.Compiler
19 public abstract class ThumbnailCompilerBase<T> : AssetDependenciesCompilerBase<T> where T :
Asset
21 private class ThumbnailFailureBuildStep :
BuildStep
23 public override string Title {
get {
return "FailureThumbnail"; } }
27 return Task.FromResult(ResultStatus.Failed);
32 return new ThumbnailFailureBuildStep();
35 public override string ToString()
46 if (context == null)
throw new ArgumentNullException(
"context");
47 if (assetItem == null)
throw new ArgumentNullException(
"assetItem");
54 return compilerResult;
62 var assetStorageUrl = AssetItem.Location.GetDirectoryAndFileName();
63 var thumbnailStorageUrl = assetStorageUrl.Insert(0,
"__THUMBNAIL__");
68 AssetsSession = AssetItem.Package.Session;
71 Compile(thumbnailCompilerContext, thumbnailStorageUrl,
AssetItem.
FullPath, compilerResult);
76 compilerResult.BuildSteps = null;
85 compilerResult.BuildSteps =
new ListBuildStep {
new ThumbnailFailureBuildStep() };
89 compilerResult.BuildSteps.StepProcessed += (_, buildStepArgs) => OnThumbnailStepProcessed(thumbnailCompilerContext, currentAsset, thumbnailStorageUrl, buildStepArgs);
90 return compilerResult;
100 var result = ThumbnailBuildResult.Failed;
102 result = ThumbnailBuildResult.Succeeded;
104 result = ThumbnailBuildResult.Cancelled;
106 var changed = buildStepEventArgs.Step.Status != ResultStatus.NotTriggeredWasSuccessful;
109 Stream thumbnailStream = null;
110 ObjectId thumbnailHash = ObjectId.Empty;
114 thumbnailStream = AssetManager.FileProvider.OpenStream(thumbnailStorageUrl, VirtualFileMode.Open, VirtualFileAccess.Read);
115 thumbnailHash = AssetManager.FileProvider.AssetIndexMap[thumbnailStorageUrl];
117 context.NotifyThumbnailBuilt(assetItem, result, changed, thumbnailStream, thumbnailHash);
120 if (thumbnailStream != null)
121 thumbnailStream.Dispose();
131 protected abstract void Compile(ThumbnailCompilerContext context,
string thumbnailStorageUrl,
UFile assetAbsolutePath, AssetCompilerResult result);
Result of a compilation of assets when using IAssetCompiler.Compile
ResultStatus Status
The status of the result.
The context used when compiling an asset in a Package.
sealed override AssetCompilerResult Compile(CompilerContext context, AssetItem assetItem)
Compiles a list of assets from the specified package.
An asset item part of a Package accessible through SiliconStudio.Assets.Package.Assets.
ResultStatus
Status of a command.
The context used when compiling an asset in a Package.
ListBuildStep BuildSteps
Gets or sets the build steps generated for the build engine. This can be null if LoggerResult.HasErrors is true.
bool Succeeded
Indicate whether the result corresponds to a successful execution (even if the command has not been t...
UFile FullPath
Gets the full absolute path of this asset on the disk, taking into account the SourceFolder, and the SiliconStudio.Assets.Package.RootDirectory. See remarks.
bool ShouldNotifyThumbnailBuilt
Indicate whether the fact that a thumbnail has been built should be notified with NotifyThumbnailBuil...
A hash to uniquely identify data.
bool HasErrors
Gets or sets a value indicating whether this instance has errors.
sealed override AssetCompilerResult CompileOverride(AssetCompilerContext context, AssetCompilerResult compilerResult)
Asset Asset
Gets or sets the asset.
The context used when building the thumbnail of an asset in a Package.
Defines a normalized file path. See UPath for details. This class cannot be inherited.