An open API service indexing awesome lists of open source software.

https://github.com/udfsoft/glideunity

GlideUnity is a lightweight and easy to use wrapper for loading images into Unity
https://github.com/udfsoft/glideunity

csharp glide image loader unity

Last synced: about 1 month ago
JSON representation

GlideUnity is a lightweight and easy to use wrapper for loading images into Unity

Awesome Lists containing this project

README

          

# GlideUnity

**GlideUnity** is a lightweight and convenient wrapper for loading images in Unity, inspired by [Glide for Android](https://github.com/bumptech/glide). It supports loading from the network, file system, and Resources folder, with memory/disk caching, placeholders, and error handling.

## ๐Ÿš€ Features

- โœ… Load images from:
- Network (`http/https`)
- File system (`file://`)
- Unity `Resources` folder
- โœ… Supports Unity UI components:
- `RawImage`
- `Image` (`Sprite`)
- โœ… Caching:
- In-memory (RAM) with LRU eviction
- On disk (`Application.persistentDataPath`)
- โœ… Placeholders and error images
- โœ… Custom HTTP headers
- โœ… Safe handling of `null` and empty paths

---

## ๐Ÿ”ง Installation

Copy the following files into your Unity project:

```
Assets/Scripts/GlideUnity/
โ”œโ”€โ”€ Glide.cs
โ”œโ”€โ”€ GlideRequestBuilder.cs
โ”œโ”€โ”€ GlideLoader.cs
โ”œโ”€โ”€ ImageRequest.cs
โ”œโ”€โ”€ ImageSourceType.cs
โ”œโ”€โ”€ ImageCache.cs
```

> ๐Ÿ“ Make sure to include `using UnityEngine.UI` where needed to use Unity UI components.

---

## ๐Ÿงช Example Usage

```csharp
Glide.With(this)
.Load("https://example.com/avatar.png")
.Placeholder(myPlaceholderTexture)
.Error(myErrorTexture)
.Header("Authorization", "Bearer xyz")
.Into(myRawImage);
```

Or for Image (Sprite):

```csharp
Glide.With(this)
.Load("https://example.com/icon.png")
.Placeholder(spriteTexture)
.Into(myUIImage);
```

## ๐Ÿ“ฆ Caching
### ๐Ÿง  In-Memory
LRU cache (default limit: 5 images)

Manually clear:

```csharp
ImageCache.ClearMemory();
```

### ๐Ÿ’พ On-Disk
Stored at Application.persistentDataPath/image_cache

Not automatically cleared (by default)

Manually clear:

```csharp
ImageCache.ClearDisk();
```

### ๐Ÿ” Safety
Load(null) and Load("") are safely handled

If the path is invalid or loading fails, the placeholder or errorImage is shown (if provided)