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:

  1. Open the Unity Package Manager window.
  2. Click the + button in the upper right corner of the window.
  3. Select Add package from git URL….
  4. Enter the repository link.
  5. 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 the IAssetFile 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

Depra Inc.