Table of Contents

Class ContentManager

Namespace
Stride.Core.Serialization.Contents
Assembly
Stride.Core.Serialization.dll

Loads and saves assets.

public sealed class ContentManager : IContentManager
Inheritance
ContentManager
Implements
Extension Methods

Constructors

ContentManager(IDatabaseFileProviderService)

public ContentManager(IDatabaseFileProviderService fileProvider)

Parameters

fileProvider IDatabaseFileProviderService

ContentManager(IServiceRegistry)

public ContentManager(IServiceRegistry services)

Parameters

services IServiceRegistry

Properties

FileProvider

public DatabaseFileProvider FileProvider { get; }

Property Value

DatabaseFileProvider

Serializer

Gets the serializer.

public ContentSerializer Serializer { get; }

Property Value

ContentSerializer

The serializer.

Methods

Exists(string)

Check if the specified asset exists.

public bool Exists(string url)

Parameters

url string

The URL.

Returns

bool

true if the specified asset url exists, false otherwise.

Get(Type, string)

Gets a previously loaded asset from its URL.

public object Get(Type type, string url)

Parameters

type Type

The type of asset to retrieve.

url string

The URL of the asset to retrieve.

Returns

object

The loaded asset, or null if the asset has not been loaded.

Remarks

This function does not increase the reference count on the asset.

GetStats()

Computes statistics about the assets that are currently loaded. This method is intended to be used for debug purpose only.

public ContentManagerStats GetStats()

Returns

ContentManagerStats

The statistics.

Get<T>(string)

Gets a previously loaded asset from its URL.

public T Get<T>(string url) where T : class

Parameters

url string

The URL of the asset to retrieve.

Returns

T

The loaded asset, or null if the asset has not been loaded.

Type Parameters

T

The type of asset to retrieve.

Remarks

This function does not increase the reference count on the asset.

IsLoaded(string, bool)

Gets whether an asset with the given URL is currently loaded.

public bool IsLoaded(string url, bool loadedManuallyOnly = false)

Parameters

url string

The URL to check.

loadedManuallyOnly bool

If true, this method will return true only if an asset with the given URL has been manually loaded via Load(Type, string, ContentManagerLoaderSettings), and not if the asset has been only loaded indirectly from another asset.

Returns

bool

True if an asset with the given URL is currently loaded, false otherwise.

Load(Type, string, ContentManagerLoaderSettings)

Loads content from the specified URL.

public object Load(Type type, string url, ContentManagerLoaderSettings settings = null)

Parameters

type Type

The type.

url string

The URL.

settings ContentManagerLoaderSettings

The settings.

Returns

object

The loaded content.

Remarks

If the asset is already loaded, it just increases the reference count of the asset and return the same instance.

Exceptions

ArgumentNullException

url

LoadAsync(Type, string, ContentManagerLoaderSettings)

Loads an asset from the specified URL asynchronously.

public Task<object> LoadAsync(Type type, string url, ContentManagerLoaderSettings settings = null)

Parameters

type Type

The type.

url string

The URL.

settings ContentManagerLoaderSettings

The settings.

Returns

Task<object>

The loaded content.

Remarks

If the asset is already loaded, it just increases the reference count of the asset and return the same instance.

LoadAsync<T>(string, ContentManagerLoaderSettings)

Loads an asset from the specified URL asynchronously.

public Task<T> LoadAsync<T>(string url, ContentManagerLoaderSettings settings = null) where T : class

Parameters

url string

The URL to load from.

settings ContentManagerLoaderSettings

The settings. If null, fallback to Default.

Returns

Task<T>

The loaded content.

Type Parameters

T

The content type.

Remarks

If the asset is already loaded, it just increases the reference count of the asset and return the same instance.

Load<T>(string, ContentManagerLoaderSettings)

Loads content from the specified URL.

public T Load<T>(string url, ContentManagerLoaderSettings settings = null) where T : class

Parameters

url string

The URL to load from.

settings ContentManagerLoaderSettings

The settings. If null, fallback to Default.

Returns

T

The loaded content.

Type Parameters

T

The content type.

Remarks

If the asset is already loaded, it just increases the reference count of the asset and return the same instance.

OpenAsStream(string, StreamFlags)

Opens the specified URL as a stream used for custom raw asset loading.

public Stream OpenAsStream(string url, StreamFlags streamFlags)

Parameters

url string

The URL to the raw asset.

streamFlags StreamFlags

The type of stream needed

Returns

Stream

A stream to the raw asset.

Reload(object, string, ContentManagerLoaderSettings)

Reloads a content. If possible, same recursively referenced objects are reused.

public bool Reload(object obj, string newUrl = null, ContentManagerLoaderSettings settings = null)

Parameters

obj object

The object to reload.

newUrl string

The url of the new object to load. This allows to replace an asset by another one, or to handle renamed content.

settings ContentManagerLoaderSettings

The loader settings.

Returns

bool

True if it could be reloaded, false otherwise.

Exceptions

InvalidOperationException

Content not loaded through this ContentManager.

ReloadAsync(object, string, ContentManagerLoaderSettings)

Reloads a content asynchronously. If possible, same recursively referenced objects are reused.

public Task<bool> ReloadAsync(object obj, string newUrl = null, ContentManagerLoaderSettings settings = null)

Parameters

obj object

The object to reload.

newUrl string

The url of the new object to load. This allows to replace an asset by another one, or to handle renamed content.

settings ContentManagerLoaderSettings

The loader settings.

Returns

Task<bool>

A task that completes when the content has been reloaded. The result of the task is True if it could be reloaded, false otherwise.

Exceptions

InvalidOperationException

Content not loaded through this ContentManager.

Save(string, object, Type)

Saves an asset at a specific URL.

public void Save(string url, object asset, Type storageType = null)

Parameters

url string

The URL.

asset object

The asset.

storageType Type

The custom storage type to use. Use null as default.

Exceptions

ArgumentNullException

url or asset

TryGetAssetUrl(object, out string)

public bool TryGetAssetUrl(object obj, out string url)

Parameters

obj object
url string

Returns

bool

TryGetLoadedAsset(string, out object)

public bool TryGetLoadedAsset(string url, out object asset)

Parameters

url string
asset object

Returns

bool

Unload(object)

Unloads the specified asset.

public void Unload(object obj)

Parameters

obj object

The object to unload.

Exceptions

InvalidOperationException

Content not loaded through this ContentManager.

Unload(string)

Unloads the asset at the specified URL.

public void Unload(string url)

Parameters

url string

The URL.

Exceptions

InvalidOperationException

Content not loaded through this ContentManager.