Skip to content

Commit

Permalink
Merge pull request #23 from IvanMurzak/continues-deployment-update
Browse files Browse the repository at this point in the history
Unit Tests setup for different Unity versions
  • Loading branch information
IvanMurzak authored Feb 12, 2025
2 parents 2865a2e + c0eea66 commit cf715aa
Show file tree
Hide file tree
Showing 34 changed files with 283 additions and 85 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/unity-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ jobs:
projectPath:
- './'
unityVersion:
- '6000.0.23f1'
- '2019.4.40f1'
- '2020.3.40f1'
- '2021.3.45f1'
- '2022.3.57f1'
- '2023.1.20f1'
- '2023.2.20f1'
- '6000.0.37f1'
testMode:
- editmode
steps:
Expand All @@ -39,6 +45,7 @@ jobs:
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
projectPath: ${{ matrix.projectPath }}
unityVersion: ${{ matrix.unityVersion }}
testMode: ${{ matrix.testMode }}
artifactsPath: ${{ matrix.testMode }}-artifacts
githubToken: ${{ secrets.GITHUB_TOKEN }}
Expand Down
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@
},
"dotnet.preferCSharpExtension": true,
"cSpell.words": [
"ARGB"
"ARGB",
"cysharp",
"imageloader",
"Murzak",
"openupm",
"ugui",
"unitask"
],
"dotnet.defaultSolution": "Unity-ImageLoader.sln"
}
8 changes: 0 additions & 8 deletions Assets/Samples.meta

This file was deleted.

12 changes: 12 additions & 0 deletions Assets/_PackageRoot/Documentation~/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

Async image loader with two caching layers for Unity.

## Test Status

| Unity Version | Status |
| ------------- | ------ |
| 2019.4.40f1 | ![2019.4.40f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2019.4.40f1) |
| 2020.3.40f1 | ![2020.3.40f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2020.3.40f1) |
| 2021.3.45f1 | ![2021.3.45f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2021.3.45f1) |
| 2022.3.57f1 | ![2022.3.57f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2022.3.57f1) |
| 2023.1.20f1 | ![2023.1.20f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2023.1.20f1) |
| 2023.2.20f1 | ![2023.2.20f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2023.2.20f1) |
| 6000.0.37f1 | ![6000.0.37f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=6000.0.37f1) |

## Features

- ✔️ Async loading from **Web** or **Local** `ImageLoader.LoadSprite(imageURL);`
Expand Down
12 changes: 12 additions & 0 deletions Assets/_PackageRoot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

Async image loader with two caching layers for Unity.

## Test Status

| Unity Version | Status |
| ------------- | ------ |
| 2019.4.40f1 | ![2019.4.40f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2019.4.40f1) |
| 2020.3.40f1 | ![2020.3.40f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2020.3.40f1) |
| 2021.3.45f1 | ![2021.3.45f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2021.3.45f1) |
| 2022.3.57f1 | ![2022.3.57f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2022.3.57f1) |
| 2023.1.20f1 | ![2023.1.20f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2023.1.20f1) |
| 2023.2.20f1 | ![2023.2.20f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2023.2.20f1) |
| 6000.0.37f1 | ![6000.0.37f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=6000.0.37f1) |

## Features

- ✔️ Async loading from **Web** or **Local** `ImageLoader.LoadSprite(imageURL);`
Expand Down
37 changes: 37 additions & 0 deletions Assets/_PackageRoot/Runtime/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;

namespace Extensions.Unity.ImageLoader
{
static class Extensions
{
public static void AddOrUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
{
lock (dictionary)
{
if (dictionary.TryGetValue(key, out var existingValue))
{
dictionary[key] = updateValueFactory(key, existingValue);
}
else
{
dictionary[key] = addValue;
}
}
}
public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default)
{
return dictionary.TryGetValue(key, out var value) ? value : defaultValue;
}
public static bool Remove<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, out TValue value)
{
if (dictionary.TryGetValue(key, out value))
{
dictionary.Remove(key);
return true;
}
value = default;
return false;
}
}
}
11 changes: 11 additions & 0 deletions Assets/_PackageRoot/Runtime/Extensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Assets/_PackageRoot/Runtime/Future/Future.API.Set.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 44 additions & 23 deletions Assets/_PackageRoot/Runtime/Future/Future.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,33 @@ internal Future<T> PassEvents(Future<T> to, bool passCancelled = true, bool pass
internal void Loading(FutureLoadingFrom loadingFrom)
{
if (cleared || IsCancelled) return;
Status = loadingFrom switch

switch(loadingFrom)
{
FutureLoadingFrom.DiskCache => FutureStatus.LoadingFromDiskCache,
FutureLoadingFrom.Source => FutureStatus.LoadingFromSource,
_ => throw new ArgumentException($"Unsupported FutureLoadingFrom with value = '{loadingFrom}' in LoadingFrom")
};
var onLoadingEvent = loadingFrom switch
case FutureLoadingFrom.DiskCache:
Status = FutureStatus.LoadingFromDiskCache;
OnLoadingFromDiskCache?.Invoke();
break;
case FutureLoadingFrom.Source:
Status = FutureStatus.LoadingFromSource;
OnLoadingFromSource?.Invoke();
break;
default:
throw new ArgumentException($"Unsupported FutureLoadingFrom with value = '{loadingFrom}' in LoadingFrom");
}

Action onLoadingEvent;
switch (loadingFrom)
{
FutureLoadingFrom.DiskCache => OnLoadingFromDiskCache,
FutureLoadingFrom.Source => OnLoadingFromSource,
_ => throw new ArgumentException($"Unsupported FutureLoadingFrom with value = '{loadingFrom}' in LoadingFrom")
};
case FutureLoadingFrom.DiskCache:
onLoadingEvent = OnLoadingFromDiskCache;
break;
case FutureLoadingFrom.Source:
onLoadingEvent = OnLoadingFromSource;
break;
default:
throw new ArgumentException($"Unsupported FutureLoadingFrom with value = '{loadingFrom}' in LoadingFrom");
}

