Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/depra-inc-unity.git README Markdown
Copy this to your project's README.md
## Installation
Add **Depra.Assets** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/depra-inc-unity.git
```
[](https://www.pkglnk.dev/pkg/depra-inc-unity)README
Depra.Assets
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:
- 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.
βοΈ 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:
- Go to the Unity Asset Store.
- Add the package to your assets.
- Click Open in Unity.
- 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 theIAssetFileinterface 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 n.melnikov@depra.org
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In