You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
125
135
.ThenSet(image) // if success set sprite into image
126
136
.Then(sprite=>image.gameObject.SetActive(true)) // if success activate gameObject
127
137
.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
129
139
.CancelOnDisable(this) // cancel OnDisable event of current gameObject
130
140
.Forget();
131
141
}
@@ -198,6 +208,36 @@ public class SampleAwaitAndForget : MonoBehaviour
198
208
}
199
209
```
200
210
211
+
# Sample - Lifecycle
212
+
213
+
```C#
214
+
usingExtensions.Unity.ImageLoader;
215
+
usingUnityEngine;
216
+
usingUnityEngine.UI;
217
+
218
+
publicclassSampleLifecycle : MonoBehaviour
219
+
{
220
+
[SerializeField] stringimageURL;
221
+
[SerializeField] Imageimage;
222
+
223
+
voidStart()
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
+
201
241
# Texture Memory Management
202
242
203
243
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`.
0 commit comments