Skip to content

Commit cf715aa

Browse files
authored
Merge pull request #23 from IvanMurzak/continues-deployment-update
Unit Tests setup for different Unity versions
2 parents 2865a2e + c0eea66 commit cf715aa

34 files changed

+283
-85
lines changed

.github/workflows/unity-tests.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ jobs:
1818
projectPath:
1919
- './'
2020
unityVersion:
21-
- '6000.0.23f1'
21+
- '2019.4.40f1'
22+
- '2020.3.40f1'
23+
- '2021.3.45f1'
24+
- '2022.3.57f1'
25+
- '2023.1.20f1'
26+
- '2023.2.20f1'
27+
- '6000.0.37f1'
2228
testMode:
2329
- editmode
2430
steps:
@@ -39,6 +45,7 @@ jobs:
3945
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
4046
with:
4147
projectPath: ${{ matrix.projectPath }}
48+
unityVersion: ${{ matrix.unityVersion }}
4249
testMode: ${{ matrix.testMode }}
4350
artifactsPath: ${{ matrix.testMode }}-artifacts
4451
githubToken: ${{ secrets.GITHUB_TOKEN }}

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@
5353
},
5454
"dotnet.preferCSharpExtension": true,
5555
"cSpell.words": [
56-
"ARGB"
56+
"ARGB",
57+
"cysharp",
58+
"imageloader",
59+
"Murzak",
60+
"openupm",
61+
"ugui",
62+
"unitask"
5763
],
5864
"dotnet.defaultSolution": "Unity-ImageLoader.sln"
5965
}

Assets/Samples.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

Assets/_PackageRoot/Documentation~/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
Async image loader with two caching layers for Unity.
66

7+
## Test Status
8+
9+
| Unity Version | Status |
10+
| ------------- | ------ |
11+
| 2019.4.40f1 | ![2019.4.40f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2019.4.40f1) |
12+
| 2020.3.40f1 | ![2020.3.40f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2020.3.40f1) |
13+
| 2021.3.45f1 | ![2021.3.45f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2021.3.45f1) |
14+
| 2022.3.57f1 | ![2022.3.57f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2022.3.57f1) |
15+
| 2023.1.20f1 | ![2023.1.20f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2023.1.20f1) |
16+
| 2023.2.20f1 | ![2023.2.20f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2023.2.20f1) |
17+
| 6000.0.37f1 | ![6000.0.37f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=6000.0.37f1) |
18+
719
## Features
820

921
- ✔️ Async loading from **Web** or **Local** `ImageLoader.LoadSprite(imageURL);`

Assets/_PackageRoot/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
Async image loader with two caching layers for Unity.
66

7+
## Test Status
8+
9+
| Unity Version | Status |
10+
| ------------- | ------ |
11+
| 2019.4.40f1 | ![2019.4.40f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2019.4.40f1) |
12+
| 2020.3.40f1 | ![2020.3.40f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2020.3.40f1) |
13+
| 2021.3.45f1 | ![2021.3.45f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2021.3.45f1) |
14+
| 2022.3.57f1 | ![2022.3.57f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2022.3.57f1) |
15+
| 2023.1.20f1 | ![2023.1.20f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2023.1.20f1) |
16+
| 2023.2.20f1 | ![2023.2.20f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=2023.2.20f1) |
17+
| 6000.0.37f1 | ![6000.0.37f1](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg?unityVersion=6000.0.37f1) |
18+
719
## Features
820

921
- ✔️ Async loading from **Web** or **Local** `ImageLoader.LoadSprite(imageURL);`
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Extensions.Unity.ImageLoader
5+
{
6+
static class Extensions
7+
{
8+
public static void AddOrUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
9+
{
10+
lock (dictionary)
11+
{
12+
if (dictionary.TryGetValue(key, out var existingValue))
13+
{
14+
dictionary[key] = updateValueFactory(key, existingValue);
15+
}
16+
else
17+
{
18+
dictionary[key] = addValue;
19+
}
20+
}
21+
}
22+
public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default)
23+
{
24+
return dictionary.TryGetValue(key, out var value) ? value : defaultValue;
25+
}
26+
public static bool Remove<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, out TValue value)
27+
{
28+
if (dictionary.TryGetValue(key, out value))
29+
{
30+
dictionary.Remove(key);
31+
return true;
32+
}
33+
value = default;
34+
return false;
35+
}
36+
}
37+
}

