WKLib 0.2.3
A modding library for White Knuckle
Loading...
Searching...
No Matches
WKLib.API.Assets.AssetService Class Reference

Loads and caches AssetBundles and assets, scoped by ModContext to avoid collisions. More...

+ Collaboration diagram for WKLib.API.Assets.AssetService:

Public Member Functions

 AssetService (WKLibAPI API)
 
async Task< AssetBundle > LoadBundleRelativeAsync (string relativePath, IProgress< float > progress=null)
 Loads an AssetBundle given a path relative to the mod assembly folder.
Caches under a key combining ModID and bundle name.

Returns
AssetBundle | null

 
void UnloadBundleRelative (string relativePath, bool unloadAllLoadedObjects=false)
 Unloads a specific bundle for this mod.
 
void UnloadAllBundles (bool unloadAllLoadedObjects=false)
 Unloads all bundles loaded by this mod.
 
async Task< Dictionary< string, M_Level > > LoadAllLevelsFromBundle (AssetBundle bundle, IProgress< float > progress=null)
 Given a loaded AssetBundle, iterate over every ".prefab" asset name, Load it as a GameObject, check for an M_Level component; if found, add to the returned list.
Also logs each M_Level found via WKLog.Debug("LevelName").
If you want to register each prefab in a CL_AssetManager database this method will do it automatically.
 
List< M_Level > FindLevelsByName (string nameContains)
 Returns all M_Level instances whose prefab names contain the given substring. (Uses levelPrefabs from the combined asset database in CL_AssetManager)
 
async Task< M_Gamemode > LoadGameModeFromBundle (AssetBundle bundle, string assetName, IProgress< float > progress=null)
 Loads a gamemode from an asset bundle.
 
Sprite LoadPngAsSpriteRelative (string relativePngPath)
 Loads a PNG as a Sprite relative to the mod folder.

Returns
Sprite | null

 
Sprite LoadPngAsSprite (string pngFileName)
 Convenience: Create a Sprite from a PNG filename.
 

Public Attributes

readonly string AssemblyFolder
 

Detailed Description

Loads and caches AssetBundles and assets, scoped by ModContext to avoid collisions.

Definition at line 21 of file AssetService.cs.

Constructor & Destructor Documentation

◆ AssetService()

WKLib.API.Assets.AssetService.AssetService ( WKLibAPI API)

Definition at line 31 of file AssetService.cs.

References WKLib.API.Assets.AssetService.AssemblyFolder.

Member Function Documentation

◆ FindLevelsByName()

List< M_Level > WKLib.API.Assets.AssetService.FindLevelsByName ( string nameContains)

Returns all M_Level instances whose prefab names contain the given substring. (Uses levelPrefabs from the combined asset database in CL_AssetManager)

Definition at line 278 of file AssetService.cs.

◆ LoadAllLevelsFromBundle()

async Task< Dictionary< string, M_Level > > WKLib.API.Assets.AssetService.LoadAllLevelsFromBundle ( AssetBundle bundle,
IProgress< float > progress = null )

Given a loaded AssetBundle, iterate over every ".prefab" asset name, Load it as a GameObject, check for an M_Level component; if found, add to the returned list.
Also logs each M_Level found via WKLog.Debug("LevelName").
If you want to register each prefab in a CL_AssetManager database this method will do it automatically.

Definition at line 182 of file AssetService.cs.

◆ LoadBundleRelativeAsync()

async Task< AssetBundle > WKLib.API.Assets.AssetService.LoadBundleRelativeAsync ( string relativePath,
IProgress< float > progress = null )

Loads an AssetBundle given a path relative to the mod assembly folder.
Caches under a key combining ModID and bundle name.

Returns
AssetBundle | null

Definition at line 54 of file AssetService.cs.

References WKLib.API.Assets.AssetService.AssemblyFolder.

◆ LoadGameModeFromBundle()

async Task< M_Gamemode > WKLib.API.Assets.AssetService.LoadGameModeFromBundle ( AssetBundle bundle,
string assetName,
IProgress< float > progress = null )

Loads a gamemode from an asset bundle.

Returns
M_Gamemode | null

Definition at line 295 of file AssetService.cs.

◆ LoadPngAsSprite()

Sprite WKLib.API.Assets.AssetService.LoadPngAsSprite ( string pngFileName)

Convenience: Create a Sprite from a PNG filename.

Definition at line 379 of file AssetService.cs.

◆ LoadPngAsSpriteRelative()

Sprite WKLib.API.Assets.AssetService.LoadPngAsSpriteRelative ( string relativePngPath)

Loads a PNG as a Sprite relative to the mod folder.

Returns
Sprite | null

Definition at line 356 of file AssetService.cs.

References WKLib.API.Assets.AssetService.AssemblyFolder.

◆ UnloadAllBundles()

void WKLib.API.Assets.AssetService.UnloadAllBundles ( bool unloadAllLoadedObjects = false)

Unloads all bundles loaded by this mod.

Definition at line 149 of file AssetService.cs.

◆ UnloadBundleRelative()

void WKLib.API.Assets.AssetService.UnloadBundleRelative ( string relativePath,
bool unloadAllLoadedObjects = false )

Unloads a specific bundle for this mod.

Definition at line 127 of file AssetService.cs.

Member Data Documentation

◆ AssemblyFolder

readonly string WKLib.API.Assets.AssetService.AssemblyFolder

The documentation for this class was generated from the following file: