This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from techno-dwarf-works/dev
Version 1.5.92
- Loading branch information
Showing
12 changed files
with
80 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
19 changes: 0 additions & 19 deletions
19
Assets/BetterExtensions/Runtime/Extensions/AsyncOperationAwaiterExtensions.cs
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
Assets/BetterExtensions/Runtime/Extensions/AsyncOperationAwaiterExtensions.cs.meta
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
Assets/BetterExtensions/Runtime/Extensions/AsyncOperationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterExtensions/Runtime/Extensions/AsyncOperationExtensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ts/BetterExtensions/Runtime/Helpers/CompletionAwaiters/AsyncOperationCompletionAwaiter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...tterExtensions/Runtime/Helpers/CompletionAwaiters/AsyncOperationCompletionAwaiter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters