Exemplo n.º 1
0
        /// <summary>
        /// Generates a <see cref="ListBuildStep"/> to compile the thumbnail of the given asset.
        /// </summary>
        /// <param name="assetItem">The asset to compile.</param>
        /// <param name="gameSettings">The current game settings</param>
        /// <param name="staticThumbnail">If the asset has to be compiled as well in the case of non static thumbnail</param>
        /// <returns>A <see cref="ListBuildStep"/> containing the build steps to generate the thumbnail of the given asset.</returns>
        public ListBuildStep Compile(AssetItem assetItem, GameSettingsAsset gameSettings, bool staticThumbnail)
        {
            if (assetItem == null)
            {
                throw new ArgumentNullException(nameof(assetItem));
            }

            using (var context = new ThumbnailCompilerContext
            {
                Platform = PlatformType.Windows
            })
            {
                context.SetGameSettingsAsset(gameSettings);
                context.CompilationContext = typeof(PreviewCompilationContext);

                context.Properties.Set(ThumbnailGenerator.Key, generator);
                context.ThumbnailBuilt += builtAction;

                var result = new AssetCompilerResult();

                if (!staticThumbnail)
                {
                    //compile the actual asset
                    result = dependenciesCompiler.Prepare(context, assetItem);
                }

                //compile the actual thumbnail
                var thumbnailStep = CompileItem(context, result, assetItem);

                foreach (var buildStep in result.BuildSteps)
                {
                    BuildStep.LinkBuildSteps(buildStep, thumbnailStep);
                }
                result.BuildSteps.Add(thumbnailStep);
                return(result.BuildSteps);
            }
        }