ContentManager Class
Namespace: Stride.Core.Serialization.ContentsAssembly: Stride.Core.Serialization.dll
Loads and saves assets.
public sealed class ContentManager : IContentManager
Name | Description | |
---|---|---|
Constructors | ||
ContentManager(IDatabaseFileProviderService) | ||
ContentManager(IServiceRegistry) | ||
Properties | ||
FileProvider | ||
Serializer | ||
Methods | ||
Exists(String) | Check if the specified asset exists. |
|
Get(Type, String) | Gets a previously loaded asset from its URL. |
|
Get<T>(String) | Gets a previously loaded asset from its URL. |
|
GetStats() | Computes statistics about the assets that are currently loaded. This method is intended to be used for debug purpose only. |
|
IsLoaded(String, Boolean) | Gets whether an asset with the given URL is currently loaded. |
|
Load(Type, String, ContentManagerLoaderSettings) | Loads content from the specified URL. |
|
Load<T>(String, ContentManagerLoaderSettings) | Loads content from the specified URL. |
|
LoadAsync(Type, String, ContentManagerLoaderSettings) | Loads an asset from the specified URL asynchronously. |
|
LoadAsync<T>(String, ContentManagerLoaderSettings) | Loads an asset from the specified URL asynchronously. |
|
OpenAsStream(String, StreamFlags) | ||
Reload(Object, String, ContentManagerLoaderSettings) | Reloads a content. If possible, same recursively referenced objects are reused. |
|
ReloadAsync(Object, String, ContentManagerLoaderSettings) | Reloads a content asynchronously. If possible, same recursively referenced objects are reused. |
|
Save(String, Object, Type) | Saves an asset at a specific URL. |
|
TryGetAssetUrl(Object, out String) | ||
Unload(Object) | Unloads the specified asset. |
|
Unload(String) | Unloads the asset at the specified URL. |
Constructors
ContentManager(IDatabaseFileProviderService)
public ContentManager(IDatabaseFileProviderService fileProvider)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseFileProviderService | fileProvider |
ContentManager(IServiceRegistry)
public ContentManager(IServiceRegistry services)
Parameters
Type | Name | Description |
---|---|---|
IServiceRegistry | services |
Properties
FileProvider
public DatabaseFileProvider FileProvider { get; }
Property Value
Type | Description |
---|---|
DatabaseFileProvider |
Serializer
public ContentSerializer Serializer { get; }
Property Value
Type | Description |
---|---|
ContentSerializer |
Methods
Exists(String)
Check if the specified asset exists.
public bool Exists(string url)
Parameters
Type | Name | Description |
---|---|---|
System.String | url | The URL. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Get(Type, String)
Gets a previously loaded asset from its URL.
public object Get(Type type, string url)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type of asset to retrieve. |
System.String | url | The URL of the asset to retrieve. |
Returns
Type | Description |
---|---|
System.Object | The loaded asset, or |
Remarks
This function does not increase the reference count on the asset.
Get<T>(String)
Gets a previously loaded asset from its URL.
public T Get<T>(string url)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.String | url | The URL of the asset to retrieve. |
Returns
Type | Description |
---|---|
T | The loaded asset, or |
Type Parameters
Name | Description |
---|---|
T | The type of asset to retrieve. |
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
Type | Description |
---|---|
ContentManagerStats | The statistics. |
IsLoaded(String, Boolean)
Gets whether an asset with the given URL is currently loaded.
public bool IsLoaded(string url, bool loadedManuallyOnly = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | url | The URL to check. |
System.Boolean | loadedManuallyOnly | If |
Returns
Type | Description |
---|---|
System.Boolean |
|
Load(Type, String, ContentManagerLoaderSettings)
Loads content from the specified URL.
public object Load(Type type, string url, ContentManagerLoaderSettings settings = null)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type. |
System.String | url | The URL. |
ContentManagerLoaderSettings | settings | The settings. |
Returns
Type | Description |
---|---|
System.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
Type | Condition |
---|---|
System.ArgumentNullException | url |
Load<T>(String, ContentManagerLoaderSettings)
Loads content from the specified URL.
public T Load<T>(string url, ContentManagerLoaderSettings settings = null)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.String | url | The URL to load from. |
ContentManagerLoaderSettings | settings | The settings. If null, fallback to Default. |
Returns
Type | Description |
---|---|
T | The loaded content. |
Type Parameters
Name | Description |
---|---|
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.
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 | Name | Description |
---|---|---|
System.Type | type | The type. |
System.String | url | The URL. |
ContentManagerLoaderSettings | settings | The settings. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.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
Type | Name | Description |
---|---|---|
System.String | url | The URL to load from. |
ContentManagerLoaderSettings | settings | The settings. If null, fallback to Default. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | The loaded content. |
Type Parameters
Name | Description |
---|---|
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)
public Stream OpenAsStream(string url, StreamFlags streamFlags)
Parameters
Type | Name | Description |
---|---|---|
System.String | url | |
StreamFlags | streamFlags |
Returns
Type | Description |
---|---|
System.IO.Stream |
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
Type | Name | Description |
---|---|---|
System.Object | obj | The object to reload. |
System.String | newUrl | The url of the new object to load. This allows to replace an asset by another one, or to handle renamed content. |
ContentManagerLoaderSettings | settings | The loader settings. |
Returns
Type | Description |
---|---|
System.Boolean | True if it could be reloaded, false otherwise. |
Exceptions
Type | Condition |
---|---|
System.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
Type | Name | Description |
---|---|---|
System.Object | obj | The object to reload. |
System.String | newUrl | The url of the new object to load. This allows to replace an asset by another one, or to handle renamed content. |
ContentManagerLoaderSettings | settings | The loader settings. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Boolean> | 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
Type | Condition |
---|---|
System.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
Type | Name | Description |
---|---|---|
System.String | url | The URL. |
System.Object | asset | The asset. |
System.Type | storageType | The custom storage type to use. Use null as default. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | url or asset |
TryGetAssetUrl(Object, out String)
public bool TryGetAssetUrl(object obj, out string url)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | |
System.String | url |
Returns
Type | Description |
---|---|
System.Boolean |
Unload(Object)
Unloads the specified asset.
public void Unload(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to unload. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Content not loaded through this ContentManager. |
Unload(String)
Unloads the asset at the specified URL.
public void Unload(string url)
Parameters
Type | Name | Description |
---|---|---|
System.String | url | The URL. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Content not loaded through this ContentManager. |