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
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
stringThe 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
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
stringThe 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
stringThe URL to check.
loadedManuallyOnly
boolIf
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
TypeThe type.
url
stringThe URL.
settings
ContentManagerLoaderSettingsThe 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
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
TypeThe type.
url
stringThe URL.
settings
ContentManagerLoaderSettingsThe settings.
Returns
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
stringThe URL to load from.
settings
ContentManagerLoaderSettingsThe 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
stringThe URL to load from.
settings
ContentManagerLoaderSettingsThe 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
stringThe URL to the raw asset.
streamFlags
StreamFlagsThe 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
objectThe object to reload.
newUrl
stringThe url of the new object to load. This allows to replace an asset by another one, or to handle renamed content.
settings
ContentManagerLoaderSettingsThe 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
objectThe object to reload.
newUrl
stringThe url of the new object to load. This allows to replace an asset by another one, or to handle renamed content.
settings
ContentManagerLoaderSettingsThe 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
stringThe URL.
asset
objectThe asset.
storageType
TypeThe 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
Returns
Unload(object)
Unloads the specified asset.
public void Unload(object obj)
Parameters
obj
objectThe 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
stringThe URL.
Exceptions
- InvalidOperationException
Content not loaded through this ContentManager.