-
Notifications
You must be signed in to change notification settings - Fork 75
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 #102 from AnnulusGames/optimize-awaiter
Add: Lightweight Awaiter without UniTask
- Loading branch information
Showing
7 changed files
with
80 additions
and
9 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
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,41 @@ | ||
#if LITMOTION_SUPPORT_UNITASK | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace LitMotion | ||
{ | ||
public readonly struct MotionAwaiter : ICriticalNotifyCompletion | ||
{ | ||
readonly MotionHandle handle; | ||
public bool IsCompleted => !handle.IsActive(); | ||
|
||
public MotionAwaiter(MotionHandle handle) | ||
{ | ||
this.handle = handle; | ||
} | ||
|
||
public MotionAwaiter GetAwaiter() | ||
{ | ||
return this; | ||
} | ||
|
||
public void GetResult() | ||
{ | ||
} | ||
|
||
public void OnCompleted(Action continuation) | ||
{ | ||
UnsafeOnCompleted(continuation); | ||
} | ||
|
||
public void UnsafeOnCompleted(Action continuation) | ||
{ | ||
if (continuation == null) return; | ||
|
||
var callbackData = MotionStorageManager.GetMotionCallbacks(handle); | ||
callbackData.OnCompleteAction += continuation; | ||
MotionStorageManager.SetMotionCallbacks(handle, callbackData); | ||
} | ||
} | ||
} | ||
#endif |
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
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,24 @@ | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using UnityEngine.TestTools.Utils; | ||
|
||
namespace LitMotion.Tests.Runtime | ||
{ | ||
public class AwaitTest | ||
{ | ||
[Test] | ||
public async Task Test_AwaitManyTimes() | ||
{ | ||
var value = 0f; | ||
var startValue = 0f; | ||
var endValue = 10f; | ||
|
||
for (int i = 0; i < 50; i++) | ||
{ | ||
await LMotion.Create(startValue, endValue, 0.1f) | ||
.Bind(x => value = x); | ||
Assert.That(value, Is.EqualTo(10f).Using(FloatEqualityComparer.Instance)); | ||
} | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/LitMotion/Assets/LitMotion/Tests/Runtime/AwaitTest.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