Depra.Assets
π§Ύ Introduction
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.
π‘ Features:
- 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.
These features make the library even more powerful and convenient for your tasks.
π¦Ύ Capabilities:
Capability | Runtime | Editor |
---|---|---|
Loading assets from Resources | β | β |
Loading UnityEngine.AssetBundle | β | β |
Loading assets from UnityEngine.AssetBundle | β | β |
Loading assets from UnityEditor.PlayerSettings | β | β |
Loading assets from UnityEngine.AssetDatabase | β | β |
π₯ Installation
π¦ Using UPM:
- 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.
βοΈ Manual:
Add the following line to Packages/manifest.json
in the dependencies
section:
"com.depra.assets.unity": "https://github.com/Depra-Inc/Assets.Unity.git"
π Contents
Key Concepts used in this library are described in the following interfaces:
-
IAssetIdent
: 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). -
ILoadableAsset<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 |
AssetBundleIdent |
Loading and unloading UnityEngine.AssetBundle . |
AssetBundleAssetFile<TAsset> |
AssetName |
Loading and unloading assets from UnityEngine.AssetBundle . |
DatabaseAsset<TAsset> |
DatabaseAssetIdent |
Loading and unloading assets from the editorβs asset database UnityEditor.AssetDatabase . β οΈAsynchronous loading is not yet supported. |
PreloadedAsset<TAsset> |
IAssetIdent |
Loading and unloading assets from project settings UnityEditor.ProjectSettings . |
All classes implementing the ILoadableAsset
interface also implement the System.IDisposable
interface for
convenient usage in using
blocks.
π Usage Examples
Loading an Asset from Resources
var resourceTexture = new ResourceAsset<Texture2D>("Textures/myTexture");
Texture2D loadedTexture = resourceTexture.Load();
// Use the loaded asset.
resourceTexture.Unload();
Loading an AssetBundle
var assetBundleFile = new AssetBundleFile("Path/To/MyBundle");
AssetBundle loadedBundle = assetBundleFile.Load();
// Use the loaded asset.
assetBundleFile.Unload();
Loading an Asset from an AssetBundle
var assetBundle = AssetBundle.LoadFromFile("Path/To/MyBundle");
var assetBundleAsset = new AssetBundleAssetFile<GameObject>("MyAsset", assetBundle);
GameObject loadedAsset = assetBundleAsset.Load();
// Use the loaded asset.
assetBundleAsset.Dispose();
Loading an Asset from the Editor Database
var databaseAsset = new DatabaseAsset<MyScriptableObject>("Path/To/MyAsset");
MyScriptableObject loadedObject = databaseAsset.Load();
// Use the loaded asset.
databaseAsset.Dispose();
Loading an Asset from Project Settings
var preloadedAsset = new PreloadedAsset<GameObject>("Path/To/MyAsset");
GameObject loadedAsset = preloadedAsset.Load();
// Use the loaded asset.
preloadedAsset.Dispose();
π Dependencies
- Depra.Assets - the base library for working with assets (provided with this UPM package).
π€ Collaboration
I welcome feature requests and bug reports in the issues section, and I also accept pull requests.
π« Support
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!
π License
This project is distributed under the Apache-2.0 license
Copyright (c) 2023 Nikolay Melnikov n.melnikov@depra.org