mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-15 11:30:09 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2eb75df68 | ||
|
|
4a62d7eba6 | ||
|
|
40d2d2fe06 | ||
|
|
d5d2cb5937 | ||
|
|
854100c075 | ||
|
|
5837b26208 | ||
|
|
da0e654e7d | ||
|
|
a3e9932be7 | ||
|
|
e82353b4d9 | ||
|
|
944b61f28c | ||
|
|
457c574865 | ||
|
|
089a509663 | ||
|
|
3bebaef969 | ||
|
|
37e8b4500e | ||
|
|
8537ddf8a6 | ||
|
|
346b1e0a6b | ||
|
|
fc7b9660a5 | ||
|
|
21e5cc22c7 | ||
|
|
3f18b37e5f | ||
|
|
5d4a90e9bd |
4
.github/workflows/build-debug.yml
vendored
4
.github/workflows/build-debug.yml
vendored
@@ -3,7 +3,7 @@ name: Build-Debug
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "**"
|
||||
- "master"
|
||||
tags:
|
||||
- "!*" # not a tag push
|
||||
pull_request:
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.101
|
||||
dotnet-version: 3.1.x
|
||||
- run: dotnet test -c Debug ./src/UniTask.NetCoreTests/UniTask.NetCoreTests.csproj
|
||||
|
||||
build-unity:
|
||||
|
||||
64
.github/workflows/build-release.yml
vendored
64
.github/workflows/build-release.yml
vendored
@@ -16,9 +16,9 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.101
|
||||
dotnet-version: 3.1.x
|
||||
# set release tag(*.*.*) to env.GIT_TAG
|
||||
- run: echo ::set-env name=GIT_TAG::${GITHUB_REF#refs/tags/}
|
||||
- run: echo "GIT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||
|
||||
# build and pack
|
||||
- run: dotnet build -c Release -p:Version=${{ env.GIT_TAG }}
|
||||
@@ -34,7 +34,7 @@ jobs:
|
||||
build-unity:
|
||||
strategy:
|
||||
matrix:
|
||||
unity: ['2019.3.9f1']
|
||||
unity: ["2019.3.9f1"]
|
||||
include:
|
||||
- unity: 2019.3.9f1
|
||||
license: UNITY_2019_3
|
||||
@@ -51,14 +51,14 @@ jobs:
|
||||
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -manualLicenseFile .Unity.ulf || exit 0
|
||||
|
||||
# set release tag(*.*.*) to env.GIT_TAG
|
||||
- run: echo ::set-env name=GIT_TAG::${GITHUB_REF#refs/tags/}
|
||||
- run: echo "GIT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||
|
||||
# Execute scripts: Export Package
|
||||
- name: Export unitypackage
|
||||
run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
|
||||
working-directory: src/UniTask
|
||||
|
||||
# Store artifacts.
|
||||
# Store artifacts.
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: UniTask.${{ env.GIT_TAG }}.unitypackage
|
||||
@@ -72,34 +72,34 @@ jobs:
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
||||
NUGET_XMLDOC_MODE: skip
|
||||
steps:
|
||||
# setup dotnet for nuget push
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.101
|
||||
# set release tag(*.*.*) to env.GIT_TAG
|
||||
- run: echo ::set-env name=GIT_TAG::${GITHUB_REF#refs/tags/}
|
||||
# setup dotnet for nuget push
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.x
|
||||
# set release tag(*.*.*) to env.GIT_TAG
|
||||
- run: echo "GIT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||
|
||||
# Create Releases
|
||||
- uses: actions/create-release@v1
|
||||
id: create_release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: Ver.${{ github.ref }}
|
||||
# Create Releases
|
||||
- uses: actions/create-release@v1
|
||||
id: create_release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: Ver.${{ github.ref }}
|
||||
|
||||
# Download(All) Artifacts to current directory
|
||||
- uses: actions/download-artifact@v2-preview
|
||||
# Download(All) Artifacts to current directory
|
||||
- uses: actions/download-artifact@v2-preview
|
||||
|
||||
# Upload to NuGet
|
||||
- run: dotnet nuget push "./nuget/*.nupkg" -s https://www.nuget.org/api/v2/package -k ${{ secrets.NUGET_KEY }}
|
||||
# Upload to NuGet
|
||||
- run: dotnet nuget push "./nuget/*.nupkg" -s https://www.nuget.org/api/v2/package -k ${{ secrets.NUGET_KEY }}
|
||||
|
||||
# Upload to Releases(unitypackage)
|
||||
- uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./UniTask.${{ env.GIT_TAG }}.unitypackage/UniTask.${{ env.GIT_TAG }}.unitypackage
|
||||
asset_name: UniTask.${{ env.GIT_TAG }}.unitypackage
|
||||
asset_content_type: application/octet-stream
|
||||
# Upload to Releases(unitypackage)
|
||||
- uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./UniTask.${{ env.GIT_TAG }}.unitypackage/UniTask.${{ env.GIT_TAG }}.unitypackage
|
||||
asset_name: UniTask.${{ env.GIT_TAG }}.unitypackage
|
||||
asset_content_type: application/octet-stream
|
||||
|
||||
12
README.md
12
README.md
@@ -215,6 +215,8 @@ await task; // NG, throws Exception
|
||||
|
||||
Store to the class field, you can use `UniTask.Lazy` that gurantee call multipletimes. `.Preserve()` allows for multiple calls (internally cached results). This is useful when multiple calls in a function scope.
|
||||
|
||||
Also `UniTaskCompletionSource` can await multipletimes and await from many caller.
|
||||
|
||||
Cancellation and Exception handling
|
||||
---
|
||||
Some UniTask factory methods have `CancellationToken cancellationToken = default` parameter. Andalso some async operation for unity have `WithCancellation(CancellationToken)` and `ToUniTask(..., CancellationToken cancellation = default)` extension methods.
|
||||
@@ -351,6 +353,8 @@ It indicates when to run, you can check [PlayerLoopList.md](https://gist.github.
|
||||
|
||||
`PlayerLoopTiming.Update` is similar as `yield return null` in coroutine, but it is called before Update(Update and uGUI events(button.onClick, etc...) are called on `ScriptRunBehaviourUpdate`, yield return null is called on `ScriptRunDelayedDynamicFrameRate`). `PlayerLoopTiming.FixedUpdate` is similar as `WaitForFixedUpdate`, `PlayerLoopTiming.LastPostLateUpdate` is similar as `WaitForEndOfFrame` in coroutine.
|
||||
|
||||
> `await UniTask.WaitForEndOfFrame()` is not equilavelnt to coroutine's `yield return new WaitForEndOfFrame()`. Coroutine's WaitForEndOfFrame seems to run after the PlayerLoop is done. Some methods that require coroutine's end of frame(`ScreenCapture.CaptureScreenshotAsTexture`, `CommandBuffer`, etc) does not work correctly when replace to async/await. In that case, use a coroutine.
|
||||
|
||||
`yield return null` and `UniTask.Yield` is similar but different. `yield return null` always return next frame but `UniTask.Yield` return next called, that is, call `UniTask.Yield(PlayerLoopTiming.Update)` on `PreUpdate`, it returns same frame. `UniTask.NextFrame()` gurantees return next frame, this would be expected to behave exactly the same as `yield return null`.
|
||||
|
||||
> UniTask.Yield(without CancellationToken) is a special type, returns `YieldAwaitable` and run on YieldRunner. It is most lightweight and faster.
|
||||
@@ -794,9 +798,11 @@ IEnumerator.ToUniTask limitation
|
||||
---
|
||||
You can convert coroutine(IEnumerator) to UniTask(or await directly) but has some limitations.
|
||||
|
||||
* `WaitForEndOfFrame`/`WaitForFixedUpdate` is not supported, used `yield return null` instead.
|
||||
* `WaitForEndOfFrame`/`WaitForFixedUpdate`/`Coroutine` is not supported.
|
||||
* Consuming loop timing is not same as StartCoroutine, it is used specified PlayerLoopTiming, and default's `PlayerLoopTiming.Update` is run before MonoBehaviour's Update and StartCoroutine's loop.
|
||||
|
||||
If you want to convert fully compatible from coroutine to async, use `IEnumerator.ToUniTask(MonoBehaviour coroutineRunner)` overload. It executes StartCoroutine on an instance of the argument MonoBehaviour and waits for it to complete in UniTask.
|
||||
|
||||
For UnityEditor
|
||||
---
|
||||
UniTask can run on Unity Edtitor like Editor Coroutine. However, there are some limitations.
|
||||
@@ -852,7 +858,7 @@ Use UniTask type.
|
||||
|
||||
Pooling Configuration
|
||||
---
|
||||
UniTask is aggressively caching async promise object to achive zero allocation. In default, cache all promises but you can configure `TaskPool.SetMaxPoolSize` to your value, the value indicates cache size per type. `TaskPool.GetCacheSizeInfo` returns current cached object in pool.
|
||||
UniTask is aggressively caching async promise object to achive zero allocation(technical details, see blog post [UniTask v2 — Zero Allocation async/await for Unity, with Asynchronous LINQ](https://medium.com/@neuecc/unitask-v2-zero-allocation-async-await-for-unity-with-asynchronous-linq-1aa9c96aa7dd)). In default, cache all promises but you can configure `TaskPool.SetMaxPoolSize` to your value, the value indicates cache size per type. `TaskPool.GetCacheSizeInfo` returns current cached object in pool.
|
||||
|
||||
```csharp
|
||||
foreach (var (type, size) in TaskPool.GetCacheSizeInfo())
|
||||
@@ -906,7 +912,7 @@ After Unity 2019.3.4f1, Unity 2020.1a21, that support path query parameter of gi
|
||||
|
||||
or add `"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask"` to `Packages/manifest.json`.
|
||||
|
||||
If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#2.0.34`. For example `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.0.34`.
|
||||
If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#2.0.36`. For example `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.0.36`.
|
||||
|
||||
### Install via OpenUPM
|
||||
|
||||
|
||||
@@ -32,6 +32,19 @@ namespace Cysharp.Threading.Tasks
|
||||
return new UniTask(EnumeratorPromise.Create(enumerator, timing, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
public static UniTask ToUniTask(this IEnumerator enumerator, MonoBehaviour coroutineRunner)
|
||||
{
|
||||
var source = AutoResetUniTaskCompletionSource.Create();
|
||||
coroutineRunner.StartCoroutine(Core(enumerator, coroutineRunner, source));
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
static IEnumerator Core(IEnumerator inner, MonoBehaviour coroutineRunner, AutoResetUniTaskCompletionSource source)
|
||||
{
|
||||
yield return coroutineRunner.StartCoroutine(inner);
|
||||
source.TrySetResult();
|
||||
}
|
||||
|
||||
sealed class EnumeratorPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<EnumeratorPromise>
|
||||
{
|
||||
static TaskPool<EnumeratorPromise> pool;
|
||||
@@ -215,7 +228,7 @@ namespace Cysharp.Threading.Tasks
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return null;
|
||||
goto WARN;
|
||||
}
|
||||
}
|
||||
else if (current is IEnumerator e3)
|
||||
@@ -228,9 +241,15 @@ namespace Cysharp.Threading.Tasks
|
||||
}
|
||||
else
|
||||
{
|
||||
// WaitForEndOfFrame, WaitForFixedUpdate, others.
|
||||
yield return null;
|
||||
goto WARN;
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
WARN:
|
||||
// WaitForEndOfFrame, WaitForFixedUpdate, others.
|
||||
UnityEngine.Debug.LogWarning($"yield {current.GetType().Name} is not supported on await IEnumerator or IEnumerator.ToUniTask(), please use ToUniTask(MonoBehaviour coroutineRunner) instead.");
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,5 +280,4 @@ namespace Cysharp.Threading.Tasks
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -223,6 +223,17 @@ namespace Cysharp.Threading.Tasks
|
||||
|
||||
void OnCompleteCallbackDelegate()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
if (this.cancelBehaviour == TweenCancelBehaviour.KillAndCancelAwait
|
||||
|| this.cancelBehaviour == TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait
|
||||
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteAndCancelAwait
|
||||
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteWithSeqeunceCallbackAndCancelAwait
|
||||
|| this.cancelBehaviour == TweenCancelBehaviour.CancelAwait)
|
||||
{
|
||||
canceled = true;
|
||||
}
|
||||
}
|
||||
if (canceled)
|
||||
{
|
||||
core.TrySetCanceled(cancellationToken);
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||
|
||||
readonly PlayerLoopTiming timing;
|
||||
|
||||
SpinLock gate = new SpinLock();
|
||||
SpinLock gate = new SpinLock(false);
|
||||
bool dequing = false;
|
||||
|
||||
int actionListCount = 0;
|
||||
@@ -70,13 +70,17 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
public int Clear()
|
||||
{
|
||||
var rest = actionListCount + waitingListCount;
|
||||
|
||||
actionListCount = 0;
|
||||
actionList = new Action[InitialSize];
|
||||
|
||||
waitingListCount = 0;
|
||||
waitingList = new Action[InitialSize];
|
||||
|
||||
return rest;
|
||||
}
|
||||
|
||||
// delegate entrypoint.
|
||||
|
||||
@@ -48,14 +48,24 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
public int Clear()
|
||||
{
|
||||
lock (arrayLock)
|
||||
{
|
||||
var rest = 0;
|
||||
|
||||
for (var index = 0; index < loopItems.Length; index++)
|
||||
{
|
||||
if (loopItems[index] != null)
|
||||
{
|
||||
rest++;
|
||||
}
|
||||
|
||||
loopItems[index] = null;
|
||||
}
|
||||
|
||||
tail = 0;
|
||||
return rest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,8 +153,6 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||
{
|
||||
var j = tail - 1;
|
||||
|
||||
var loopItems = this.loopItems;
|
||||
// eliminate array-bound check for i
|
||||
for (int i = 0; i < loopItems.Length; i++)
|
||||
{
|
||||
var action = loopItems[i];
|
||||
|
||||
@@ -110,27 +110,30 @@ namespace Cysharp.Threading.Tasks
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.playModeStateChanged += (state) =>
|
||||
{
|
||||
if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.EnteredPlayMode)
|
||||
if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.ExitingEditMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// run rest action before clear.
|
||||
if (runner != null)
|
||||
{
|
||||
runner.Run();
|
||||
runner.Clear();
|
||||
}
|
||||
if (lastRunner != null)
|
||||
{
|
||||
lastRunner.Run();
|
||||
lastRunner.Clear();
|
||||
}
|
||||
|
||||
if (runner != null)
|
||||
{
|
||||
runner.Clear();
|
||||
}
|
||||
if (lastRunner != null)
|
||||
{
|
||||
lastRunner.Clear();
|
||||
}
|
||||
|
||||
if (cq != null)
|
||||
{
|
||||
cq.Clear();
|
||||
}
|
||||
if (lastCq != null)
|
||||
{
|
||||
lastCq.Clear();
|
||||
if (cq != null)
|
||||
{
|
||||
cq.Run();
|
||||
cq.Clear();
|
||||
}
|
||||
if (lastCq != null)
|
||||
{
|
||||
lastCq.Run();
|
||||
lastCq.Clear();
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -12,7 +12,9 @@ namespace Cysharp.Threading.Tasks
|
||||
public static class TaskPool
|
||||
{
|
||||
internal static int MaxPoolSize;
|
||||
static ConcurrentDictionary<Type, Func<int>> sizes = new ConcurrentDictionary<Type, Func<int>>();
|
||||
|
||||
// avoid to use ConcurrentDictionary for safety of WebGL build.
|
||||
static Dictionary<Type, Func<int>> sizes = new Dictionary<Type, Func<int>>();
|
||||
|
||||
static TaskPool()
|
||||
{
|
||||
@@ -40,19 +42,24 @@ namespace Cysharp.Threading.Tasks
|
||||
|
||||
public static IEnumerable<(Type, int)> GetCacheSizeInfo()
|
||||
{
|
||||
foreach (var item in sizes)
|
||||
lock (sizes)
|
||||
{
|
||||
yield return (item.Key, item.Value());
|
||||
foreach (var item in sizes)
|
||||
{
|
||||
yield return (item.Key, item.Value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterSizeGetter(Type type, Func<int> getSize)
|
||||
{
|
||||
sizes[type] = getSize;
|
||||
lock (sizes)
|
||||
{
|
||||
sizes[type] = getSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface ITaskPoolNode<T>
|
||||
{
|
||||
ref T NextNode { get; }
|
||||
|
||||
@@ -1541,6 +1541,7 @@ namespace Cysharp.Threading.Tasks.Triggers
|
||||
#endregion
|
||||
|
||||
#region MouseDown
|
||||
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
|
||||
public interface IAsyncOnMouseDownHandler
|
||||
{
|
||||
@@ -1597,9 +1598,11 @@ namespace Cysharp.Threading.Tasks.Triggers
|
||||
return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseDownAsync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region MouseDrag
|
||||
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
|
||||
public interface IAsyncOnMouseDragHandler
|
||||
{
|
||||
@@ -1656,9 +1659,11 @@ namespace Cysharp.Threading.Tasks.Triggers
|
||||
return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseDragAsync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region MouseEnter
|
||||
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
|
||||
public interface IAsyncOnMouseEnterHandler
|
||||
{
|
||||
@@ -1715,9 +1720,11 @@ namespace Cysharp.Threading.Tasks.Triggers
|
||||
return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseEnterAsync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region MouseExit
|
||||
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
|
||||
public interface IAsyncOnMouseExitHandler
|
||||
{
|
||||
@@ -1774,9 +1781,11 @@ namespace Cysharp.Threading.Tasks.Triggers
|
||||
return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseExitAsync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region MouseOver
|
||||
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
|
||||
public interface IAsyncOnMouseOverHandler
|
||||
{
|
||||
@@ -1833,9 +1842,11 @@ namespace Cysharp.Threading.Tasks.Triggers
|
||||
return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseOverAsync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region MouseUp
|
||||
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
|
||||
public interface IAsyncOnMouseUpHandler
|
||||
{
|
||||
@@ -1892,9 +1903,11 @@ namespace Cysharp.Threading.Tasks.Triggers
|
||||
return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseUpAsync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region MouseUpAsButton
|
||||
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
|
||||
public interface IAsyncOnMouseUpAsButtonHandler
|
||||
{
|
||||
@@ -1951,6 +1964,7 @@ namespace Cysharp.Threading.Tasks.Triggers
|
||||
return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseUpAsButtonAsync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region ParticleCollision
|
||||
|
||||
@@ -25,13 +25,7 @@
|
||||
("Update", "Update", "AsyncUnit", null, empty),
|
||||
("FixedUpdate", "FixedUpdate", "AsyncUnit", null, empty),
|
||||
("LateUpdate", "LateUpdate", "AsyncUnit", null, empty),
|
||||
("MouseDown", "OnMouseDown", "AsyncUnit", null, empty),
|
||||
("MouseDrag", "OnMouseDrag", "AsyncUnit", null, empty),
|
||||
("MouseEnter", "OnMouseEnter", "AsyncUnit", null, empty),
|
||||
("MouseExit", "OnMouseExit", "AsyncUnit", null, empty),
|
||||
("MouseOver", "OnMouseOver", "AsyncUnit", null, empty),
|
||||
("MouseUp", "OnMouseUp", "AsyncUnit", null, empty),
|
||||
("MouseUpAsButton", "OnMouseUpAsButton", "AsyncUnit", null, empty),
|
||||
|
||||
("ParticleCollision", "OnParticleCollision", "GameObject", null, new []{ ("GameObject", "other") }),
|
||||
("RectTransformDimensionsChange", "OnRectTransformDimensionsChange", "AsyncUnit", null, empty),
|
||||
("RectTransformRemoved", "OnRectTransformRemoved", "AsyncUnit", null, empty),
|
||||
@@ -47,6 +41,15 @@
|
||||
("BecameInvisible", "OnBecameInvisible", "AsyncUnit", null, empty),
|
||||
("BecameVisible", "OnBecameVisible", "AsyncUnit", null, empty),
|
||||
|
||||
// Mouse... #if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
("MouseDown", "OnMouseDown", "AsyncUnit", null, empty),
|
||||
("MouseDrag", "OnMouseDrag", "AsyncUnit", null, empty),
|
||||
("MouseEnter", "OnMouseEnter", "AsyncUnit", null, empty),
|
||||
("MouseExit", "OnMouseExit", "AsyncUnit", null, empty),
|
||||
("MouseOver", "OnMouseOver", "AsyncUnit", null, empty),
|
||||
("MouseUp", "OnMouseUp", "AsyncUnit", null, empty),
|
||||
("MouseUpAsButton", "OnMouseUpAsButton", "AsyncUnit", null, empty),
|
||||
|
||||
// new in v2
|
||||
("ApplicationFocus", "OnApplicationFocus", "bool", null, new []{("bool", "hasFocus") }),
|
||||
("ApplicationPause", "OnApplicationPause", "bool", null, new []{("bool", "pauseStatus") }),
|
||||
@@ -104,6 +107,7 @@
|
||||
Func<(string argType, string argName)[], string> BuildResultParameter = x => x.Length == 0 ? "AsyncUnit.Default" : "(" + string.Join(", ", x.Select(y => y.argName)) + ")";
|
||||
|
||||
Func<string, bool> Is2019_3 = x => x == "ParticleUpdateJobScheduled";
|
||||
Func<string, bool> IsMouseTrigger = x => x.StartsWith("Mouse");
|
||||
#>
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
@@ -117,6 +121,9 @@ namespace Cysharp.Threading.Tasks.Triggers
|
||||
#region <#= t.triggerName #>
|
||||
<# if(Is2019_3(t.triggerName)) { #>
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
<# } #>
|
||||
<# if(IsMouseTrigger(t.triggerName)) { #>
|
||||
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
<# } #>
|
||||
|
||||
public interface <#= ToInterfaceName(t.methodName) #>
|
||||
@@ -174,7 +181,7 @@ namespace Cysharp.Threading.Tasks.Triggers
|
||||
return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(this, cancellationToken, true)).<#= t.methodName #>Async();
|
||||
}
|
||||
}
|
||||
<# if(Is2019_3(t.triggerName)) { #>
|
||||
<# if(Is2019_3(t.triggerName) || IsMouseTrigger(t.triggerName)) { #>
|
||||
#endif
|
||||
<# } #>
|
||||
#endregion
|
||||
|
||||
@@ -561,21 +561,23 @@ namespace Cysharp.Threading.Tasks
|
||||
UniTaskScheduler.PublishUnobservedTaskException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
awaiter.SourceOnCompleted(state =>
|
||||
else
|
||||
{
|
||||
using (var t = (StateTuple<UniTask.Awaiter>)state)
|
||||
awaiter.SourceOnCompleted(state =>
|
||||
{
|
||||
try
|
||||
using (var t = (StateTuple<UniTask.Awaiter>)state)
|
||||
{
|
||||
t.Item1.GetResult();
|
||||
try
|
||||
{
|
||||
t.Item1.GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UniTaskScheduler.PublishUnobservedTaskException(ex);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UniTaskScheduler.PublishUnobservedTaskException(ex);
|
||||
}
|
||||
}
|
||||
}, StateTuple.Create(awaiter));
|
||||
}, StateTuple.Create(awaiter));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Forget(this UniTask task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true)
|
||||
@@ -629,21 +631,23 @@ namespace Cysharp.Threading.Tasks
|
||||
UniTaskScheduler.PublishUnobservedTaskException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
awaiter.SourceOnCompleted(state =>
|
||||
else
|
||||
{
|
||||
using (var t = (StateTuple<UniTask<T>.Awaiter>)state)
|
||||
awaiter.SourceOnCompleted(state =>
|
||||
{
|
||||
try
|
||||
using (var t = (StateTuple<UniTask<T>.Awaiter>)state)
|
||||
{
|
||||
t.Item1.GetResult();
|
||||
try
|
||||
{
|
||||
t.Item1.GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UniTaskScheduler.PublishUnobservedTaskException(ex);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UniTaskScheduler.PublishUnobservedTaskException(ex);
|
||||
}
|
||||
}
|
||||
}, StateTuple.Create(awaiter));
|
||||
}, StateTuple.Create(awaiter));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Forget<T>(this UniTask<T> task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true)
|
||||
@@ -736,12 +740,12 @@ namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
await await task;
|
||||
}
|
||||
|
||||
|
||||
public static async UniTask<T> Unwrap<T>(this Task<UniTask<T>> task)
|
||||
{
|
||||
return await await task;
|
||||
}
|
||||
|
||||
|
||||
public static async UniTask<T> Unwrap<T>(this Task<UniTask<T>> task, bool continueOnCapturedContext)
|
||||
{
|
||||
return await await task.ConfigureAwait(continueOnCapturedContext);
|
||||
@@ -756,12 +760,12 @@ namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
await await task.ConfigureAwait(continueOnCapturedContext);
|
||||
}
|
||||
|
||||
|
||||
public static async UniTask<T> Unwrap<T>(this UniTask<Task<T>> task)
|
||||
{
|
||||
return await await task;
|
||||
}
|
||||
|
||||
|
||||
public static async UniTask<T> Unwrap<T>(this UniTask<Task<T>> task, bool continueOnCapturedContext)
|
||||
{
|
||||
return await (await task).ConfigureAwait(continueOnCapturedContext);
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Cysharp.Threading.Tasks
|
||||
const int MaxArrayLength = 0X7FEFFFFF;
|
||||
const int InitialSize = 16;
|
||||
|
||||
static SpinLock gate = new SpinLock();
|
||||
static SpinLock gate = new SpinLock(false);
|
||||
static bool dequing = false;
|
||||
|
||||
static int actionListCount = 0;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.cysharp.unitask",
|
||||
"displayName": "UniTask",
|
||||
"version": "2.0.34",
|
||||
"version": "2.0.37",
|
||||
"unity": "2018.4",
|
||||
"description": "Provides an efficient async/await integration to Unity.",
|
||||
"keywords": [ "async/await", "async", "Task", "UniTask" ],
|
||||
|
||||
@@ -492,8 +492,44 @@ public class SandboxMain : MonoBehaviour
|
||||
Debug.Log("Current SyncContext:" + SynchronizationContext.Current.GetType().FullName);
|
||||
}
|
||||
|
||||
|
||||
async UniTask QuitCheck()
|
||||
{
|
||||
try
|
||||
{
|
||||
await UniTask.Delay(TimeSpan.FromMinutes(1), cancellationToken: quitSource.Token);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Debug.Log("End QuitCheck async");
|
||||
}
|
||||
}
|
||||
|
||||
CancellationTokenSource quitSource = new CancellationTokenSource();
|
||||
|
||||
|
||||
IEnumerator TestCor()
|
||||
{
|
||||
Debug.Log("start cor");
|
||||
yield return null;
|
||||
yield return new WaitForEndOfFrame();
|
||||
Debug.Log("end cor");
|
||||
}
|
||||
|
||||
async UniTaskVoid Start()
|
||||
{
|
||||
await TestCor().ToUniTask(this);
|
||||
|
||||
Debug.Log("App Start");
|
||||
|
||||
Application.quitting += () =>
|
||||
{
|
||||
Debug.Log("called quitting");
|
||||
quitSource.Cancel();
|
||||
};
|
||||
|
||||
QuitCheck().Forget();
|
||||
|
||||
//Expression.Lambda<Func<int>>(null).Compile(true);
|
||||
|
||||
//RunStandardTaskAsync();
|
||||
|
||||
@@ -55,6 +55,8 @@ namespace Cysharp.Threading.TasksTests
|
||||
}
|
||||
}
|
||||
|
||||
#if !UNITY_WEBGL
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator DelayAnd() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
@@ -76,6 +78,8 @@ namespace Cysharp.Threading.TasksTests
|
||||
}
|
||||
});
|
||||
|
||||
#endif
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator DelayIgnore() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
@@ -183,6 +187,8 @@ namespace Cysharp.Threading.TasksTests
|
||||
diff.Should().Be(11);
|
||||
});
|
||||
|
||||
#if !UNITY_WEBGL
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator SwitchTo() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
@@ -215,6 +221,8 @@ namespace Cysharp.Threading.TasksTests
|
||||
currentThreadId.Should().Be(switchedThreadId2);
|
||||
});
|
||||
|
||||
#endif
|
||||
|
||||
//[UnityTest]
|
||||
//public IEnumerator ObservableConversion() => UniTask.ToCoroutine(async () =>
|
||||
//{
|
||||
|
||||
@@ -135,6 +135,8 @@ namespace Cysharp.Threading.TasksTests
|
||||
l.Add(30);
|
||||
}
|
||||
|
||||
#if !UNITY_WEBGL
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator WaitForSecondsTest() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
@@ -162,6 +164,8 @@ namespace Cysharp.Threading.TasksTests
|
||||
yield return new WaitForSeconds(3.0f);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
IEnumerator Worker(List<(int, int)> l)
|
||||
{
|
||||
l.Add((0, Time.frameCount));
|
||||
|
||||
@@ -175,6 +175,7 @@ namespace Cysharp.Threading.TasksTests
|
||||
}
|
||||
});
|
||||
|
||||
#if !UNITY_WEBGL
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator DelayInThreadPool() => UniTask.ToCoroutine(async () =>
|
||||
@@ -185,6 +186,8 @@ namespace Cysharp.Threading.TasksTests
|
||||
});
|
||||
});
|
||||
|
||||
#endif
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator DelayRealtime() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
@@ -200,5 +203,16 @@ namespace Cysharp.Threading.TasksTests
|
||||
okay1.Should().Be(true);
|
||||
okay2.Should().Be(true);
|
||||
});
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator LoopTest() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
UniTask.DelayFrame(100).Forget();
|
||||
await UniTask.DelayFrame(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ namespace Cysharp.Threading.TasksTests
|
||||
{
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#if !UNITY_WSA
|
||||
#if !UNITY_WEBGL
|
||||
|
||||
//[UnityTest]
|
||||
//public IEnumerator RunThread() => UniTask.ToCoroutine(async () =>
|
||||
@@ -88,7 +89,7 @@ namespace Cysharp.Threading.TasksTests
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -543,7 +543,7 @@ PlayerSettings:
|
||||
platformArchitecture: {}
|
||||
scriptingBackend:
|
||||
Android: 1
|
||||
Standalone: 0
|
||||
Standalone: 1
|
||||
il2cppCompilerConfiguration: {}
|
||||
managedStrippingLevel: {}
|
||||
incrementalIl2cppBuild: {}
|
||||
|
||||
Reference in New Issue
Block a user