Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AssetImporterParameters.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 using System.Collections.Generic;
5 using System.Linq;
6 
7 using SiliconStudio.Core;
8 using SiliconStudio.Core.Diagnostics;
9 
10 namespace SiliconStudio.Assets
11 {
12  /// <summary>
13  /// Parameters used by <see cref="IAssetImporter.Import"/>
14  /// </summary>
16  {
17  /// <summary>
18  /// Gets or sets the logger to use during the import.
19  /// </summary>
20  public Logger Logger { get; set; }
21 
22  /// <summary>
23  /// Initializes a new instance of the <see cref="AssetImporterParameters"/> class.
24  /// </summary>
26  {
27  SelectedOutputTypes = new Dictionary<Type, bool>();
28  }
29 
30  /// <summary>
31  /// Initializes a new instance of the <see cref="AssetImporterParameters"/> class.
32  /// </summary>
33  /// <param name="supportedTypes">The supported types.</param>
34  public AssetImporterParameters(params Type[] supportedTypes) : this((IEnumerable<Type>)supportedTypes)
35  {
36  }
37 
38  /// <summary>
39  /// Initializes a new instance of the <see cref="AssetImporterParameters"/> class.
40  /// </summary>
41  /// <param name="supportedTypes">The supported types.</param>
42  /// <exception cref="System.ArgumentNullException">supportedTypes</exception>
43  /// <exception cref="System.ArgumentException">Invalid type [{0}]. Type must be assignable to Asset.ToFormat(type);supportedTypes</exception>
44  public AssetImporterParameters(IEnumerable<Type> supportedTypes) : this()
45  {
46  if (supportedTypes == null) throw new ArgumentNullException("supportedTypes");
47  foreach (var type in supportedTypes)
48  {
49  if (!typeof(Asset).IsAssignableFrom(type))
50  {
51  throw new ArgumentException("Invalid type [{0}]. Type must be assignable to Asset".ToFormat(type), "supportedTypes");
52  }
53  SelectedOutputTypes[type] = true;
54  }
55  }
56 
57  /// <summary>
58  /// Gets the selected output types.
59  /// </summary>
60  /// <value>The selected output types.</value>
61  public Dictionary<Type, bool> SelectedOutputTypes { get; private set; }
62 
63  /// <summary>
64  /// Determines whether the specified type is type selected for output by this importer.
65  /// </summary>
66  /// <typeparam name="T">A Type asset </typeparam>
67  /// <returns><c>true</c> if the specified type is type selected for output by this importer; otherwise, <c>false</c>.</returns>
68  public bool IsTypeSelectedForOutput<T>() where T : Asset
69  {
70  return IsTypeSelectedForOutput(typeof(T));
71  }
72 
73  /// <summary>
74  /// Determines whether the specified type is type selected for output by this importer.
75  /// </summary>
76  /// <param name="type">The type.</param>
77  /// <returns><c>true</c> if the specified type is type selected for output by this importer; otherwise, <c>false</c>.</returns>
78  public bool IsTypeSelectedForOutput(Type type)
79  {
80  bool isSelected;
81  if (SelectedOutputTypes.TryGetValue(type, out isSelected))
82  {
83  return isSelected;
84  }
85  return false;
86  }
87 
88  /// <summary>
89  /// Gets a value indicating whether this instance has valid selected output types.
90  /// </summary>
91  /// <value><c>true</c> if this instance has selected output types; otherwise, <c>false</c>.</value>
92  public bool HasSelectedOutputTypes
93  {
94  get
95  {
96  return SelectedOutputTypes.Count > 0 && SelectedOutputTypes.Any(selectedOutputType => selectedOutputType.Value);
97  }
98  }
99  }
100 }
AssetImporterParameters(params Type[] supportedTypes)
Initializes a new instance of the AssetImporterParameters class.
Base class for Asset.
Definition: Asset.cs:14
AssetImporterParameters()
Initializes a new instance of the AssetImporterParameters class.
bool IsTypeSelectedForOutput(Type type)
Determines whether the specified type is type selected for output by this importer.
Parameters used by IAssetImporter.Import
Base implementation for ILogger.
Definition: Logger.cs:10
AssetImporterParameters(IEnumerable< Type > supportedTypes)
Initializes a new instance of the AssetImporterParameters class.