mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-25 17:30:12 +00:00
Compare commits
18 Commits
v2.5.11
...
a17afee0b0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a17afee0b0 | ||
|
|
2c20cf1e5d | ||
|
|
f213ff497e | ||
|
|
7568061eda | ||
|
|
459a572c1d | ||
|
|
06067cd4c8 | ||
|
|
d9983cfe27 | ||
|
|
70eb7cd3ee | ||
|
|
cc3c70af90 | ||
|
|
8042b29ff8 | ||
|
|
b0d01ca75f | ||
|
|
7a63ab7088 | ||
|
|
bdf102f145 | ||
|
|
41cea030ab | ||
|
|
f9fd769be7 | ||
|
|
579304fe47 | ||
|
|
740ca7ef01 | ||
|
|
7c0f199fe0 |
41
.editorconfig
Normal file
41
.editorconfig
Normal file
@@ -0,0 +1,41 @@
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Visual Studio Spell checker configs (https://learn.microsoft.com/en-us/visualstudio/ide/text-spell-checker?view=vs-2022#how-to-customize-the-spell-checker)
|
||||
spelling_exclusion_path = ./exclusion.dic
|
||||
|
||||
[*.cs]
|
||||
indent_size = 4
|
||||
charset = utf-8-bom
|
||||
end_of_line = unset
|
||||
|
||||
# Solution files
|
||||
[*.{sln,slnx}]
|
||||
end_of_line = unset
|
||||
|
||||
# MSBuild project files
|
||||
[*.{csproj,props,targets}]
|
||||
end_of_line = unset
|
||||
|
||||
# Xml config files
|
||||
[*.{ruleset,config,nuspec,resx,runsettings,DotSettings}]
|
||||
end_of_line = unset
|
||||
|
||||
[*{_AssemblyInfo.cs,.notsupported.cs}]
|
||||
generated_code = true
|
||||
|
||||
# C# code style settings
|
||||
[*.{cs}]
|
||||
dotnet_diagnostic.IDE0044.severity = none # IDE0044: Make field readonly
|
||||
|
||||
# https://stackoverflow.com/questions/79195382/how-to-disable-fading-unused-methods-in-visual-studio-2022-17-12-0
|
||||
dotnet_diagnostic.IDE0051.severity = none # IDE0051: Remove unused private member
|
||||
dotnet_diagnostic.IDE0130.severity = none # IDE0130: Namespace does not match folder structure
|
||||
5
.github/dependabot.yaml
vendored
5
.github/dependabot.yaml
vendored
@@ -5,3 +5,8 @@ updates:
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly" # Check for updates to GitHub Actions every week
|
||||
ignore:
|
||||
# I just want update action when major/minor version is updated. patch updates are too noisy.
|
||||
- dependency-name: '*'
|
||||
update-types:
|
||||
- version-update:semver-patch
|
||||
|
||||
@@ -10,10 +10,12 @@ on:
|
||||
|
||||
jobs:
|
||||
build-dotnet:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
|
||||
- run: dotnet build -c Debug
|
||||
- run: dotnet test -c Debug
|
||||
@@ -25,21 +27,23 @@ jobs:
|
||||
max-parallel: 2
|
||||
matrix:
|
||||
unity: ["2022.3.39f1", "6000.0.12f1"] # Test with LTS
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 30 # Unity build takes more than 20min.
|
||||
steps:
|
||||
- name: Load secrets
|
||||
id: op-load-secret
|
||||
uses: 1password/load-secrets-action@v2
|
||||
uses: 1password/load-secrets-action@581a835fb51b8e7ec56b71cf2ffddd7e68bb25e0 # v2.0.0
|
||||
with:
|
||||
export-env: false
|
||||
env:
|
||||
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
|
||||
UNITY_EMAIL: "op://GitHubActionsPublic/UNITY_LICENSE/username"
|
||||
UNITY_PASSWORD: "op://GitHubActionsPublic/UNITY_LICENSE/credential"
|
||||
UNITY_SERIAL: "op://GitHubActionsPublic/UNITY_LICENSE/serial"
|
||||
UNITY_EMAIL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/username"
|
||||
UNITY_PASSWORD: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/credential"
|
||||
UNITY_SERIAL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/serial"
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||
|
||||
# Execute scripts: Export Package
|
||||
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
|
||||
@@ -56,10 +60,6 @@ jobs:
|
||||
targetPlatform: StandaloneLinux64
|
||||
buildMethod: PackageExporter.Export
|
||||
|
||||
- uses: Cysharp/Actions/.github/actions/check-metas@main # check meta files
|
||||
with:
|
||||
directory: src/UniTask
|
||||
|
||||
# Execute UnitTest
|
||||
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend IL2CPP /BuildTarget StandaloneLinux64
|
||||
- name: Build UnitTest (IL2CPP)
|
||||
@@ -79,6 +79,10 @@ jobs:
|
||||
- name: Execute UnitTest
|
||||
run: ./src/UniTask/bin/UnitTest/StandaloneLinux64_IL2CPP/test
|
||||
|
||||
- uses: Cysharp/Actions/.github/actions/check-metas@main # check meta files
|
||||
with:
|
||||
directory: src/UniTask
|
||||
|
||||
# Store artifacts.
|
||||
- uses: Cysharp/Actions/.github/actions/upload-artifact@main
|
||||
if: ${{ startsWith(matrix.unity, '2021') }} # only execute 2021
|
||||
@@ -8,24 +8,27 @@ on:
|
||||
|
||||
jobs:
|
||||
run-docfx:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pages: write
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||
with:
|
||||
repository: Cysharp/DocfxTemplate
|
||||
path: docs/_DocfxTemplate
|
||||
- uses: Kirbyrawr/docfx-action@master
|
||||
- uses: Kirbyrawr/docfx-action@db9a22c8fe1e8693a2a21be54cb0b87dfaa72cc4
|
||||
name: Docfx metadata
|
||||
with:
|
||||
args: metadata docs/docfx.json
|
||||
- uses: Kirbyrawr/docfx-action@master
|
||||
- uses: Kirbyrawr/docfx-action@db9a22c8fe1e8693a2a21be54cb0b87dfaa72cc4
|
||||
name: Docfx build
|
||||
with:
|
||||
args: build docs/docfx.json
|
||||
- name: Publish to GitHub Pages
|
||||
uses: peaceiris/actions-gh-pages@v4
|
||||
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: docs/_site
|
||||
@@ -14,6 +14,9 @@ on:
|
||||
|
||||
jobs:
|
||||
update-packagejson:
|
||||
permissions:
|
||||
actions: read
|
||||
contents: write
|
||||
uses: Cysharp/Actions/.github/workflows/update-packagejson.yaml@main
|
||||
with:
|
||||
file-path: ./src/UniTask/Assets/Plugins/UniTask/package.json
|
||||
@@ -22,11 +25,13 @@ jobs:
|
||||
|
||||
build-dotnet:
|
||||
needs: [update-packagejson]
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
||||
- uses: actions/checkout@v4
|
||||
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||
with:
|
||||
ref: ${{ needs.update-packagejson.outputs.sha }}
|
||||
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
|
||||
@@ -46,22 +51,24 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
unity: ["2022.3.39f1"]
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Load secrets
|
||||
id: op-load-secret
|
||||
uses: 1password/load-secrets-action@v2
|
||||
uses: 1password/load-secrets-action@581a835fb51b8e7ec56b71cf2ffddd7e68bb25e0 # v2.0.0
|
||||
with:
|
||||
export-env: false
|
||||
env:
|
||||
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
|
||||
UNITY_EMAIL: "op://GitHubActionsPublic/UNITY_LICENSE/username"
|
||||
UNITY_PASSWORD: "op://GitHubActionsPublic/UNITY_LICENSE/credential"
|
||||
UNITY_SERIAL: "op://GitHubActionsPublic/UNITY_LICENSE/serial"
|
||||
UNITY_EMAIL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/username"
|
||||
UNITY_PASSWORD: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/credential"
|
||||
UNITY_SERIAL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/serial"
|
||||
|
||||
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
||||
- uses: actions/checkout@v4
|
||||
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||
with:
|
||||
ref: ${{ needs.update-packagejson.outputs.sha }}
|
||||
# Execute scripts: Export Package
|
||||
@@ -92,6 +99,8 @@ jobs:
|
||||
# release
|
||||
create-release:
|
||||
needs: [update-packagejson, build-dotnet, build-unity]
|
||||
permissions:
|
||||
contents: write
|
||||
uses: Cysharp/Actions/.github/workflows/create-release.yaml@main
|
||||
with:
|
||||
commit-id: ${{ needs.update-packagejson.outputs.sha }}
|
||||
@@ -105,6 +114,8 @@ jobs:
|
||||
cleanup:
|
||||
if: ${{ needs.update-packagejson.outputs.is-branch-created == 'true' }}
|
||||
needs: [update-packagejson, build-dotnet, build-unity]
|
||||
permissions:
|
||||
contents: write
|
||||
uses: Cysharp/Actions/.github/workflows/clean-packagejson-branch.yaml@main
|
||||
with:
|
||||
branch: ${{ needs.update-packagejson.outputs.branch-name }}
|
||||
@@ -7,4 +7,6 @@ on:
|
||||
|
||||
jobs:
|
||||
detect:
|
||||
permissions:
|
||||
contents: read
|
||||
uses: Cysharp/Actions/.github/workflows/prevent-github-change.yaml@main
|
||||
@@ -7,4 +7,8 @@ on:
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
issues: write
|
||||
uses: Cysharp/Actions/.github/workflows/stale-issue.yaml@main
|
||||
15
.github/workflows/toc.yaml
vendored
Normal file
15
.github/workflows/toc.yaml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
name: TOC Generator
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
toc:
|
||||
permissions:
|
||||
contents: write
|
||||
uses: Cysharp/Actions/.github/workflows/toc-generator.yaml@main
|
||||
with:
|
||||
TOC_TITLE: "## Table of Contents"
|
||||
secrets: inherit
|
||||
15
.github/workflows/toc.yml
vendored
15
.github/workflows/toc.yml
vendored
@@ -1,15 +0,0 @@
|
||||
name: TOC Generator
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
generateTOC:
|
||||
name: TOC Generator
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: technote-space/toc-generator@v4.3.1
|
||||
with:
|
||||
TOC_TITLE: "## Table of Contents"
|
||||
12
README.md
12
README.md
@@ -33,6 +33,7 @@ For advanced tips, see blog post: [Extends UnityWebRequest via async decorator p
|
||||
- [AsyncEnumerable and Async LINQ](#asyncenumerable-and-async-linq)
|
||||
- [Awaitable Events](#awaitable-events)
|
||||
- [Channel](#channel)
|
||||
- [vs Awaitable](#vs-awaitable)
|
||||
- [For Unit Testing](#for-unit-testing)
|
||||
- [ThreadPool limitation](#threadpool-limitation)
|
||||
- [IEnumerator.ToUniTask limitation](#ienumeratortounitask-limitation)
|
||||
@@ -67,6 +68,7 @@ async UniTask<string> DemoAsync()
|
||||
await SceneManager.LoadSceneAsync("scene2");
|
||||
|
||||
// .WithCancellation enables Cancel, GetCancellationTokenOnDestroy synchornizes with lifetime of GameObject
|
||||
// after Unity 2022.2, you can use `destroyCancellationToken` in MonoBehaviour
|
||||
var asset2 = await Resources.LoadAsync<TextAsset>("bar").WithCancellation(this.GetCancellationTokenOnDestroy());
|
||||
|
||||
// .ToUniTask accepts progress callback(and all options), Progress.Create is a lightweight alternative of IProgress<T>
|
||||
@@ -293,6 +295,8 @@ public class MyBehaviour : MonoBehaviour
|
||||
}
|
||||
```
|
||||
|
||||
After Unity 2022.2, Unity adds CancellationToken in [MonoBehaviour.destroyCancellationToken](https://docs.unity3d.com/ScriptReference/MonoBehaviour-destroyCancellationToken.html) and [Application.exitCancellationToken](https://docs.unity3d.com/ScriptReference/Application-exitCancellationToken.html).
|
||||
|
||||
When cancellation is detected, all methods throw `OperationCanceledException` and propagate upstream. When exception(not limited to `OperationCanceledException`) is not handled in async method, it is propagated finally to `UniTaskScheduler.UnobservedTaskException`. The default behaviour of received unhandled exception is to write log as exception. Log level can be changed using `UniTaskScheduler.UnobservedExceptionWriteLogType`. If you want to use custom behaviour, set an action to `UniTaskScheduler.UnobservedTaskException.`
|
||||
|
||||
And also `OperationCanceledException` is a special exception, this is silently ignored at `UnobservedTaskException`.
|
||||
@@ -953,6 +957,14 @@ public class AsyncMessageBroker<T> : IDisposable
|
||||
}
|
||||
```
|
||||
|
||||
vs Awaitable
|
||||
---
|
||||
Unity 6 introduces the awaitable type, [Awaitable](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Awaitable.html). To put it simply, Awaitable can be considered a subset of UniTask, and in fact, Awaitable's design was influenced by UniTask. It should be able to handle PlayerLoop-based awaits, pooled Tasks, and support for cancellation with `CancellationToken` in a similar way. With its inclusion in the standard library, you may wonder whether to continue using UniTask or migrate to Awaitable. Here's a brief guide.
|
||||
|
||||
First, the functionality provided by Awaitable is equivalent to what coroutines offer. Instead of `yield return`, you use await; `await NextFrameAsync()` replaces `yield return null`; and there are equivalents for `WaitForSeconds` and `EndOfFrame`. However, that's the extent of it. Being coroutine-based in terms of functionality, it lacks Task-based features. In practical application development using async/await, operations like `WhenAll` are essential. Additionally, UniTask enables many frame-based operations (such as `DelayFrame`) and more flexible PlayerLoopTiming control, which are not available in Awaitable. Of course, there's no Tracker Window either.
|
||||
|
||||
Therefore, I recommend using UniTask for application development. UniTask is a superset of Awaitable and includes many essential features. For library development, where you want to avoid external dependencies, using Awaitable as a return type for methods would be appropriate. Awaitable can be converted to UniTask using `AsUniTask`, so there's no issue in handling Awaitable-based functionality within the UniTask library. Of course, if you don't need to worry about dependencies, using UniTask would be the best choice even for library development.
|
||||
|
||||
For Unit Testing
|
||||
---
|
||||
Unity's `[UnityTest]` attribute can test coroutine(IEnumerator) but can not test async. `UniTask.ToCoroutine` bridges async/await to coroutine so you can test async methods.
|
||||
|
||||
466
README_CN.md
466
README_CN.md
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
||||
#if UNITASK_TEXTMESHPRO_SUPPORT
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using TMPro;
|
||||
|
||||
namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
public static partial class TextMeshProAsyncExtensions
|
||||
{
|
||||
public static IAsyncValueChangedEventHandler<int> GetAsyncValueChangedEventHandler(this TMP_Dropdown dropdown)
|
||||
{
|
||||
return new AsyncUnityEventHandler<int>(dropdown.onValueChanged, dropdown.GetCancellationTokenOnDestroy(), false);
|
||||
}
|
||||
|
||||
public static IAsyncValueChangedEventHandler<int> GetAsyncValueChangedEventHandler(this TMP_Dropdown dropdown, CancellationToken cancellationToken)
|
||||
{
|
||||
return new AsyncUnityEventHandler<int>(dropdown.onValueChanged, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<int> OnValueChangedAsync(this TMP_Dropdown dropdown)
|
||||
{
|
||||
return new AsyncUnityEventHandler<int>(dropdown.onValueChanged, dropdown.GetCancellationTokenOnDestroy(), true).OnInvokeAsync();
|
||||
}
|
||||
|
||||
public static UniTask<int> OnValueChangedAsync(this TMP_Dropdown dropdown, CancellationToken cancellationToken)
|
||||
{
|
||||
return new AsyncUnityEventHandler<int>(dropdown.onValueChanged, cancellationToken, true).OnInvokeAsync();
|
||||
}
|
||||
|
||||
public static IUniTaskAsyncEnumerable<int> OnValueChangedAsAsyncEnumerable(this TMP_Dropdown dropdown)
|
||||
{
|
||||
return new UnityEventHandlerAsyncEnumerable<int>(dropdown.onValueChanged, dropdown.GetCancellationTokenOnDestroy());
|
||||
}
|
||||
|
||||
public static IUniTaskAsyncEnumerable<int> OnValueChangedAsAsyncEnumerable(this TMP_Dropdown dropdown, CancellationToken cancellationToken)
|
||||
{
|
||||
return new UnityEventHandlerAsyncEnumerable<int>(dropdown.onValueChanged, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b858132b120c42b99cac55fd06dd32d3
|
||||
timeCreated: 1736165018
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "com.cysharp.unitask",
|
||||
"displayName": "UniTask",
|
||||
"author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" },
|
||||
"version": "2.5.9",
|
||||
"version": "2.5.10",
|
||||
"unity": "2018.4",
|
||||
"description": "Provides an efficient async/await integration to Unity.",
|
||||
"keywords": [ "async/await", "async", "Task", "UniTask" ],
|
||||
|
||||
Reference in New Issue
Block a user