Assets/_PackageRoot/Runtime/Extensions.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/_PackageRoot/Runtime/Future/Future.API.Set.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/_PackageRoot/Runtime/Future/Future.cs

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,33 @@ internal Future<T> PassEvents(Future<T> to, bool passCancelled = true, bool pass
9696
internal void Loading(FutureLoadingFrom loadingFrom)
9797
{
9898
if (cleared || IsCancelled) return;
99-
Status = loadingFrom switch
99+
100+
switch(loadingFrom)
100101
{
101-
FutureLoadingFrom.DiskCache => FutureStatus.LoadingFromDiskCache,
102-
FutureLoadingFrom.Source => FutureStatus.LoadingFromSource,
103-
_ => throw new ArgumentException($"Unsupported FutureLoadingFrom with value = '{loadingFrom}' in LoadingFrom")
104-
};
105-
var onLoadingEvent = loadingFrom switch
102+
case FutureLoadingFrom.DiskCache:
103+
Status = FutureStatus.LoadingFromDiskCache;
104+
OnLoadingFromDiskCache?.Invoke();
105+
break;
106+
case FutureLoadingFrom.Source:
107+
Status = FutureStatus.LoadingFromSource;
108+
OnLoadingFromSource?.Invoke();
109+
break;
110+
default:
111+
throw new ArgumentException($"Unsupported FutureLoadingFrom with value = '{loadingFrom}' in LoadingFrom");
112+
}
113+
114+
Action onLoadingEvent;
115+
switch (loadingFrom)
106116
{
107-
FutureLoadingFrom.DiskCache => OnLoadingFromDiskCache,
108-
FutureLoadingFrom.Source => OnLoadingFromSource,
109-
_ => throw new ArgumentException($"Unsupported FutureLoadingFrom with value = '{loadingFrom}' in LoadingFrom")
110-
};
117+
case FutureLoadingFrom.DiskCache:
118+
onLoadingEvent = OnLoadingFromDiskCache;
119+
break;
120+
case FutureLoadingFrom.Source:
121+
onLoadingEvent = OnLoadingFromSource;
122+
break;
123+
default:
124+
throw new ArgumentException($"Unsupported FutureLoadingFrom with value = '{loadingFrom}' in LoadingFrom");
125+
}
111126

112127
if (ImageLoader.settings.debugLevel <= DebugLevel.Log && !muteLogs)
113128
Debug.Log($"[ImageLoader] Future[id={id}] Loading: {Url}, from: {loadingFrom}");
@@ -117,21 +132,27 @@ internal void Loading(FutureLoadingFrom loadingFrom)
117132
internal void Loaded(T value, FutureLoadedFrom loadedFrom)
118133
{
119134
if (cleared || IsCancelled) return;
135+
120136
this.value = value;
121-
Status = loadedFrom switch
122-
{
123-
FutureLoadedFrom.MemoryCache => FutureStatus.LoadedFromMemoryCache,
124-
FutureLoadedFrom.DiskCache => FutureStatus.LoadedFromDiskCache,
125-
FutureLoadedFrom.Source => FutureStatus.LoadedFromSource,
126-
_ => throw new ArgumentException($"Unsupported FutureLoadedFrom with value = '{loadedFrom}' in Loaded")
127-
};
128-
var onLoadedEvent = loadedFrom switch
137+
138+
Action<T> onLoadedEvent;
139+
switch(loadedFrom)
129140
{
130-
FutureLoadedFrom.MemoryCache => OnLoadedFromMemoryCache,
131-
FutureLoadedFrom.DiskCache => OnLoadedFromDiskCache,
132-
FutureLoadedFrom.Source => OnLoadedFromSource,
133-
_ => throw new ArgumentException($"Unsupported FutureLoadedFrom with value = '{loadedFrom}' in Loaded")
134-
};
141+
case FutureLoadedFrom.MemoryCache:
142+
Status = FutureStatus.LoadedFromMemoryCache;
143+
onLoadedEvent = OnLoadedFromMemoryCache;
144+
break;
145+
case FutureLoadedFrom.DiskCache:
146+
Status = FutureStatus.LoadedFromDiskCache;
147+
onLoadedEvent = OnLoadedFromDiskCache;
148+
break;
149+
case FutureLoadedFrom.Source:
150+
Status = FutureStatus.LoadedFromSource;
151+
onLoadedEvent = OnLoadedFromSource;
152+
break;
153+
default:
154+
throw new ArgumentException($"Unsupported FutureLoadedFrom with value = '{loadedFrom}' in Loaded");
155+
}
135156

136157
if (ImageLoader.settings.debugLevel <= DebugLevel.Log && !muteLogs)
137158
Debug.Log($"[ImageLoader] Future[id={id}] Loaded: {Url}, from: {loadedFrom}");

Assets/_PackageRoot/Runtime/ImageLoader.LoadSprite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static async void InternalLoadSprite(Future<Sprite> future, Vector2 pivot, Textu
183183
#if UNITY_2020_1_OR_NEWER
184184
var isError = future.WebRequest.result != UnityWebRequest.Result.Success;
185185
#else
186-
var isError = future.WebRequest.isNetworkError || request.isHttpError;
186+
var isError = future.WebRequest.isNetworkError || future.WebRequest.isHttpError;
187187
#endif
188188
if (isError)
189189
{

0 commit comments

Comments
 (0)