[English] | 中文
- Navigate to the Releases page, locate the latest release, and download the
uniasset-unity-scripts.zip
file from the assets provided in the release. - 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 theAssets/Plugins
directory of your Unity project. Configure the platform of the native libraries in the Inspector.
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();
}
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.