Skip to content

Commit 4b17f4f

Browse files
authored
Merge pull request #22 from IvanMurzak/continues-integration
Continues Integration
2 parents 8f9ebd0 + 9895b5d commit 4b17f4f

24 files changed

+708
-143
lines changed

.github/workflows/unity-tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Editor Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
testAllModes:
10+
name: ${{ matrix.unityVersion }} ${{ matrix.testMode }}
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
projectPath:
16+
- './'
17+
unityVersion:
18+
- '2019.2.1f1'
19+
- '2019.3.0f1'
20+
- '2019.4.0f1'
21+
- '2020.3.0f1'
22+
- '2021.3.0f1'
23+
- '2022.3.0f1'
24+
- '2023.2.0f1'
25+
- '6000.0.23f1'
26+
testMode:
27+
- editmode
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
lfs: false
32+
- uses: actions/cache@v4
33+
with:
34+
path: ${{ matrix.projectPath }}/Library
35+
key: Library-${{ matrix.projectPath }}
36+
restore-keys: |
37+
Library-
38+
- uses: game-ci/unity-test-runner@v4
39+
id: tests
40+
env:
41+
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
42+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
43+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
44+
with:
45+
projectPath: ${{ matrix.projectPath }}
46+
testMode: ${{ matrix.testMode }}
47+
artifactsPath: ${{ matrix.testMode }}-artifacts
48+
githubToken: ${{ secrets.GITHUB_TOKEN }}
49+
checkName: ${{ matrix.unityVersion }} ${{ matrix.testMode }} Test Results
50+

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"recommendations": [
3-
"visualstudiotoolsforunity.vstuc"
3+
"visualstudiotoolsforunity.vstuc",
4+
"github.vscode-github-actions"
45
]
56
}

Assets/_PackageRoot/Documentation~/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unity Image Loader
22

