Skip to content

Commit d2ebe4a

Browse files
committed
Update README.md
1 parent 76088c5 commit d2ebe4a

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

Assets/_PackageRoot/Documentation~/README.md

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ Async image loader with two caching layers for Unity.
1919
- ✔️ Error handling `ImageLoader.LoadSprite(imageURL).Failed(exception => ...);`
2020
- ✔️ Debug level for logging `ImageLoader.settings.debugLevel = DebugLevel.Error;`
2121

22+
# Installation
23+
24+
- [Install OpenUPM-CLI](https://github.com/openupm/openupm-cli#installation)
25+
- Open command line in Unity project folder
26+
- Run the command
27+
28+
``` CLI
29+
openupm add extensions.unity.imageloader
30+
```
31+
2232
# Usage
2333

2434
In the main thread somewhere at the start of the project need to call `ImageLoader.Init();` once to initialize static properties in the right thread. It is required to make in the main thread. Then you can use `ImageLoader` from any thread and at any time.
@@ -125,7 +135,7 @@ public class SampleCancellation : MonoBehaviour
125135
.ThenSet(image) // if success set sprite into image
126136
.Then(sprite => image.gameObject.SetActive(true)) // if success activate gameObject
127137
.Failed(exception => image.gameObject.SetActive(false)) // if fail deactivate gameObject
128-
.Cancelled(() => Debug.Log("ImageLoading cancelled")) // if cancelled
138+
.Canceled(() => Debug.Log("ImageLoading canceled")) // if canceled
129139
.CancelOnDisable(this) // cancel OnDisable event of current gameObject
130140
.Forget();
131141
}
@@ -198,6 +208,36 @@ public class SampleAwaitAndForget : MonoBehaviour
198208
}
199209
```
200210

211+
# Sample - Lifecycle
212+
213+
``` C#
214+
using Extensions.Unity.ImageLoader;
215+
using UnityEngine;
216+
using UnityEngine.UI;
217+
218+
public class SampleLifecycle : MonoBehaviour
219+
{
220+
[SerializeField] string imageURL;
221+
[SerializeField] Image image;
222+
223+
void Start()
224+
{
225+
ImageLoader.LoadSprite(imageURL) // load sprite
226+
.LoadedFromMemoryCache(sprite => Debug.Log("Loaded from memory cache")) // if loaded from memory cache
227+
.LoadingFromDiskCache(() => Debug.Log("Loading from disk cache")) // if loading from disk cache
228+
.LoadedFromDiskCache(sprite => Debug.Log("Loaded from disk cache")) // if loaded from disk cache
229+
.LoadingFromSource(() => Debug.Log("Loading from source")) // if loading from source
230+
.LoadedFromSource(sprite => Debug.Log("Loaded from source")) // if loaded from source
231+
.Failed(exception => Debug.LogException(exception)) // if failed to load
232+
.Completed(isLoaded => Debug.Log($"Completed, isLoaded={isLoaded}")) // if completed (failed, loaded or canceled)
233+
.Then(sprite => Debug.Log("Loaded")) // if loaded
234+
.ThenSet(image) // if loaded set sprite into image
235+
.Canceled(() => Debug.Log("Canceled")) // if cancelled
236+
.Forget();
237+
}
238+
}
239+
```
240+
201241
# Texture Memory Management
202242

203243
ImageLoader can manager memory usage of loaded textures. To use it need to call `ImageLoader.LoadSpriteRef` instead of `ImageLoader.LoadSprite`. It will return `Reference<Sprite>` object which contains `Sprite` and `Url` objects. When `Reference<Sprite>` object is not needed anymore, call `Dispose` method to release memory, or just don't save the reference on it. It is `IDisposable` and it will clean itself automatically. Each new instance of `Reference<Sprite>` increments reference counter of the texture. When the last reference is disposed, the texture will be unloaded from memory. Also the all related References will be automatically disposed if you call `ImageLoader.ClearMemoryCache` or `ImageLoader.ClearCache`.
@@ -266,13 +306,3 @@ ImageLoader.ClearDiskCache();
266306
// Clear only Disk cache for specific image
267307
ImageLoader.ClearDiskCache(url);
268308
```
269-
270-
# Installation
271-
272-
- [Install OpenUPM-CLI](https://github.com/openupm/openupm-cli#installation)
273-
- Open command line in Unity project folder
274-
- Run the command
275-
276-
``` CLI
277-
openupm add extensions.unity.imageloader
278-
```

0 commit comments

Comments
 (0)