Skip to content

Load or use external resources in Unity conveniently

License

Notifications You must be signed in to change notification settings

Klrohias/uniasset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[English] | 中文

Uniasset

uniasset

Usage

Installation

  1. Navigate to the Releases page, locate the latest release, and download the uniasset-unity-scripts.zip file from the assets provided in the release.
  2. Depending on your project's requirements, download the corresponding native libraries (.dll for Windows, .so for Linux / Android, .a for iOS, .dylib for macOS) and place them in the Assets/Plugins directory of your Unity project. Configure the platform of the native libraries in the Inspector.

Basic Usage

using System.IO;
using System.Threading.Tasks;
using Uniasset.Image;
using Uniasset.Audio;

async void LoadAsync()
{
    // Load image
    var pathToResource = "/path/to/your/image.png";
    var fileContent = await File.ReadAllBytesAsync(pathToResource);

    using var imageAsset = new ImageAsset();
    await imageAsset.LoadAsync(fileContent);

    // Crop
    await imageAsset.CropAsync(100, 100, 100, 100);

    // Resize
    await imageAsset.ResizeAsync(50, 50);

    // Convert to Texture2D and display
    // Note that although this is Async, due to Unity restrictions, some code still executes on the main thread, so make sure to call this on the main thread
    image.texture = await imageAsset.ToTexture2DAsync();

    // Load audio
    pathToResource = "/path/to/your/audio.ogg";
    fileContent = await File.ReadAllBytesAsync(pathToResource);

    using var audioAsset = new AudioAsset();
    await audioAsset.LoadAsync(fileContent);

    // Convert to AudioClip and play
    using var decoder = audioAsset.GetAudioDecoder();
    audioSource.clip = decoder.ToAudioClip();
    audioSource.Play();

    await Task.Delay(5000);

    audioSource.Pause();
}

License

This project is licensed under the MIT License, which allows modification according to specific project requirements (such as resource encryption) without the need for re-licensing.