Table of Contents
This library provides classes and interfaces for convenient and efficient loading of various types of assets in Unity projects.
It contains common methods and functionality for working with assets, as well as implementations of specific loading strategies for different sources.
- Standardization: A unified API for asset loading from various sources.
- Cancellation Support: The ability to cancel loading operations at any point.
- Progress Tracking: Providing information on the current loading progress.
- Extensibility: A flexible architecture for extending functionality according to your needs.
- Lightweight: The package contains only tens of kilobytes of necessary scripts and nothing unnecessary.
These features make the library even more powerful and convenient for your tasks.
Capability | Runtime | Editor |
---|---|---|
Loading assets from UnityEngine.Resources | β | β |
Loading UnityEngine.AssetBundle | β | β |
Loading assets from UnityEngine.AssetBundle | β | β |
Loading assets from UnityEditor.PlayerSettings | β | β |
Loading assets from UnityEngine.AssetDatabase | β | β |
- Open the Unity Package Manager window.
- Click the + button in the upper right corner of the window.
- Select Add package from git URL....
- Enter the repository link.
- Click Add.
Add the following line to Packages/manifest.json
in the dependencies
section:
"com.depra.assets.unity": "https://github.com/Depra-Inc/Assets.Unity.git"
- Go to the Unity Asset Store.
- Add the package to your assets.
- Click Open in Unity.
- Follow the instructions in the Unity editor.
Key Concepts used in this library are described in the following interfaces:
-
IAssetUri
: Designed to facilitate resource management in Unity projects. It provides a simple and standardized way of identifying and managing assets using URI (Uniform Resource Identifier). -
IAssetFile<TAsset>
: Defines the fundamental methods and properties required for loading and unloading assets. It extends the functionality of theIAssetFile
interface presented in Depra.Assets and offers the ability to perform both synchronous and asynchronous asset loading, as well as checking the loading state.
You can create your own implementations of these interfaces or use ready-made ones presented in the table:
Asset class type | Ident | Description |
---|---|---|
ResourceAsset<TAsset> |
ResourcesPath |
Loading and unloading assets from UnityEngine.Resources . |
AssetBundleFile |
AssetBundleUri |
Loading and unloading UnityEngine.AssetBundle . |
AssetBundleAssetFile<TAsset> |
AssetName |
Loading and unloading assets from UnityEngine.AssetBundle . |
EditorDatabaseAsset<TAsset> |
DatabaseAssetUri |
Loading and unloading assets from the editor's asset database UnityEditor.AssetDatabase . |
PreloadedAsset<TAsset> |
IAssetUri |
Loading and unloading assets from project settings UnityEditor.ProjectSettings . |
All classes implementing the IAssetFile<TAsset>
interface also implement the System.IDisposable
interface for
convenient usage in using
blocks.
var resourceTexture = new ResourceAsset<Texture2D>("Textures/myTexture");
Texture2D loadedTexture = resourceTexture.Load();
// Use the loaded asset.
resourceTexture.Unload();
var assetBundleSource = new AssetBundleFromFile();
var assetBundleFile = new AssetBundleFile("Path/To/MyBundle", assetBundleSource);
AssetBundle loadedBundle = assetBundleFile.Load();
// Use the loaded asset.
assetBundleFile.Unload();
var assetBundle = AssetBundle.LoadFromFile("Path/To/MyBundle");
var assetBundleAsset = new AssetBundleAssetFile<GameObject>("MyAsset", assetBundle);
GameObject loadedAsset = assetBundleAsset.Load();
// Use the loaded asset.
assetBundleAsset.Unload();
var databaseAsset = new EditorDatabaseAsset<MyScriptableObject>("Path/To/MyAsset");
MyScriptableObject loadedObject = databaseAsset.Load();
// Use the loaded asset.
databaseAsset.Unload();
var anyAsset = new ResourcesAsset<GameObject>("Path/To/MyAsset");
var preloadedAsset = new PreloadedAsset<GameObject>(anyAsset);
GameObject loadedAsset = preloadedAsset.Load();
// Use the loaded asset.
preloadedAsset.Unload();
- Depra.Assets - the base library for working with assets (provided with this UPM package).
I welcome feature requests and bug reports in the issues section, and I also accept pull requests.
I am an independent developer, and most of the development of this project is done in my free time. If you are interested in collaborating or hiring me for a project, please check out my portfolio and contact me!
This project is distributed under the Apache-2.0 license
Copyright (c) 2023 Nikolay Melnikov [email protected]