Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #66 from techno-dwarf-works/dev
Browse files Browse the repository at this point in the history
Version 1.5.92
  • Loading branch information
OpOpYaDev authored Mar 3, 2024
2 parents f68ed0c + 514481b commit 7b6fe2d
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Better.Extensions.Runtime
{
public static class AssetBundleRequestAwaiterExtensions
public static class AssetBundleRequestExtensions
{
public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest self)
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Threading.Tasks;
using Better.Extensions.Runtime.Helpers;
using UnityEngine;

namespace Better.Extensions.Runtime
{
public static class AsyncOperationExtensions
{
public static bool IsRelativeCompleted(this AsyncOperation self)
{
return self.allowSceneActivation ? self.isDone : self.progress >= 0.9f;
}

public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation self)
{
if (self == null)
{
throw new ArgumentNullException(nameof(self));
}

return new AsyncOperationAwaiter(self);
}

public static async Task AwaitCompletion(this AsyncOperation self, IProgress<float> progress = null)
{
var awaiter = new AsyncOperationCompletionAwaiter(self, progress);
await awaiter.Task;
}
}
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Better.Extensions.Runtime
{
public static class ResourceRequestAwaiterExtensions
public static class ResourceRequestExtensions
{
public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest self)
{
Expand Down
5 changes: 5 additions & 0 deletions Assets/BetterExtensions/Runtime/Extensions/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public static async void Forget(this Task self)
{
await self;
}

public static async void Forget<T>(this Task<T> self)
{
await self;
}

public static Task WhenAll(this IEnumerable<Task> self)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Threading;
using UnityEngine;
using ThreadingTask = System.Threading.Tasks.Task;

namespace Better.Extensions.Runtime.Helpers
{
internal class AsyncOperationCompletionAwaiter : BaseCompletionAwaiter<bool>
{
private readonly IProgress<float> _progress;

public AsyncOperationCompletionAwaiter(AsyncOperation sourceOperation, IProgress<float> progress = null)
: base(CancellationToken.None)
{
_progress = progress;
ProcessAsync(sourceOperation);
}

private async void ProcessAsync(AsyncOperation asyncOperation)
{
while (!asyncOperation.IsRelativeCompleted())
{
_progress?.Report(asyncOperation.progress);
await ThreadingTask.Yield();
}

SetResult(true);
}

protected override void OnCompleted(bool result)
{
_progress?.Report(1f);
}
}
}

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

2 changes: 1 addition & 1 deletion Assets/BetterExtensions/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.uurha.betterextensions",
"displayName": "Better Extensions",
"version": "1.5.91",
"version": "1.5.92",
"unity": "2021.3",
"description": "Unity extensions, serialize extension, async extension, string extension and UI extensions",
"dependencies": {
Expand Down

0 comments on commit 7b6fe2d

Please sign in to comment.