Class AssetManager
AssetManager is responsible for loading and managing assets in the application.
public class AssetManager
- Inheritance
-
AssetManager
- Inherited Members
Properties
AssemblyPath
Assembly path of the executing assembly.
public string AssemblyPath { get; }
Property Value
Methods
Add<T>(string, T)
Adds an asset to the asset manager.
public T Add<T>(string name, T asset) where T : class
Parameters
namestringassetT
Returns
- T
Type Parameters
T
Exceptions
Add<T>(T)
Adds the specified asset to the collection if an asset with the same name does not already exist.
public T Add<T>(T asset) where T : class, IIdentifier
Parameters
assetTThe asset to add to the collection. Cannot be null.
Returns
- T
The added asset of type
T.
Type Parameters
TThe type of asset to add. Must implement IIdentifier.
Exceptions
- ArgumentNullException
Thrown if
assetis null.- InvalidOperationException
Thrown if an asset with the same name already exists in the collection.
ClearAssets()
Removes all assets from the collection.
public void ClearAssets()
DisposeAssets(IRenderDevice)
Releases all graphics resources associated with the managed assets using the specified rendering device.
public void DisposeAssets(IRenderDevice renderer)
Parameters
rendererIRenderDeviceThe rendering device to use when disposing of graphics resources. Cannot be null.
Remarks
Only assets that implement the IGraphicsResource interface are disposed. Assets that do not implement this interface are ignored.
Exists<T>(string)
Determines whether an asset of the specified type and name exists in the collection.
public bool Exists<T>(string name) where T : class
Parameters
namestringThe name of the asset to locate. The comparison is case-sensitive.
Returns
- bool
true if an asset of type T with the specified name exists; otherwise, false.
Type Parameters
TThe type of the asset to check for. Must be a reference type.
ForeachAsset<T>(Action<T>)
Executes an action for each asset of a specific type in the asset manager.
public void ForeachAsset<T>(Action<T> action) where T : class
Parameters
actionAction<T>
Type Parameters
T
FreeCPUResources()
Frees the CPU resources associated with the managed assets.
public void FreeCPUResources()
FreeCPUResources<T>()
Releases CPU-side resources for all assets of the specified type that implement IGraphicsResource.
public void FreeCPUResources<T>() where T : IRendererResource
Type Parameters
TThe type of asset for which to free CPU resources. Must implement IRendererResource.
Remarks
This method iterates through all managed assets and calls FreeCPUResources on those that are both of type T and implement IGraphicsResource. Assets that do not meet these criteria are skipped.
GetAllAssets<T>(bool)
Get all assets of a specific type from the asset manager.
public IEnumerable<T> GetAllAssets<T>(bool assignables = true) where T : class
Parameters
assignablesbool
Returns
- IEnumerable<T>
Type Parameters
T
GetAssetCount<T>()
Gets the asset count for a specific asset type.
public int GetAssetCount<T>() where T : class
Returns
Type Parameters
T
Get<T>(string)
Retrieves an asset of the specified type and name from the asset collection.
public T? Get<T>(string name) where T : class
Parameters
namestringThe name of the asset to retrieve. The name is case-sensitive.
Returns
- T
The asset of type
Twith the specified name, or null if no matching asset is found.
Type Parameters
TThe type of asset to retrieve. Must be a reference type.
Remarks
If multiple assets exist with the same name but different types, only the asset matching the specified type is returned. The method returns null if the asset does not exist or is not of the requested type.
InitializeAssets(IRenderDevice)
Initializes all assets that implement the IRenderResource interface using the specified render device.
public void InitializeAssets(IRenderDevice renderer)
Parameters
rendererIRenderDeviceThe render device to use for initializing render resources. Cannot be null.
Remarks
Only assets that implement IRenderResource are initialized. Other assets are ignored.
Load<T>(string, object?)
Loads an asset from the specified path.
public T Load<T>(string path, object? loadingArgs = null) where T : class
Parameters
Returns
- T
Type Parameters
T
RegisterLoader<T>(IAssetLoader)
Registers a loader for a specific asset type.
public void RegisterLoader<T>(IAssetLoader loader) where T : class
Parameters
loaderIAssetLoader
Type Parameters
T
Exceptions
UnloadAsset(string)
Unloads an asset from the asset manager.
public void UnloadAsset(string path)
Parameters
pathstring