Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AssetManagerLoaderSettings.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.Linq;
5 using SiliconStudio.Core.Serialization.Contents;
6 
7 namespace SiliconStudio.Core.Serialization.Assets
8 {
9  /// <summary>
10  /// Specifies settings for <see cref="AssetManager.Load{T}"/> operations.
11  /// </summary>
12  public sealed class AssetManagerLoaderSettings
13  {
14  private static readonly AssetManagerLoaderSettings defaultValue = new AssetManagerLoaderSettings();
15  private static readonly AssetManagerLoaderSettings ignoreReferences = new AssetManagerLoaderSettings { LoadContentReferences = false };
16  private bool loadContentReferences = true;
17 
18  public delegate void ContentFilterDelegate(ContentReference contentReference, ref bool shouldBeLoaded);
19 
20  /// <summary>
21  /// Gets the default loader settings.
22  /// </summary>
23  /// <value>
24  /// The default loader settings.
25  /// </value>
27  {
28  get { return defaultValue; }
29  }
30 
31  /// <summary>
32  /// Gets the loader settings which doesn't load content references.
33  /// </summary>
34  /// <value>
35  /// The loader settings which doesn't load content references.
36  /// </value>
37  public static AssetManagerLoaderSettings IgnoreReferences
38  {
39  get { return ignoreReferences; }
40  }
41 
42  /// <summary>
43  /// Gets or sets a value indicating whether <see cref="ContentReference{T}"/> should be loaded.
44  /// </summary>
45  /// <value>
46  /// <c>true</c> if <see cref="ContentReference{T}"/> should be loaded; otherwise, <c>false</c>.
47  /// </value>
48  public bool LoadContentReferences
49  {
50  get { return loadContentReferences; }
51  set { loadContentReferences = value; }
52  }
53 
54  /// <summary>
55  /// Gets or sets a filter that can indicate whether <see cref="ContentReference{T}"/> should be loaded.
56  /// </summary>
57  /// <value>
58  /// The content reference filter.
59  /// </value>
60  public ContentFilterDelegate ContentFilter { get; set; }
61 
62  /// <summary>
63  /// Creates a new content filter that won't load chunk if not one of the given types.
64  /// </summary>
65  /// <param name="types">The accepted types.</param>
66  /// <returns></returns>
67  public static ContentFilterDelegate NewContentFilterByType(params Type[] types)
68  {
69  // We could convert to HashSet, but usually not worth it for small sets
70  return (ContentReference contentReference, ref bool shouldBeLoaded) =>
71  {
72  if (!types.Contains(contentReference.Type))
73  shouldBeLoaded = false;
74  };
75  }
76  }
77 }
Specifies settings for AssetManager.Load{T} operations.
Use the default mode depending on the type of the field/property.
static ContentFilterDelegate NewContentFilterByType(params Type[] types)
Creates a new content filter that won't load chunk if not one of the given types. ...