Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AssetCompilerBase.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 using SiliconStudio.Core.IO;
6 
7 namespace SiliconStudio.Assets.Compiler
8 {
9  /// <summary>
10  /// Base implementation for <see cref="IAssetCompiler"/> suitable to compile a single type of <see cref="Asset"/>.
11  /// </summary>
12  /// <typeparam name="T">Type of the asset</typeparam>
13  public abstract class AssetCompilerBase<T> : IAssetCompiler where T : Asset
14  {
15  /// <summary>
16  /// The current <see cref="AssetItem"/> to compile.
17  /// </summary>
18  protected AssetItem AssetItem;
19 
21  {
22  if (context == null) throw new ArgumentNullException("context");
23  if (assetItem == null) throw new ArgumentNullException("assetItem");
24 
25  AssetItem = assetItem;
26 
27  var result = new AssetCompilerResult(GetType().Name);
28 
29  // Only use the path to the asset without its extension
30  var fullPath = assetItem.FullPath;
31  if (!fullPath.IsAbsolute)
32  {
33  throw new InvalidOperationException("assetItem must be an absolute path");
34  }
35 
36  Compile((AssetCompilerContext)context, assetItem.Location.GetDirectoryAndFileName(), assetItem.FullPath, (T)assetItem.Asset, result);
37  return result;
38  }
39 
40  /// <summary>
41  /// Compiles the asset from the specified package.
42  /// </summary>
43  /// <param name="context"></param>
44  /// <param name="urlInStorage">The absolute URL to the asset, relative to the storage.</param>
45  /// <param name="assetAbsolutePath">Absolute path of the asset on the disk</param>
46  /// <param name="asset">The asset.</param>
47  /// <param name="result">The result where the commands and logs should be output.</param>
48  protected abstract void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, T asset, AssetCompilerResult result);
49  }
50 }
Result of a compilation of assets when using IAssetCompiler.Compile
Base class for Asset.
Definition: Asset.cs:14
The context used when compiling an asset in a Package.
An asset item part of a Package accessible through SiliconStudio.Assets.Package.Assets.
Definition: AssetItem.cs:17
The context used when compiling an asset in a Package.
UFile Location
Gets the location of this asset.
Definition: AssetItem.cs:51
AssetItem AssetItem
The current AssetItem to compile.
AssetCompilerResult Compile(CompilerContext context, AssetItem assetItem)
Compiles a list of assets from the specified package.
string GetDirectoryAndFileName()
Gets the file path (UPath.GetDirectory() + '/' + UFile.GetFileName()) without the extension or drive...
Definition: UFile.cs:61
Main interface for compiling an Asset.
Asset Asset
Gets or sets the asset.
Definition: AssetItem.cs:197
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13