3-
![npm](https://img.shields.io/npm/v/extensions.unity.imageloader) [![openupm](https://img.shields.io/npm/v/extensions.unity.imageloader?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/extensions.unity.imageloader/) ![License](https://img.shields.io/github/license/IvanMurzak/Unity-ImageLoader) [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
3+
![npm](https://img.shields.io/npm/v/extensions.unity.imageloader) [![openupm](https://img.shields.io/npm/v/extensions.unity.imageloader?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/extensions.unity.imageloader/) ![example workflow](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg) ![License](https://img.shields.io/github/license/IvanMurzak/Unity-ImageLoader) [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
44

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

@@ -71,7 +71,7 @@ public class SampleSetMultipleSpriteIntoMultipleImages : MonoBehaviour
7171

7272
void Start()
7373
{
74-
// Loading with auto set to multiple images
74+
// Loading with auto set to multiple images
7575
ImageLoader.LoadSprite(imageURL).ThenSet(image1, image2).Forget();
7676
}
7777
}

Assets/_PackageRoot/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unity Image Loader
22

3-
![npm](https://img.shields.io/npm/v/extensions.unity.imageloader) [![openupm](https://img.shields.io/npm/v/extensions.unity.imageloader?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/extensions.unity.imageloader/) ![License](https://img.shields.io/github/license/IvanMurzak/Unity-ImageLoader) [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
3+
![npm](https://img.shields.io/npm/v/extensions.unity.imageloader) [![openupm](https://img.shields.io/npm/v/extensions.unity.imageloader?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/extensions.unity.imageloader/) ![example workflow](https://github.com/IvanMurzak/Unity-ImageLoader/actions/workflows/unity-tests.yml/badge.svg) ![License](https://img.shields.io/github/license/IvanMurzak/Unity-ImageLoader) [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
44

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

@@ -71,7 +71,7 @@ public class SampleSetMultipleSpriteIntoMultipleImages : MonoBehaviour
7171

7272
void Start()
7373
{
74-
// Loading with auto set to multiple images
74+
// Loading with auto set to multiple images
7575
ImageLoader.LoadSprite(imageURL).ThenSet(image1, image2).Forget();
7676
}
7777
}

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ public Future<T> Canceled(Action action)
139139
{
140140
if (IsCancelled)
141141
{
142+
if (ImageLoader.settings.debugLevel <= DebugLevel.Log && !muteLogs)
143+
Debug.Log($"[ImageLoader] Future[id={id}] Canceled: {Url}");
142144
action();
143145
return this;
144146
}
@@ -153,6 +155,13 @@ public Future<T> Canceled(Action action)
153155
/// <returns>Returns the Future instance</returns>
154156
public Future<T> Disposed(Action<Future<T>> action)
155157
{
158+
if (Status == FutureStatus.Disposed)
159+
{
160+
if (ImageLoader.settings.debugLevel <= DebugLevel.Log && !muteLogs)
161+
Debug.Log($"[ImageLoader] Future[id={id}] Disposed: {Url}");
162+
action?.Invoke(this);
163+
return this;
164+
}
156165
OnDispose += action;
157166
return this;
158167
}
@@ -164,7 +173,7 @@ public void Cancel()
164173
{
165174
if (cleared || IsCancelled) return;
166175
if (ImageLoader.settings.debugLevel <= DebugLevel.Log && !muteLogs)
167-
Debug.Log($"[ImageLoader] Cancel: {Url}");
176+
Debug.Log($"[ImageLoader] Future[id={id}] Cancel: {Url}");
168177
Status = FutureStatus.Canceled;
169178
if (!cts.IsCancellationRequested)
170179
{
@@ -180,23 +189,30 @@ public void Cancel()
180189
public void Dispose()
181190
{
182191
if (Status == FutureStatus.Disposed) return;
192+
193+
if (ImageLoader.settings.debugLevel <= DebugLevel.Log && !muteLogs)
194+
Debug.Log($"[ImageLoader] Future[id={id}] Disposed: {Url}");
195+
183196
if (!cts.IsCancellationRequested)
184197
{
185198
cts.Cancel();
186199
OnCanceled?.Invoke();
200+
OnCanceled = null;
187201
}
188202
Status = FutureStatus.Disposed;
189203
OnDispose?.Invoke(this);
190204
OnDispose = null;
191205
Clear();
192206

193-
if (value is IDisposable disposable)
207+
if (disposeValue && value is IDisposable disposable)
194208
disposable?.Dispose();
195209

196210
value = default;
197211
exception = default;
198212

199213
cts.Dispose();
214+
WebRequest?.Dispose();
215+
WebRequest = null;
200216
}
201217

202218
/// <summary>

Assets/_PackageRoot/Runtime/Future/Future.ThenSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static Future<Sprite> ThenSet<T>(this Future<Sprite> future, Action<T, Sp
4545
if (target == null)
4646
{
4747
if (ImageLoader.settings.debugLevel <= DebugLevel.Warning)
48-
Debug.LogWarning($"[ImageLoader] The target is null. Can't set image into it. Skipping.");
48+
Debug.LogWarning($"[ImageLoader] Future[id={future.id}] The target is null. Can't set image into it. Skipping.");
4949
continue;
5050
}
5151
if (target is UIBehaviour uiBehaviour)

Assets/_PackageRoot/Runtime/Future/Future.ThenSetRef.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static Future<Reference<Sprite>> ThenSet<T>(this Future<Reference<Sprite>
3131
if (target == null)
3232
{
3333
if (ImageLoader.settings.debugLevel <= DebugLevel.Warning)
34-
Debug.LogWarning($"[ImageLoader] The target is null. Can't set image into it. Skipping.");
34+
Debug.LogWarning($"[ImageLoader] Future[id={future.id}] The target is null. Can't set image into it. Skipping.");
3535
continue;
3636
}
3737
if (target is UIBehaviour uiBehaviour)

Assets/_PackageRoot/Runtime/Future/Future.Timeout.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,29 @@
33

44
namespace Extensions.Unity.ImageLoader
55
{
6-
public static partial class FutureEx
6+
public partial class Future<T>
77
{
88
/// <summary>
99
/// Set timeout duration. If the duration reached it fails the Future with related exception
1010
/// </summary>
1111
/// <param name="duration">The timeout duration</param>
1212
/// <returns>Returns async Future</returns>
13-
public static Future<T> Timeout<T>(this Future<T> future, TimeSpan duration)
13+
public Future<T> Timeout(TimeSpan duration)
1414
{
15-
if (duration <= TimeSpan.Zero)
15+
timeout = duration;
16+
if (WebRequest != null)
1617
{
17-
future.FailToLoad(new Exception($"[ImageLoader] Timeout ({duration}): {future.Url}"));
18-
return future;
18+
WebRequest.timeout = (int)Math.Ceiling(duration.TotalSeconds);
1919
}
20-
UniTask.Delay(duration).ContinueWith(() =>
20+
if (duration <= TimeSpan.Zero)
2121
{
22-
future.FailToLoad(new Exception($"[ImageLoader] Timeout ({duration}): {future.Url}"));
23-
});
24-
return future;
22+
FailToLoad(new Exception($"[ImageLoader] Future[id={id}] Timeout ({duration}): {Url}"));
23+
return this;
24+
}
25+
UniTask.Delay(duration)
26+
.ContinueWith(() => FailToLoad(new Exception($"[ImageLoader] Future[id={id}] Timeout ({duration}): {Url}")))
27+
.AttachExternalCancellation(CancellationToken);
28+
return this;
2529
}
2630
}
2731
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using UnityEngine.Networking;
3+
4+
namespace Extensions.Unity.ImageLoader
5+
{
6+
public partial class Future<T> : IFuture, IDisposable
7+
{
8+
internal Future<T> SetWebRequest(UnityWebRequest webRequest)
9+
{
10+
webRequest.timeout = (int)Math.Ceiling(timeout.TotalSeconds);
11+
this.WebRequest = webRequest;
12+
return this;
13+
}
14+
15+
internal UnityWebRequestAsyncOperation SendWebRequest()
16+
{
17+
if (WebRequest == null)
18+
{
19+
throw new Exception($"[ImageLoader] Future[id={id}] UnityWebRequest is not set. Use SetWebRequest method before calling SendWebRequest.");
20+
}
21+
return WebRequest.SendWebRequest();
22+
}
23+
}
24+
}

Assets/_PackageRoot/Runtime/Future/Future.WebRequest.cs.meta

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

0 commit comments

Comments
 (0)