if (ImageLoader.settings.debugLevel <= DebugLevel.Log && !muteLogs)
Debug.Log($"[ImageLoader] Future[id={id}] Loading: {Url}, from: {loadingFrom}");
Expand All @@ -117,21 +132,27 @@ internal void Loading(FutureLoadingFrom loadingFrom)
internal void Loaded(T value, FutureLoadedFrom loadedFrom)
{
if (cleared || IsCancelled) return;

this.value = value;
Status = loadedFrom switch
{
FutureLoadedFrom.MemoryCache => FutureStatus.LoadedFromMemoryCache,
FutureLoadedFrom.DiskCache => FutureStatus.LoadedFromDiskCache,
FutureLoadedFrom.Source => FutureStatus.LoadedFromSource,
_ => throw new ArgumentException($"Unsupported FutureLoadedFrom with value = '{loadedFrom}' in Loaded")
};
var onLoadedEvent = loadedFrom switch

Action<T> onLoadedEvent;
switch(loadedFrom)
{
FutureLoadedFrom.MemoryCache => OnLoadedFromMemoryCache,
FutureLoadedFrom.DiskCache => OnLoadedFromDiskCache,
FutureLoadedFrom.Source => OnLoadedFromSource,
_ => throw new ArgumentException($"Unsupported FutureLoadedFrom with value = '{loadedFrom}' in Loaded")
};
case FutureLoadedFrom.MemoryCache:
Status = FutureStatus.LoadedFromMemoryCache;
onLoadedEvent = OnLoadedFromMemoryCache;
break;
case FutureLoadedFrom.DiskCache:
Status = FutureStatus.LoadedFromDiskCache;
onLoadedEvent = OnLoadedFromDiskCache;
break;
case FutureLoadedFrom.Source:
Status = FutureStatus.LoadedFromSource;
onLoadedEvent = OnLoadedFromSource;
break;
default:
throw new ArgumentException($"Unsupported FutureLoadedFrom with value = '{loadedFrom}' in Loaded");
}

if (ImageLoader.settings.debugLevel <= DebugLevel.Log && !muteLogs)
Debug.Log($"[ImageLoader] Future[id={id}] Loaded: {Url}, from: {loadedFrom}");
Expand Down
2 changes: 1 addition & 1 deletion Assets/_PackageRoot/Runtime/ImageLoader.LoadSprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static async void InternalLoadSprite(Future<Sprite> future, Vector2 pivot, Textu
#if UNITY_2020_1_OR_NEWER
var isError = future.WebRequest.result != UnityWebRequest.Result.Success;
#else
var isError = future.WebRequest.isNetworkError || request.isHttpError;
var isError = future.WebRequest.isNetworkError || future.WebRequest.isHttpError;
#endif
if (isError)
{
Expand Down
9 changes: 4 additions & 5 deletions Assets/_PackageRoot/Runtime/ImageLoader.MemoryCache.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using UnityEngine;

Expand All @@ -7,9 +6,9 @@ namespace Extensions.Unity.ImageLoader
{
public static partial class ImageLoader
{
internal static volatile ConcurrentDictionary<string, Sprite> memorySpriteCache = new ConcurrentDictionary<string, Sprite>();
internal static volatile Dictionary<string, Sprite> memorySpriteCache = new Dictionary<string, Sprite>();

#if UNITY_EDITOR
#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
[UnityEditor.InitializeOnEnterPlayMode]
private static void ClearMemoryCacheOnEnterPlayMode()
{
Expand Down Expand Up @@ -54,7 +53,7 @@ public static void SaveToMemoryCache(string url, Sprite sprite, bool replace = f
/// </summary>
/// <param name="url">URL to the picture, web or local</param>
/// <returns>Returns null if not allowed to use Memory cache or if there is no cached Sprite</returns>
public static Reference<Sprite>? LoadFromMemoryCacheRef(string url)
public static Reference<Sprite> LoadFromMemoryCacheRef(string url)
{
if (!settings.useMemoryCache) return null;

Expand All @@ -69,7 +68,7 @@ public static void SaveToMemoryCache(string url, Sprite sprite, bool replace = f
/// </summary>
/// <param name="url">URL to the picture, web or local</param>
/// <returns>Returns null if not allowed to use Memory cache or if there is no cached Sprite</returns>
public static Sprite? LoadFromMemoryCache(string url)
public static Sprite LoadFromMemoryCache(string url)
{
if (!settings.useMemoryCache) return null;

Expand Down
5 changes: 2 additions & 3 deletions Assets/_PackageRoot/Runtime/Reference.Counter.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace Extensions.Unity.ImageLoader
{
public partial class Reference<T> : IDisposable
{
private volatile static ConcurrentDictionary<string, int> referenceCounters = new ConcurrentDictionary<string, int>();
private volatile static Dictionary<string, int> referenceCounters = new Dictionary<string, int>();
internal static void Clear()
{
lock (referenceCounters) referenceCounters.Clear();
Expand All @@ -15,7 +14,7 @@ internal static void Clear()
internal static bool Clear(string url)
{
var result = false;
lock (referenceCounters) result = referenceCounters.Remove(url, out var _);
lock (referenceCounters) result = referenceCounters.Remove(url);
EventOnClearUrl?.Invoke(url);
return result;
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit cf715aa

Please sign in to comment.