AssetLoaders
Coding Style wiki
using OxGFrame.AssetLoader;
Core Mechanism: Path Resolution Rules
AssetLoaders has a built-in automatic filtering mechanism that determines the loading path based on the prefix of assetName:
- Asset
- Load from Resources: If the path has the res# prefix (e.g.,
res#Prefabs/Player), it will be automatically parsed and loaded from Unity's built-in Resources. - Load from Bundle: If there is no prefix, it defaults to loading from YooAsset resource packages (subject to addressing rules).
- Load from Resources: If the path has the res# prefix (e.g.,
- Scene
- Load from Build Scene: If the path has the build# prefix (e.g.,
build#SimpleScene), it will be automatically parsed and loaded from Unity's built-in Scenes In Build list.
- Load from Build Scene: If the path has the build# prefix (e.g.,
Scene Methods
Provides asynchronous and synchronous loading of scenes, supporting Single and Additive modes.
LoadSceneAsync / LoadScene
Loads the specified scene.
- Params:
string assetName: Scene name or path.LoadSceneMode loadSceneMode: Scene loading mode.bool activateOnLoad: Whether to automatically activate the scene after loading is complete.Progression progression: Loading progress callback.
LoadSingleSceneAsync / LoadAdditiveSceneAsync
Shortcuts for loading in Single (replaces current scene) or Additive (stacks scenes) mode respectively.
UnloadScene
Unloads the scene and releases associated resources.
Asset Methods (Resource Loading and Instantiation)
Handles resource loading and object generation for Prefabs, Textures, AudioClips, etc.
PreloadAssetAsync / PreloadAsset
Preloads resources into the cache without performing instantiation (Instantiate), suitable for performance optimization.
LoadAssetAsync / LoadAsset
Loads the resource and returns the resource object.
InstantiateAssetAsync / InstantiateAsset
Loads the resource and directly performs Object.Instantiate to create an instance.
- Supports multiple Overloads: Specify parameters such as
Position,Rotation,Parent,WorldPositionStays, etc.
UnloadAsset
Unloads a single resource cache. If forceUnload = true is passed, it will force release.
RawFile Methods
Specifically for loading Rawfile type files (such as Config, Json, Bin, Mp4, etc.), only supports loading from Bundles.
GetRawFilePathAsync / GetRawFilePath
Gets the physical path of the RawFile in the local cache, which can be used for subsequent file reading (FileStream/IO).
LoadRawFileAsync / LoadRawFile
Directly loads file content and converts it to a specified type:
- Supports generic
stringorbyte[].
Group Cacher
For scenarios requiring "batch management and batch release" (e.g., all resources of a specific level), all Load/Preload methods provide versions with an int groupId.
- HasInCache(int groupId, string assetName): Checks if the resource already exists in a specific group cache.
- UnloadAssets(int groupId, LoadType loadType = LoadType.Any): Releases all Resources & Bundle assets in that group, still subject to reference counting.
Important Before releasing resources, make sure the resource is no longer referenced. For Bundle resources, it is recommended to call Unload & Destroy in pairs instead of directly destroying the object to maintain the correctness of the reference count.