Class ContentManager
- Namespace
- Stride.Core.Serialization.Contents
- Assembly
- Stride.Core.Serialization.dll
Loads and saves assets.
public sealed class ContentManager : IContentManager
- Inheritance
-
objectContentManager
- Implements
- Extension Methods
Constructors
ContentManager(IDatabaseFileProviderService)
public ContentManager(IDatabaseFileProviderService fileProvider)
Parameters
fileProviderIDatabaseFileProviderService
ContentManager(IServiceRegistry)
public ContentManager(IServiceRegistry services)
Parameters
servicesIServiceRegistry
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
urlstringThe URL.
Returns
- bool
trueif the specified asset url exists,falseotherwise.
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
nullif 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
urlstringThe URL of the asset to retrieve.
Returns
- T
The loaded asset, or
nullif the asset has not been loaded.
Type Parameters
TThe 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
urlstringThe URL to check.
loadedManuallyOnlyboolIf
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
Trueif an asset with the given URL is currently loaded,falseotherwise.
Load(Type, string, ContentManagerLoaderSettings?)
Loads content from the specified URL.
public object Load(Type type, string url, ContentManagerLoaderSettings? settings = null)
Parameters
typeTypeThe type.
urlstringThe URL.
settingsContentManagerLoaderSettingsThe 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
typeTypeThe type.
urlstringThe URL.
settingsContentManagerLoaderSettingsThe 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
urlstringThe URL to load from.
settingsContentManagerLoaderSettingsThe settings. If null, fallback to Default.
Returns
- Task<T>
The loaded content.
Type Parameters
TThe 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
urlstringThe URL to load from.
settingsContentManagerLoaderSettingsThe settings. If null, fallback to Default.
Returns
- T
The loaded content.
Type Parameters
TThe 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
urlstringThe URL to the raw asset.
streamFlagsStreamFlagsThe 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
objobjectThe object to reload.
newUrlstringThe url of the new object to load. This allows to replace an asset by another one, or to handle renamed content.
settingsContentManagerLoaderSettingsThe 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
objobjectThe object to reload.
newUrlstringThe url of the new object to load. This allows to replace an asset by another one, or to handle renamed content.
settingsContentManagerLoaderSettingsThe 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
urlstringThe URL.
assetobjectThe asset.
storageTypeTypeThe 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
objobjecturlstring
Returns
TryGetLoadedAsset(string, out object?)
public bool TryGetLoadedAsset(string url, out object? asset)
Parameters
urlstringassetobject
Returns
Unload(object)
Unloads the specified asset.
public void Unload(object obj)
Parameters
objobjectThe 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
urlstringThe URL.
Exceptions
- InvalidOperationException
Content not loaded through this ContentManager.