Skip to content

Provides an API for loading Unity asset files πŸ—ƒοΈ in multiple ways through a single interface.

License

Notifications You must be signed in to change notification settings

Depra-Inc/Assets.Unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Depra.Assets

License Last Commit Code Size

Table of Contents

🧾 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.
  • 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.

🦾 Capabilities:

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 ❌ βœ…

πŸ“₯ 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.

βš™οΈ Using UPM via manifest.json:

Add the following line to Packages/manifest.json in the dependencies section:

"com.depra.assets.unity": "https://github.com/Depra-Inc/Assets.Unity.git"

πŸ›’ Using Unity Asset Store:

  1. Go to the Unity Asset Store.
  2. Add the package to your assets.
  3. Click Open in Unity.
  4. Follow the instructions in the Unity editor.

πŸ“– Contents

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 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 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. ⚠️Asynchronous loading is not yet supported.
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.

πŸ“‹ 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 assetBundleSource = new AssetBundleFromFile();
var assetBundleFile = new AssetBundleFile("Path/To/MyBundle", assetBundleSource);
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.Unload();

Loading an Asset from the Editor Database

var databaseAsset = new EditorDatabaseAsset<MyScriptableObject>("Path/To/MyAsset");
MyScriptableObject loadedObject = databaseAsset.Load();
// Use the loaded asset.
databaseAsset.Unload();

Loading an Asset from Project Settings

var anyAsset = new ResourcesAsset<GameObject>("Path/To/MyAsset");
var preloadedAsset = new PreloadedAsset<GameObject>(anyAsset);
GameObject loadedAsset = preloadedAsset.Load();
// Use the loaded asset.
preloadedAsset.Unload();

πŸ–‡ 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 [email protected]

About

Provides an API for loading Unity asset files πŸ—ƒοΈ in multiple ways through a single interface.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages