mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-15 03:20:16 +00:00
Compare commits
129 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e33d572104 | ||
|
|
2b2af9e455 | ||
|
|
d003597662 | ||
|
|
ec0a8f5a8b | ||
|
|
49ba57f20a | ||
|
|
6f4d1183cc | ||
|
|
dd18c9fff8 | ||
|
|
21f5f78ff1 | ||
|
|
1729f389db | ||
|
|
6d37bb7bac | ||
|
|
957adfad7a | ||
|
|
3ef889e17d | ||
|
|
c73af7390f | ||
|
|
c5b4376486 | ||
|
|
ba65049dd8 | ||
|
|
ee58aab0a9 | ||
|
|
859eaa2278 | ||
|
|
79f770e687 | ||
|
|
8ff4de67a1 | ||
|
|
6a7a6fde5c | ||
|
|
6a5e259006 | ||
|
|
f6622ad29c | ||
|
|
3de29a181d | ||
|
|
090cacece5 | ||
|
|
354fd65d58 | ||
|
|
d3538bdc8f | ||
|
|
bd6906792d | ||
|
|
7fc6c6bd36 | ||
|
|
c23b9ca480 | ||
|
|
cda59ba9c2 | ||
|
|
61a3744fdd | ||
|
|
72efadd0a2 | ||
|
|
57c414a6e0 | ||
|
|
85dc70a3ab | ||
|
|
7298686d5a | ||
|
|
418586fbfb | ||
|
|
12c507574e | ||
|
|
b20b37e7a5 | ||
|
|
8ef7a66081 | ||
|
|
a5f47d4095 | ||
|
|
1316328766 | ||
|
|
c0da316cb4 | ||
|
|
4d13523df7 | ||
|
|
16c527fa89 | ||
|
|
5db5beab29 | ||
|
|
3f082f1923 | ||
|
|
93dd82e3d4 | ||
|
|
af6dbd8868 | ||
|
|
716decd199 | ||
|
|
f37cd703a9 | ||
|
|
31b788a2c9 | ||
|
|
e93bcbf564 | ||
|
|
aa8cb80866 | ||
|
|
dd6a8da96f | ||
|
|
d4511c0f67 | ||
|
|
c16433e0fe | ||
|
|
ed0990e402 | ||
|
|
856a049dd0 | ||
|
|
61b798b6e9 | ||
|
|
be45066773 | ||
|
|
5d0d29dffd | ||
|
|
be539fdb10 | ||
|
|
66fa203f7c | ||
|
|
a78dc55875 | ||
|
|
84f4d8007d | ||
|
|
6be955816b | ||
|
|
ebe3065c34 | ||
|
|
5f90807cb7 | ||
|
|
81d83c17c3 | ||
|
|
4e9d268d1c | ||
|
|
6c1b590fd8 | ||
|
|
32a4e84513 | ||
|
|
7f61f85bc7 | ||
|
|
f0d745924a | ||
|
|
51f4003bc5 | ||
|
|
b9b2925e8d | ||
|
|
7cb0b17e6a | ||
|
|
d565f39dde | ||
|
|
a26a806b0f | ||
|
|
eb379903b8 | ||
|
|
6e80295ec7 | ||
|
|
75f0bd26e7 | ||
|
|
b8d1a09224 | ||
|
|
7bc9ef90f1 | ||
|
|
28e1fa98c9 | ||
|
|
9f7b897837 | ||
|
|
f28743f7f6 | ||
|
|
341953b441 | ||
|
|
623936c7b8 | ||
|
|
3654a9e2f9 | ||
|
|
082f3e7335 | ||
|
|
fbec6e9a58 | ||
|
|
ef248e2e0a | ||
|
|
86fa934510 | ||
|
|
ca58784c4d | ||
|
|
11bc28b33f | ||
|
|
b2d3423a33 | ||
|
|
2ccaf0a03b | ||
|
|
b4ec35aadd | ||
|
|
6c64205292 | ||
|
|
232e2eb1f2 | ||
|
|
34b065520f | ||
|
|
e6734478c5 | ||
|
|
d5f607204b | ||
|
|
676aba7cce | ||
|
|
745de32006 | ||
|
|
a0ef75e797 | ||
|
|
dda6cbd679 | ||
|
|
141b447b30 | ||
|
|
8e7a89eff7 | ||
|
|
7848f878d7 | ||
|
|
c3a02ffbe6 | ||
|
|
d509317ed2 | ||
|
|
74738ab13e | ||
|
|
de3d491375 | ||
|
|
139f5f7914 | ||
|
|
5e2a4934dd | ||
|
|
4ef15f3a14 | ||
|
|
6d56f8d2bb | ||
|
|
6e441a2d14 | ||
|
|
66ba4b9986 | ||
|
|
7e26573abb | ||
|
|
9db6482f0a | ||
|
|
9c257e44f0 | ||
|
|
ecd678117e | ||
|
|
ebce2e922d | ||
|
|
e67562b823 | ||
|
|
d639283f59 | ||
|
|
ecf6c1fba5 |
@@ -1,84 +0,0 @@
|
||||
version: 2.1
|
||||
executors:
|
||||
unity:
|
||||
# https://hub.docker.com/r/gableroux/unity3d/tags
|
||||
parameters:
|
||||
version: {type: string}
|
||||
docker:
|
||||
- image: gableroux/unity3d:<< parameters.version >>
|
||||
commands:
|
||||
unity_activate:
|
||||
parameters:
|
||||
unity_version: {type: string}
|
||||
unity_license: {type: string}
|
||||
steps:
|
||||
# get activation file, if fail to activate unity, use this key and activate from https://license.unity3d.com/manual
|
||||
- run: apt update && apt install libunwind8 -y
|
||||
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -logFile -createManualActivationFile || exit 0
|
||||
- run: cat Unity_v<< parameters.unity_version >>.alf
|
||||
# get from UNITY_LICENSE envvar(base64 encoded(cat foo.ulf | base64 )), this file is generated from above manual activation
|
||||
- run: echo << parameters.unity_license >> | base64 -di >> .circleci/Unity.ulf
|
||||
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -manualLicenseFile .circleci/Unity.ulf || exit 0
|
||||
jobs:
|
||||
build-and-test:
|
||||
parameters:
|
||||
unity_version: {type: string}
|
||||
unity_license: {type: string}
|
||||
executor:
|
||||
name: unity
|
||||
version: << parameters.unity_version >>
|
||||
steps:
|
||||
- checkout
|
||||
- unity_activate:
|
||||
unity_version: << parameters.unity_version >>
|
||||
unity_license: << parameters.unity_license >>
|
||||
- run:
|
||||
name: Build Linux(Mono)
|
||||
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend Mono2x /BuildTarget StandaloneLinux64
|
||||
working_directory: .
|
||||
# TODO:check unity version and packages...
|
||||
# - run: ./bin/UnitTest/StandaloneLinux64_Mono2x/test
|
||||
build-and-create-package:
|
||||
parameters:
|
||||
unity_version: {type: string}
|
||||
unity_license: {type: string}
|
||||
executor:
|
||||
name: unity
|
||||
version: << parameters.unity_version >>
|
||||
steps:
|
||||
- checkout
|
||||
- unity_activate:
|
||||
unity_version: << parameters.unity_version >>
|
||||
unity_license: << parameters.unity_license >>
|
||||
- run:
|
||||
name: Export unitypackage
|
||||
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
|
||||
working_directory: .
|
||||
- store_artifacts:
|
||||
path: ./UniRx.Async.unitypackage
|
||||
destination: /UniRx.Async.unitypackage
|
||||
workflows:
|
||||
version: 2
|
||||
build-unity:
|
||||
jobs:
|
||||
# does not exists yet.
|
||||
# - build-and-test:
|
||||
# unity_version: 2019.3.0a2
|
||||
# unity_license: ${UNITY_LICENSE_2019_3}
|
||||
# - build-and-test:
|
||||
# unity_version: 2019.2.0b2
|
||||
# unity_license: ${UNITY_LICENSE_2019_2}
|
||||
- build-and-create-package:
|
||||
unity_version: 2019.1.2f1
|
||||
unity_license: ${UNITY_LICENSE_2019_1}
|
||||
- build-and-test:
|
||||
unity_version: 2019.1.2f1
|
||||
unity_license: ${UNITY_LICENSE_2019_1}
|
||||
# test asmdef will not found.
|
||||
# - build-and-test:
|
||||
# unity_version: 2018.4.0f1
|
||||
# unity_license: ${UNITY_LICENSE_2018_4}
|
||||
# # UniTask minimum support version is 2018.3(C# 7.x)
|
||||
# - build-and-test:
|
||||
# unity_version: 2018.3.12f1
|
||||
# unity_license: ${UNITY_LICENSE_2018_3}
|
||||
73
.github/workflows/build-debug.yml
vendored
Normal file
73
.github/workflows/build-debug.yml
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
name: Build-Debug
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "**"
|
||||
tags:
|
||||
- "!*" # not a tag push
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- synchronize
|
||||
|
||||
jobs:
|
||||
build-dotnet:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
||||
NUGET_XMLDOC_MODE: skip
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.101
|
||||
- run: dotnet test -c Debug ./src/UniTask.NetCoreTests/UniTask.NetCoreTests.csproj
|
||||
|
||||
build-unity:
|
||||
strategy:
|
||||
matrix:
|
||||
unity: ['2019.3.9f1', '2020.1.0b5']
|
||||
include:
|
||||
- unity: 2019.3.9f1
|
||||
license: UNITY_2019_3
|
||||
- unity: 2020.1.0b5
|
||||
license: UNITY_2020_1
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
# with linux-il2cpp. image from https://hub.docker.com/r/gableroux/unity3d/tags
|
||||
image: gableroux/unity3d:${{ matrix.unity }}-linux-il2cpp
|
||||
steps:
|
||||
- run: apt update && apt install git -y
|
||||
- uses: actions/checkout@v2
|
||||
# create unity activation file and store to artifacts.
|
||||
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -logFile -createManualActivationFile || exit 0
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: Unity_v${{ matrix.unity }}.alf
|
||||
path: ./Unity_v${{ matrix.unity }}.alf
|
||||
# activate Unity from manual license file(ulf)
|
||||
- run: echo -n "$UNITY_LICENSE" >> .Unity.ulf
|
||||
env:
|
||||
UNITY_LICENSE: ${{ secrets[matrix.license] }}
|
||||
- name: Activate Unity, always returns a success. But if a subsequent run fails, the activation may have failed(if succeeded, shows `Next license update check is after` and not shows other message(like GUID != GUID). If fails not). In that case, upload the artifact's .alf file to https://license.unity3d.com/manual to get the .ulf file and set it to secrets.
|
||||
run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -manualLicenseFile .Unity.ulf || exit 0
|
||||
|
||||
# Execute scripts: RuntimeUnitTestToolkit
|
||||
- name: Build UnitTest(Linux64, mono)
|
||||
run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend mono /BuildTarget StandaloneLinux64
|
||||
working-directory: src/UniTask
|
||||
- name: Execute UnitTest
|
||||
run: ./src/UniTask/bin/UnitTest/StandaloneLinux64_Mono2x/test
|
||||
|
||||
# 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.
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: UniTask.unitypackage.zip
|
||||
path: ./src/UniTask/*.unitypackage
|
||||
108
.github/workflows/build-release.yml
vendored
Normal file
108
.github/workflows/build-release.yml
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
name: Build-Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "[0-9]+.[0-9]+.[0-9]+*"
|
||||
|
||||
jobs:
|
||||
build-dotnet:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
||||
NUGET_XMLDOC_MODE: skip
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- 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/}
|
||||
|
||||
# build CommandTools first (use dotnet run command in ZLogger.csproj)
|
||||
- run: dotnet build -c Release ./tools/CommandTools/CommandTools.csproj
|
||||
- run: dotnet build -c Release -p:Version=${{ env.GIT_TAG }}
|
||||
- run: dotnet test -c Release --no-build
|
||||
- run: dotnet pack ./src/ZLogger/ZLogger.csproj -c Release --no-build -p:Version=${{ env.GIT_TAG }}
|
||||
|
||||
# Store artifacts.
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: nuget
|
||||
path: ./src/ZLogger/bin/Release/ZLogger.${{ env.GIT_TAG }}.nupkg
|
||||
|
||||
build-unity:
|
||||
strategy:
|
||||
matrix:
|
||||
unity: ['2019.3.9f1']
|
||||
include:
|
||||
- unity: 2019.3.9f1
|
||||
license: UNITY_2019_3
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
# with linux-il2cpp. image from https://hub.docker.com/r/gableroux/unity3d/tags
|
||||
image: gableroux/unity3d:${{ matrix.unity }}-linux-il2cpp
|
||||
steps:
|
||||
- run: apt update && apt install git -y
|
||||
- uses: actions/checkout@v2
|
||||
- run: echo -n "$UNITY_LICENSE" >> .Unity.ulf
|
||||
env:
|
||||
UNITY_LICENSE: ${{ secrets[matrix.license] }}
|
||||
- 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/}
|
||||
|
||||
# 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/ZLogger.Unity
|
||||
env:
|
||||
UNITY_PACKAGE_VERSION: ${{ env.GIT_TAG }}
|
||||
|
||||
# Store artifacts.
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: ZLogger.Unity.${{ env.GIT_TAG }}.unitypackage
|
||||
path: ./src/ZLogger.Unity/ZLogger.Unity.${{ env.GIT_TAG }}.unitypackage
|
||||
|
||||
create-release:
|
||||
needs: [build-dotnet, build-unity]
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
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/}
|
||||
|
||||
# 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
|
||||
|
||||
# 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: ./ZLogger.Unity.${{ env.GIT_TAG }}.unitypackage/ZLogger.Unity.${{ env.GIT_TAG }}.unitypackage
|
||||
asset_name: ZLogger.Unity.${{ env.GIT_TAG }}.unitypackage
|
||||
asset_content_type: application/octet-stream
|
||||
15
.github/workflows/toc.yml
vendored
Normal file
15
.github/workflows/toc.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
name: TOC Generator
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
generateTOC:
|
||||
name: TOC Generator
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: technote-space/toc-generator@v2.4.0
|
||||
with:
|
||||
TOC_TITLE: "## Table of Contents"
|
||||
12
.gitignore
vendored
12
.gitignore
vendored
@@ -145,3 +145,15 @@ RuntimeUnitTestToolkit\.csproj
|
||||
Assembly-CSharp-Editor\.csproj
|
||||
|
||||
UniRx\.Async\.unitypackage
|
||||
|
||||
UniRx.Async.Tests.Editor.csproj
|
||||
|
||||
src/UniTask/UniTask.csproj
|
||||
|
||||
src/UniTask/UniTask.Editor.csproj
|
||||
|
||||
src/UniTask/UniTask.Tests.csproj
|
||||
|
||||
src/UniTask/UniTask.Tests.Editor.csproj
|
||||
|
||||
src/UniTask/UniTask.*.unitypackage
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public static class PackageExporter
|
||||
{
|
||||
[MenuItem("Tools/Export Unitypackage")]
|
||||
public static void Export()
|
||||
{
|
||||
// configure
|
||||
var root = "UniRx.Async";
|
||||
var exportPath = "./UniRx.Async.unitypackage";
|
||||
|
||||
var path = Path.Combine(Application.dataPath, root);
|
||||
var assets = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)
|
||||
.Where(x => Path.GetExtension(x) == ".cs" || Path.GetExtension(x) == ".asmdef" || Path.GetExtension(x) == ".json")
|
||||
.Select(x => "Assets" + x.Replace(Application.dataPath, "").Replace(@"\", "/"))
|
||||
.ToArray();
|
||||
|
||||
UnityEngine.Debug.Log("Export below files" + Environment.NewLine + string.Join(Environment.NewLine, assets));
|
||||
|
||||
AssetDatabase.ExportPackage(
|
||||
assets,
|
||||
exportPath,
|
||||
ExportPackageOptions.Default);
|
||||
|
||||
UnityEngine.Debug.Log("Export complete: " + Path.GetFullPath(exportPath));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,450 +0,0 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RuntimeUnitTestToolkit
|
||||
{
|
||||
public class UnitTestRunner : MonoBehaviour
|
||||
{
|
||||
// object is IEnumerator or Func<IEnumerator>
|
||||
Dictionary<string, List<KeyValuePair<string, object>>> tests = new Dictionary<string, List<KeyValuePair<string, object>>>();
|
||||
|
||||
List<Pair> additionalActionsOnFirst = new List<Pair>();
|
||||
|
||||
public Button clearButton;
|
||||
public RectTransform list;
|
||||
public Scrollbar listScrollBar;
|
||||
|
||||
public Text logText;
|
||||
public Scrollbar logScrollBar;
|
||||
|
||||
readonly Color passColor = new Color(0f, 1f, 0f, 1f); // green
|
||||
readonly Color failColor = new Color(1f, 0f, 0f, 1f); // red
|
||||
readonly Color normalColor = new Color(1f, 1f, 1f, 1f); // white
|
||||
|
||||
bool allTestGreen = true;
|
||||
|
||||
void Start()
|
||||
{
|
||||
try
|
||||
{
|
||||
UnityEngine.Application.logMessageReceived += (a, b, c) =>
|
||||
{
|
||||
logText.text += "[" + c + "]" + a + "\n";
|
||||
};
|
||||
|
||||
// register all test types
|
||||
foreach (var item in GetTestTargetTypes())
|
||||
{
|
||||
RegisterAllMethods(item);
|
||||
}
|
||||
|
||||
var executeAll = new List<Func<Coroutine>>();
|
||||
foreach (var ___item in tests)
|
||||
{
|
||||
var actionList = ___item; // be careful, capture in lambda
|
||||
|
||||
executeAll.Add(() => StartCoroutine(RunTestInCoroutine(actionList)));
|
||||
Add(actionList.Key, () => StartCoroutine(RunTestInCoroutine(actionList)));
|
||||
}
|
||||
|
||||
var executeAllButton = Add("Run All Tests", () => StartCoroutine(ExecuteAllInCoroutine(executeAll)));
|
||||
|
||||
clearButton.gameObject.GetComponent<Image>().color = new Color(170 / 255f, 170 / 255f, 170 / 255f, 1);
|
||||
executeAllButton.gameObject.GetComponent<Image>().color = new Color(250 / 255f, 150 / 255f, 150 / 255f, 1);
|
||||
executeAllButton.transform.SetSiblingIndex(1);
|
||||
|
||||
additionalActionsOnFirst.Reverse();
|
||||
foreach (var item in additionalActionsOnFirst)
|
||||
{
|
||||
var newButton = GameObject.Instantiate(clearButton);
|
||||
newButton.name = item.Name;
|
||||
newButton.onClick.RemoveAllListeners();
|
||||
newButton.GetComponentInChildren<Text>().text = item.Name;
|
||||
newButton.onClick.AddListener(item.Action);
|
||||
newButton.transform.SetParent(list);
|
||||
newButton.transform.SetSiblingIndex(1);
|
||||
}
|
||||
|
||||
clearButton.onClick.AddListener(() =>
|
||||
{
|
||||
logText.text = "";
|
||||
foreach (var btn in list.GetComponentsInChildren<Button>())
|
||||
{
|
||||
btn.interactable = true;
|
||||
btn.GetComponent<Image>().color = normalColor;
|
||||
}
|
||||
executeAllButton.gameObject.GetComponent<Image>().color = new Color(250 / 255f, 150 / 255f, 150 / 255f, 1);
|
||||
});
|
||||
|
||||
listScrollBar.value = 1;
|
||||
logScrollBar.value = 1;
|
||||
|
||||
if (Application.isBatchMode)
|
||||
{
|
||||
// run immediately in player
|
||||
StartCoroutine(ExecuteAllInCoroutine(executeAll));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (Application.isBatchMode)
|
||||
{
|
||||
// when failed(can not start runner), quit immediately.
|
||||
WriteToConsole(ex.ToString());
|
||||
Application.Quit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button Add(string title, UnityAction test)
|
||||
{
|
||||
var newButton = GameObject.Instantiate(clearButton);
|
||||
newButton.name = title;
|
||||
newButton.onClick.RemoveAllListeners();
|
||||
newButton.GetComponentInChildren<Text>().text = title;
|
||||
newButton.onClick.AddListener(test);
|
||||
|
||||
newButton.transform.SetParent(list);
|
||||
return newButton;
|
||||
}
|
||||
|
||||
static IEnumerable<Type> GetTestTargetTypes()
|
||||
{
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
var n = assembly.FullName;
|
||||
if (n.StartsWith("UnityEngine")) continue;
|
||||
if (n.StartsWith("mscorlib")) continue;
|
||||
if (n.StartsWith("System")) continue;
|
||||
|
||||
foreach (var item in assembly.GetTypes())
|
||||
{
|
||||
foreach (var method in item.GetMethods())
|
||||
{
|
||||
var t1 = method.GetCustomAttribute<TestAttribute>(true);
|
||||
if (t1 != null)
|
||||
{
|
||||
yield return item;
|
||||
break;
|
||||
}
|
||||
var t2 = method.GetCustomAttribute<UnityTestAttribute>(true);
|
||||
if (t2 != null)
|
||||
{
|
||||
yield return item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddTest(string group, string title, Action test)
|
||||
{
|
||||
List<KeyValuePair<string, object>> list;
|
||||
if (!tests.TryGetValue(group, out list))
|
||||
{
|
||||
list = new List<KeyValuePair<string, object>>();
|
||||
tests[group] = list;
|
||||
}
|
||||
|
||||
list.Add(new KeyValuePair<string, object>(title, test));
|
||||
}
|
||||
|
||||
public void AddAsyncTest(string group, string title, Func<IEnumerator> asyncTestCoroutine)
|
||||
{
|
||||
List<KeyValuePair<string, object>> list;
|
||||
if (!tests.TryGetValue(group, out list))
|
||||
{
|
||||
list = new List<KeyValuePair<string, object>>();
|
||||
tests[group] = list;
|
||||
}
|
||||
|
||||
list.Add(new KeyValuePair<string, object>(title, asyncTestCoroutine));
|
||||
}
|
||||
|
||||
public void AddCutomAction(string name, UnityAction action)
|
||||
{
|
||||
additionalActionsOnFirst.Add(new Pair { Name = name, Action = action });
|
||||
}
|
||||
|
||||
|
||||
public void RegisterAllMethods<T>()
|
||||
where T : new()
|
||||
{
|
||||
RegisterAllMethods(typeof(T));
|
||||
}
|
||||
|
||||
public void RegisterAllMethods(Type testType)
|
||||
{
|
||||
try
|
||||
{
|
||||
var test = Activator.CreateInstance(testType);
|
||||
|
||||
var methods = testType.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
|
||||
foreach (var item in methods)
|
||||
{
|
||||
try
|
||||
{
|
||||
var iteratorTest = item.GetCustomAttribute<UnityEngine.TestTools.UnityTestAttribute>(true);
|
||||
if (iteratorTest != null)
|
||||
{
|
||||
if (item.GetParameters().Length == 0 && item.ReturnType == typeof(IEnumerator))
|
||||
{
|
||||
var factory = (Func<IEnumerator>)Delegate.CreateDelegate(typeof(Func<IEnumerator>), test, item);
|
||||
AddAsyncTest(factory.Target.GetType().Name, factory.Method.Name, factory);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.Log(testType.Name + "." + item.Name + " currently does not supported in RuntumeUnitTestToolkit(multiple parameter or return type is invalid).");
|
||||
}
|
||||
}
|
||||
|
||||
var standardTest = item.GetCustomAttribute<NUnit.Framework.TestAttribute>(true);
|
||||
if (standardTest != null)
|
||||
{
|
||||
if (item.GetParameters().Length == 0 && item.ReturnType == typeof(void))
|
||||
{
|
||||
var invoke = (Action)Delegate.CreateDelegate(typeof(Action), test, item);
|
||||
AddTest(invoke.Target.GetType().Name, invoke.Method.Name, invoke);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.Log(testType.Name + "." + item.Name + " currently does not supported in RuntumeUnitTestToolkit(multiple parameter or return type is invalid).");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UnityEngine.Debug.LogError(testType.Name + "." + item.Name + " failed to register method, exception: " + e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator ScrollLogToEndNextFrame()
|
||||
{
|
||||
yield return null;
|
||||
yield return null;
|
||||
logScrollBar.value = 0;
|
||||
}
|
||||
|
||||
IEnumerator RunTestInCoroutine(KeyValuePair<string, List<KeyValuePair<string, object>>> actionList)
|
||||
{
|
||||
Button self = null;
|
||||
foreach (var btn in list.GetComponentsInChildren<Button>())
|
||||
{
|
||||
btn.interactable = false;
|
||||
if (btn.name == actionList.Key) self = btn;
|
||||
}
|
||||
if (self != null)
|
||||
{
|
||||
self.GetComponent<Image>().color = normalColor;
|
||||
}
|
||||
|
||||
var allGreen = true;
|
||||
|
||||
logText.text += "<color=yellow>" + actionList.Key + "</color>\n";
|
||||
WriteToConsole("Begin Test Class: " + actionList.Key);
|
||||
yield return null;
|
||||
|
||||
var totalExecutionTime = new List<double>();
|
||||
foreach (var item2 in actionList.Value)
|
||||
{
|
||||
// before start, cleanup
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
|
||||
logText.text += "<color=teal>" + item2.Key + "</color>\n";
|
||||
yield return null;
|
||||
|
||||
var v = item2.Value;
|
||||
|
||||
var methodStopwatch = System.Diagnostics.Stopwatch.StartNew();
|
||||
Exception exception = null;
|
||||
if (v is Action)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Action)v).Invoke();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var coroutineFactory = (Func<IEnumerator>)v;
|
||||
IEnumerator coroutine = null;
|
||||
try
|
||||
{
|
||||
coroutine = coroutineFactory();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
}
|
||||
if (exception == null)
|
||||
{
|
||||
yield return StartCoroutine(UnwrapEnumerator(coroutine, ex =>
|
||||
{
|
||||
exception = ex;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
methodStopwatch.Stop();
|
||||
totalExecutionTime.Add(methodStopwatch.Elapsed.TotalMilliseconds);
|
||||
if (exception == null)
|
||||
{
|
||||
logText.text += "OK, " + methodStopwatch.Elapsed.TotalMilliseconds.ToString("0.00") + "ms\n";
|
||||
WriteToConsoleResult(item2.Key + ", " + methodStopwatch.Elapsed.TotalMilliseconds.ToString("0.00") + "ms", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// found match line...
|
||||
var line = string.Join("\n", exception.StackTrace.Split('\n').Where(x => x.Contains(actionList.Key) || x.Contains(item2.Key)).ToArray());
|
||||
logText.text += "<color=red>" + exception.Message + "\n" + line + "</color>\n";
|
||||
WriteToConsoleResult(item2.Key + ", " + exception.Message, false);
|
||||
WriteToConsole(line);
|
||||
allGreen = false;
|
||||
allTestGreen = false;
|
||||
}
|
||||
}
|
||||
|
||||
logText.text += "[" + actionList.Key + "]" + totalExecutionTime.Sum().ToString("0.00") + "ms\n\n";
|
||||
foreach (var btn in list.GetComponentsInChildren<Button>()) btn.interactable = true;
|
||||
if (self != null)
|
||||
{
|
||||
self.GetComponent<Image>().color = allGreen ? passColor : failColor;
|
||||
}
|
||||
|
||||
yield return StartCoroutine(ScrollLogToEndNextFrame());
|
||||
|
||||
|
||||
}
|
||||
|
||||
IEnumerator ExecuteAllInCoroutine(List<Func<Coroutine>> tests)
|
||||
{
|
||||
allTestGreen = true;
|
||||
|
||||
foreach (var item in tests)
|
||||
{
|
||||
yield return item();
|
||||
}
|
||||
|
||||
if (Application.isBatchMode)
|
||||
{
|
||||
var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
|
||||
bool disableAutoClose = (scene.name.Contains("DisableAutoClose"));
|
||||
|
||||
if (allTestGreen)
|
||||
{
|
||||
WriteToConsole("Test Complete Successfully");
|
||||
if (!disableAutoClose)
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteToConsole("Test Failed, please see [NG] log.");
|
||||
if (!disableAutoClose)
|
||||
{
|
||||
Application.Quit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator UnwrapEnumerator(IEnumerator enumerator, Action<Exception> exceptionCallback)
|
||||
{
|
||||
var hasNext = true;
|
||||
while (hasNext)
|
||||
{
|
||||
try
|
||||
{
|
||||
hasNext = enumerator.MoveNext();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exceptionCallback(ex);
|
||||
hasNext = false;
|
||||
}
|
||||
|
||||
if (hasNext)
|
||||
{
|
||||
// unwrap self for bug of Unity
|
||||
// https://issuetracker.unity3d.com/issues/does-not-stop-coroutine-when-it-throws-exception-in-movenext-at-first-frame
|
||||
var moreCoroutine = enumerator.Current as IEnumerator;
|
||||
if (moreCoroutine != null)
|
||||
{
|
||||
yield return StartCoroutine(UnwrapEnumerator(moreCoroutine, ex =>
|
||||
{
|
||||
exceptionCallback(ex);
|
||||
hasNext = false;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return enumerator.Current;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteToConsole(string msg)
|
||||
{
|
||||
if (Application.isBatchMode)
|
||||
{
|
||||
Console.WriteLine(msg);
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteToConsoleResult(string msg, bool green)
|
||||
{
|
||||
if (Application.isBatchMode)
|
||||
{
|
||||
if (!green)
|
||||
{
|
||||
var currentForeground = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.Write("[NG]");
|
||||
Console.ForegroundColor = currentForeground;
|
||||
}
|
||||
else
|
||||
{
|
||||
var currentForeground = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.Write("[OK]");
|
||||
Console.ForegroundColor = currentForeground;
|
||||
}
|
||||
|
||||
System.Console.WriteLine(msg);
|
||||
}
|
||||
}
|
||||
|
||||
struct Pair
|
||||
{
|
||||
public string Name;
|
||||
public UnityAction Action;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UniRx.Async;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SandboxMain : MonoBehaviour
|
||||
{
|
||||
public Button okButton;
|
||||
public Button cancelButton;
|
||||
CancellationTokenSource cts;
|
||||
|
||||
async void Start()
|
||||
{
|
||||
await UniTask.CompletedTask; // ok
|
||||
|
||||
// var subject = new Subject<Unit>();
|
||||
//subject.OnCompleted();
|
||||
IObservable<AsyncUnit> subject = default;
|
||||
try
|
||||
{
|
||||
await subject.ToUniTask(); // exception
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.Log(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace UniRx.Async.CompilerServices
|
||||
{
|
||||
internal class MoveNextRunner<TStateMachine>
|
||||
where TStateMachine : IAsyncStateMachine
|
||||
{
|
||||
public TStateMachine StateMachine;
|
||||
|
||||
[DebuggerHidden]
|
||||
public void Run()
|
||||
{
|
||||
StateMachine.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,64 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public enum AwaiterStatus
|
||||
{
|
||||
/// <summary>The operation has not yet completed.</summary>
|
||||
Pending = 0,
|
||||
/// <summary>The operation completed successfully.</summary>
|
||||
Succeeded = 1,
|
||||
/// <summary>The operation completed with an error.</summary>
|
||||
Faulted = 2,
|
||||
/// <summary>The operation completed due to cancellation.</summary>
|
||||
Canceled = 3
|
||||
}
|
||||
|
||||
public interface IAwaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
AwaiterStatus Status { get; }
|
||||
bool IsCompleted { get; }
|
||||
void GetResult();
|
||||
}
|
||||
|
||||
public interface IAwaiter<out T> : IAwaiter
|
||||
{
|
||||
new T GetResult();
|
||||
}
|
||||
|
||||
public static class AwaiterStatusExtensions
|
||||
{
|
||||
/// <summary>!= Pending.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsCompleted(this AwaiterStatus status)
|
||||
{
|
||||
return status != AwaiterStatus.Pending;
|
||||
}
|
||||
|
||||
/// <summary>== Succeeded.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsCompletedSuccessfully(this AwaiterStatus status)
|
||||
{
|
||||
return status == AwaiterStatus.Succeeded;
|
||||
}
|
||||
|
||||
/// <summary>== Canceled.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsCanceled(this AwaiterStatus status)
|
||||
{
|
||||
return status == AwaiterStatus.Canceled;
|
||||
}
|
||||
|
||||
/// <summary>== Faulted.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsFaulted(this AwaiterStatus status)
|
||||
{
|
||||
return status == AwaiterStatus.Faulted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,32 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Threading;
|
||||
|
||||
namespace UniRx.Async.Internal
|
||||
{
|
||||
internal static class CancellationTokenHelper
|
||||
{
|
||||
public static bool TrySetOrLinkCancellationToken(ref CancellationToken field, CancellationToken newCancellationToken)
|
||||
{
|
||||
if (newCancellationToken == CancellationToken.None)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (field == CancellationToken.None)
|
||||
{
|
||||
field = newCancellationToken;
|
||||
return true;
|
||||
}
|
||||
else if (field == newCancellationToken)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
field = CancellationTokenSource.CreateLinkedTokenSource(field, newCancellationToken).Token;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,130 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace UniRx.Async.Internal
|
||||
{
|
||||
internal sealed class LazyPromise : IAwaiter
|
||||
{
|
||||
Func<UniTask> factory;
|
||||
UniTask value;
|
||||
|
||||
public LazyPromise(Func<UniTask> factory)
|
||||
{
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
void Create()
|
||||
{
|
||||
var f = Interlocked.Exchange(ref factory, null);
|
||||
if (f != null)
|
||||
{
|
||||
value = f();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
Create();
|
||||
return value.IsCompleted;
|
||||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
Create();
|
||||
return value.Status;
|
||||
}
|
||||
}
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
Create();
|
||||
value.GetResult();
|
||||
}
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
GetResult();
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Create();
|
||||
value.GetAwaiter().UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class LazyPromise<T> : IAwaiter<T>
|
||||
{
|
||||
Func<UniTask<T>> factory;
|
||||
UniTask<T> value;
|
||||
|
||||
public LazyPromise(Func<UniTask<T>> factory)
|
||||
{
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
void Create()
|
||||
{
|
||||
var f = Interlocked.Exchange(ref factory, null);
|
||||
if (f != null)
|
||||
{
|
||||
value = f();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
Create();
|
||||
return value.IsCompleted;
|
||||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
Create();
|
||||
return value.Status;
|
||||
}
|
||||
}
|
||||
|
||||
public T GetResult()
|
||||
{
|
||||
Create();
|
||||
return value.Result;
|
||||
}
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
GetResult();
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Create();
|
||||
value.GetAwaiter().UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,34 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniRx.Async.Internal
|
||||
{
|
||||
internal static class PromiseHelper
|
||||
{
|
||||
internal static void TrySetResultAll<TPromise, T>(IEnumerable<TPromise> source, T value)
|
||||
where TPromise : class, IResolvePromise<T>
|
||||
{
|
||||
var rentArray = ArrayPoolUtil.Materialize(source);
|
||||
var clearArray = true;
|
||||
try
|
||||
{
|
||||
var array = rentArray.Array;
|
||||
var len = rentArray.Length;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
array[i].TrySetResult(value);
|
||||
array[i] = null;
|
||||
}
|
||||
clearArray = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
rentArray.DisposeManually(clearArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,395 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace UniRx.Async.Internal
|
||||
{
|
||||
// public for some types uses it.
|
||||
|
||||
public abstract class ReusablePromise : IAwaiter
|
||||
{
|
||||
ExceptionDispatchInfo exception;
|
||||
object continuation; // Action or Queue<Action>
|
||||
AwaiterStatus status;
|
||||
|
||||
public UniTask Task => new UniTask(this);
|
||||
|
||||
// can override for control 'start/reset' timing.
|
||||
public virtual bool IsCompleted => status.IsCompleted();
|
||||
|
||||
public virtual void GetResult()
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case AwaiterStatus.Succeeded:
|
||||
return;
|
||||
case AwaiterStatus.Faulted:
|
||||
exception.Throw();
|
||||
break;
|
||||
case AwaiterStatus.Canceled:
|
||||
throw new OperationCanceledException();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Invalid Status:" + status);
|
||||
}
|
||||
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
GetResult();
|
||||
}
|
||||
|
||||
public void ResetStatus(bool forceReset)
|
||||
{
|
||||
if (forceReset)
|
||||
{
|
||||
status = AwaiterStatus.Pending;
|
||||
}
|
||||
else if (status == AwaiterStatus.Succeeded)
|
||||
{
|
||||
status = AwaiterStatus.Pending;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool TrySetCanceled()
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Canceled;
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TrySetException(Exception ex)
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Faulted;
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TrySetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TryInvokeContinuation()
|
||||
{
|
||||
if (continuation == null) return;
|
||||
|
||||
if (continuation is Action act)
|
||||
{
|
||||
continuation = null;
|
||||
act();
|
||||
}
|
||||
else
|
||||
{
|
||||
// reuse Queue(don't null clear)
|
||||
var q = (MinimumQueue<Action>)continuation;
|
||||
var size = q.Count;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
q.Dequeue().Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCompleted(Action action)
|
||||
{
|
||||
UnsafeOnCompleted(action);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action action)
|
||||
{
|
||||
if (continuation == null)
|
||||
{
|
||||
continuation = action;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (continuation is Action act)
|
||||
{
|
||||
var q = new MinimumQueue<Action>(4);
|
||||
q.Enqueue(act);
|
||||
q.Enqueue(action);
|
||||
continuation = q;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
((MinimumQueue<Action>)continuation).Enqueue(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class ReusablePromise<T> : IAwaiter<T>
|
||||
{
|
||||
T result;
|
||||
ExceptionDispatchInfo exception;
|
||||
object continuation; // Action or Queue<Action>
|
||||
AwaiterStatus status;
|
||||
|
||||
public UniTask<T> Task => new UniTask<T>(this);
|
||||
|
||||
// can override for control 'start/reset' timing.
|
||||
public virtual bool IsCompleted => status.IsCompleted();
|
||||
|
||||
protected T RawResult => result;
|
||||
|
||||
protected void ForceSetResult(T result)
|
||||
{
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public virtual T GetResult()
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case AwaiterStatus.Succeeded:
|
||||
return result;
|
||||
case AwaiterStatus.Faulted:
|
||||
exception.Throw();
|
||||
break;
|
||||
case AwaiterStatus.Canceled:
|
||||
throw new OperationCanceledException();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Invalid Status:" + status);
|
||||
}
|
||||
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
GetResult();
|
||||
}
|
||||
|
||||
public void ResetStatus(bool forceReset)
|
||||
{
|
||||
if (forceReset)
|
||||
{
|
||||
status = AwaiterStatus.Pending;
|
||||
}
|
||||
else if (status == AwaiterStatus.Succeeded)
|
||||
{
|
||||
status = AwaiterStatus.Pending;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool TrySetCanceled()
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Canceled;
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TrySetException(Exception ex)
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Faulted;
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TrySetResult(T result)
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
this.result = result;
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void TryInvokeContinuation()
|
||||
{
|
||||
if (continuation == null) return;
|
||||
|
||||
if (continuation is Action act)
|
||||
{
|
||||
continuation = null;
|
||||
act();
|
||||
}
|
||||
else
|
||||
{
|
||||
// reuse Queue(don't null clear)
|
||||
var q = (MinimumQueue<Action>)continuation;
|
||||
var size = q.Count;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
q.Dequeue().Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCompleted(Action action)
|
||||
{
|
||||
UnsafeOnCompleted(action);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action action)
|
||||
{
|
||||
if (continuation == null)
|
||||
{
|
||||
continuation = action;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (continuation is Action act)
|
||||
{
|
||||
var q = new MinimumQueue<Action>(4);
|
||||
q.Enqueue(act);
|
||||
q.Enqueue(action);
|
||||
continuation = q;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
((MinimumQueue<Action>)continuation).Enqueue(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class PlayerLoopReusablePromiseBase : ReusablePromise, IPlayerLoopItem
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
protected readonly CancellationToken cancellationToken;
|
||||
bool isRunning = false;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
string capturedStackTraceForDebugging;
|
||||
#endif
|
||||
|
||||
public PlayerLoopReusablePromiseBase(PlayerLoopTiming timing, CancellationToken cancellationToken, int skipTrackFrameCountAdditive)
|
||||
{
|
||||
this.timing = timing;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
this.capturedStackTraceForDebugging = TaskTracker.CaptureStackTrace(skipTrackFrameCountAdditive + 1); // 1 is self,
|
||||
#endif
|
||||
}
|
||||
|
||||
public override bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Status == AwaiterStatus.Canceled || Status == AwaiterStatus.Faulted) return true;
|
||||
|
||||
if (!isRunning)
|
||||
{
|
||||
isRunning = true;
|
||||
ResetStatus(false);
|
||||
OnRunningStart();
|
||||
#if UNITY_EDITOR
|
||||
TaskTracker.TrackActiveTask(this, capturedStackTraceForDebugging);
|
||||
#endif
|
||||
PlayerLoopHelper.AddAction(timing, this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void OnRunningStart();
|
||||
|
||||
protected void Complete()
|
||||
{
|
||||
isRunning = false;
|
||||
#if UNITY_EDITOR
|
||||
TaskTracker.RemoveTracking(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
public abstract bool MoveNext();
|
||||
}
|
||||
|
||||
public abstract class PlayerLoopReusablePromiseBase<T> : ReusablePromise<T>, IPlayerLoopItem
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
protected readonly CancellationToken cancellationToken;
|
||||
bool isRunning = false;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
string capturedStackTraceForDebugging;
|
||||
#endif
|
||||
|
||||
public PlayerLoopReusablePromiseBase(PlayerLoopTiming timing, CancellationToken cancellationToken, int skipTrackFrameCountAdditive)
|
||||
{
|
||||
this.timing = timing;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
this.capturedStackTraceForDebugging = TaskTracker.CaptureStackTrace(skipTrackFrameCountAdditive + 1); // 1 is self,
|
||||
#endif
|
||||
}
|
||||
|
||||
public override bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Status == AwaiterStatus.Canceled || Status == AwaiterStatus.Faulted) return true;
|
||||
|
||||
if (!isRunning)
|
||||
{
|
||||
isRunning = true;
|
||||
ResetStatus(false);
|
||||
OnRunningStart();
|
||||
#if UNITY_EDITOR
|
||||
TaskTracker.TrackActiveTask(this, capturedStackTraceForDebugging);
|
||||
#endif
|
||||
PlayerLoopHelper.AddAction(timing, this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void OnRunningStart();
|
||||
|
||||
protected void Complete()
|
||||
{
|
||||
isRunning = false;
|
||||
#if UNITY_EDITOR
|
||||
TaskTracker.RemoveTracking(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
public abstract bool MoveNext();
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,156 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UniRx.Async.Internal;
|
||||
using System.Threading;
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
using UnityEngine.LowLevel;
|
||||
#else
|
||||
using UnityEngine.Experimental.LowLevel;
|
||||
#endif
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public static class UniTaskLoopRunners
|
||||
{
|
||||
public struct UniTaskLoopRunnerInitialization { };
|
||||
public struct UniTaskLoopRunnerEarlyUpdate { };
|
||||
public struct UniTaskLoopRunnerFixedUpdate { };
|
||||
public struct UniTaskLoopRunnerPreUpdate { };
|
||||
public struct UniTaskLoopRunnerUpdate { };
|
||||
public struct UniTaskLoopRunnerPreLateUpdate { };
|
||||
public struct UniTaskLoopRunnerPostLateUpdate { };
|
||||
|
||||
// Yield
|
||||
|
||||
public struct UniTaskLoopRunnerYieldInitialization { };
|
||||
public struct UniTaskLoopRunnerYieldEarlyUpdate { };
|
||||
public struct UniTaskLoopRunnerYieldFixedUpdate { };
|
||||
public struct UniTaskLoopRunnerYieldPreUpdate { };
|
||||
public struct UniTaskLoopRunnerYieldUpdate { };
|
||||
public struct UniTaskLoopRunnerYieldPreLateUpdate { };
|
||||
public struct UniTaskLoopRunnerYieldPostLateUpdate { };
|
||||
}
|
||||
|
||||
public enum PlayerLoopTiming
|
||||
{
|
||||
Initialization = 0,
|
||||
EarlyUpdate = 1,
|
||||
FixedUpdate = 2,
|
||||
PreUpdate = 3,
|
||||
Update = 4,
|
||||
PreLateUpdate = 5,
|
||||
PostLateUpdate = 6
|
||||
}
|
||||
|
||||
public interface IPlayerLoopItem
|
||||
{
|
||||
bool MoveNext();
|
||||
}
|
||||
|
||||
public static class PlayerLoopHelper
|
||||
{
|
||||
public static SynchronizationContext UnitySynchronizationContext => unitySynchronizationContetext;
|
||||
public static int MainThreadId => mainThreadId;
|
||||
|
||||
static int mainThreadId;
|
||||
static SynchronizationContext unitySynchronizationContetext;
|
||||
static ContinuationQueue[] yielders;
|
||||
static PlayerLoopRunner[] runners;
|
||||
|
||||
static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem, Type loopRunnerYieldType, ContinuationQueue cq, Type loopRunnerType, PlayerLoopRunner runner)
|
||||
{
|
||||
var yieldLoop = new PlayerLoopSystem
|
||||
{
|
||||
type = loopRunnerYieldType,
|
||||
#if UNITY_EDITOR
|
||||
updateDelegate = () =>
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
cq.Run();
|
||||
}
|
||||
}
|
||||
#else
|
||||
updateDelegate = cq.Run
|
||||
#endif
|
||||
};
|
||||
|
||||
var runnerLoop = new PlayerLoopSystem
|
||||
{
|
||||
type = loopRunnerType,
|
||||
#if UNITY_EDITOR
|
||||
updateDelegate = () =>
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
runner.Run();
|
||||
}
|
||||
}
|
||||
#else
|
||||
updateDelegate = runner.Run
|
||||
#endif
|
||||
};
|
||||
|
||||
var dest = new PlayerLoopSystem[loopSystem.subSystemList.Length + 2];
|
||||
Array.Copy(loopSystem.subSystemList, 0, dest, 2, loopSystem.subSystemList.Length);
|
||||
dest[0] = yieldLoop;
|
||||
dest[1] = runnerLoop;
|
||||
return dest;
|
||||
}
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
static void Init()
|
||||
{
|
||||
// capture default(unity) sync-context.
|
||||
unitySynchronizationContetext = SynchronizationContext.Current;
|
||||
mainThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
|
||||
if (runners != null) return; // already initialized
|
||||
|
||||
var playerLoop =
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
PlayerLoop.GetCurrentPlayerLoop();
|
||||
#else
|
||||
PlayerLoop.GetDefaultPlayerLoop();
|
||||
#endif
|
||||
|
||||
Initialize(ref playerLoop);
|
||||
}
|
||||
|
||||
public static void Initialize(ref PlayerLoopSystem playerLoop)
|
||||
{
|
||||
yielders = new ContinuationQueue[7];
|
||||
runners = new PlayerLoopRunner[7];
|
||||
|
||||
var copyList = playerLoop.subSystemList.ToArray();
|
||||
|
||||
copyList[0].subSystemList = InsertRunner(copyList[0], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldInitialization), yielders[0] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerInitialization), runners[0] = new PlayerLoopRunner());
|
||||
copyList[1].subSystemList = InsertRunner(copyList[1], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldEarlyUpdate), yielders[1] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerEarlyUpdate), runners[1] = new PlayerLoopRunner());
|
||||
copyList[2].subSystemList = InsertRunner(copyList[2], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldFixedUpdate), yielders[2] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerFixedUpdate), runners[2] = new PlayerLoopRunner());
|
||||
copyList[3].subSystemList = InsertRunner(copyList[3], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreUpdate), yielders[3] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreUpdate), runners[3] = new PlayerLoopRunner());
|
||||
copyList[4].subSystemList = InsertRunner(copyList[4], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldUpdate), yielders[4] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerUpdate), runners[4] = new PlayerLoopRunner());
|
||||
copyList[5].subSystemList = InsertRunner(copyList[5], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreLateUpdate), yielders[5] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreLateUpdate), runners[5] = new PlayerLoopRunner());
|
||||
copyList[6].subSystemList = InsertRunner(copyList[6], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPostLateUpdate), yielders[6] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPostLateUpdate), runners[6] = new PlayerLoopRunner());
|
||||
|
||||
playerLoop.subSystemList = copyList;
|
||||
PlayerLoop.SetPlayerLoop(playerLoop);
|
||||
}
|
||||
|
||||
public static void AddAction(PlayerLoopTiming timing, IPlayerLoopItem action)
|
||||
{
|
||||
runners[(int)timing].AddAction(action);
|
||||
}
|
||||
|
||||
public static void AddContinuation(PlayerLoopTiming timing, Action continuation)
|
||||
{
|
||||
yielders[(int)timing].Enqueue(continuation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,54 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncAnimatorTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<int> onAnimatorIK;
|
||||
AsyncTriggerPromiseDictionary<int> onAnimatorIKs;
|
||||
AsyncTriggerPromise<AsyncUnit> onAnimatorMove;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onAnimatorMoves;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onAnimatorIK, onAnimatorIKs, onAnimatorMove, onAnimatorMoves);
|
||||
}
|
||||
|
||||
|
||||
void OnAnimatorIK(int layerIndex)
|
||||
{
|
||||
TrySetResult(onAnimatorIK, onAnimatorIKs, layerIndex);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<int> OnAnimatorIKAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onAnimatorIK, ref onAnimatorIKs, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnAnimatorMove()
|
||||
{
|
||||
TrySetResult(onAnimatorMove, onAnimatorMoves, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnAnimatorMoveAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onAnimatorMove, ref onAnimatorMoves, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae912c37ac7f4cd42b25f22452435103
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncAwakeTrigger : MonoBehaviour
|
||||
{
|
||||
bool called = false;
|
||||
UniTaskCompletionSource promise;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
called = true;
|
||||
promise?.TrySetResult();
|
||||
}
|
||||
|
||||
public UniTask AwakeAsync()
|
||||
{
|
||||
if (called) return UniTask.CompletedTask;
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this));
|
||||
return new UniTask(promise ?? (promise = new UniTaskCompletionSource()));
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
promise?.TrySetCanceled();
|
||||
}
|
||||
|
||||
class AwakeMonitor : IPlayerLoopItem
|
||||
{
|
||||
readonly AsyncAwakeTrigger trigger;
|
||||
|
||||
public AwakeMonitor(AsyncAwakeTrigger trigger)
|
||||
{
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (trigger.called) return false;
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger.OnDestroy();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncBeginDragTrigger : AsyncTriggerBase, IBeginDragHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onBeginDrag;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onBeginDrags;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onBeginDrag, onBeginDrags);
|
||||
}
|
||||
|
||||
|
||||
void IBeginDragHandler.OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onBeginDrag, onBeginDrags, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnBeginDragAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onBeginDrag, ref onBeginDrags, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 171fd2191eb22af4fbd92b51815ca757
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncCancelTrigger : AsyncTriggerBase, ICancelHandler
|
||||
{
|
||||
AsyncTriggerPromise<BaseEventData> onCancel;
|
||||
AsyncTriggerPromiseDictionary<BaseEventData> onCancels;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onCancel, onCancels);
|
||||
}
|
||||
|
||||
|
||||
void ICancelHandler.OnCancel(BaseEventData eventData)
|
||||
{
|
||||
TrySetResult(onCancel, onCancels, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<BaseEventData> OnCancelAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onCancel, ref onCancels, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 291886b6e5f2d044a85b2a4dedcaca97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncCanvasGroupChangedTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<AsyncUnit> onCanvasGroupChanged;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onCanvasGroupChangeds;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onCanvasGroupChanged, onCanvasGroupChangeds);
|
||||
}
|
||||
|
||||
|
||||
void OnCanvasGroupChanged()
|
||||
{
|
||||
TrySetResult(onCanvasGroupChanged, onCanvasGroupChangeds, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnCanvasGroupChangedAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onCanvasGroupChanged, ref onCanvasGroupChangeds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eddba832648f83046a320ffcacfc771d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,69 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncCollision2DTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<Collision2D> onCollisionEnter2D;
|
||||
AsyncTriggerPromiseDictionary<Collision2D> onCollisionEnter2Ds;
|
||||
AsyncTriggerPromise<Collision2D> onCollisionExit2D;
|
||||
AsyncTriggerPromiseDictionary<Collision2D> onCollisionExit2Ds;
|
||||
AsyncTriggerPromise<Collision2D> onCollisionStay2D;
|
||||
AsyncTriggerPromiseDictionary<Collision2D> onCollisionStay2Ds;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onCollisionEnter2D, onCollisionEnter2Ds, onCollisionExit2D, onCollisionExit2Ds, onCollisionStay2D, onCollisionStay2Ds);
|
||||
}
|
||||
|
||||
|
||||
void OnCollisionEnter2D(Collision2D coll)
|
||||
{
|
||||
TrySetResult(onCollisionEnter2D, onCollisionEnter2Ds, coll);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collision2D> OnCollisionEnter2DAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onCollisionEnter2D, ref onCollisionEnter2Ds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnCollisionExit2D(Collision2D coll)
|
||||
{
|
||||
TrySetResult(onCollisionExit2D, onCollisionExit2Ds, coll);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collision2D> OnCollisionExit2DAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onCollisionExit2D, ref onCollisionExit2Ds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnCollisionStay2D(Collision2D coll)
|
||||
{
|
||||
TrySetResult(onCollisionStay2D, onCollisionStay2Ds, coll);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collision2D> OnCollisionStay2DAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onCollisionStay2D, ref onCollisionStay2Ds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fbeb63f69bedec44f8003730887f914b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,69 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncCollisionTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<Collision> onCollisionEnter;
|
||||
AsyncTriggerPromiseDictionary<Collision> onCollisionEnters;
|
||||
AsyncTriggerPromise<Collision> onCollisionExit;
|
||||
AsyncTriggerPromiseDictionary<Collision> onCollisionExits;
|
||||
AsyncTriggerPromise<Collision> onCollisionStay;
|
||||
AsyncTriggerPromiseDictionary<Collision> onCollisionStays;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onCollisionEnter, onCollisionEnters, onCollisionExit, onCollisionExits, onCollisionStay, onCollisionStays);
|
||||
}
|
||||
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
TrySetResult(onCollisionEnter, onCollisionEnters, collision);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collision> OnCollisionEnterAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onCollisionEnter, ref onCollisionEnters, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnCollisionExit(Collision collisionInfo)
|
||||
{
|
||||
TrySetResult(onCollisionExit, onCollisionExits, collisionInfo);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collision> OnCollisionExitAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onCollisionExit, ref onCollisionExits, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnCollisionStay(Collision collisionInfo)
|
||||
{
|
||||
TrySetResult(onCollisionStay, onCollisionStays, collisionInfo);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collision> OnCollisionStayAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onCollisionStay, ref onCollisionStays, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72db4a683be8f6a428823502599014a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncDeselectTrigger : AsyncTriggerBase, IDeselectHandler
|
||||
{
|
||||
AsyncTriggerPromise<BaseEventData> onDeselect;
|
||||
AsyncTriggerPromiseDictionary<BaseEventData> onDeselects;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onDeselect, onDeselects);
|
||||
}
|
||||
|
||||
|
||||
void IDeselectHandler.OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
TrySetResult(onDeselect, onDeselects, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<BaseEventData> OnDeselectAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onDeselect, ref onDeselects, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30faa9be5bd883e488bdc52f4825c4da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,93 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Threading;
|
||||
using UniRx.Async.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncDestroyTrigger : MonoBehaviour
|
||||
{
|
||||
bool called = false;
|
||||
UniTaskCompletionSource promise;
|
||||
CancellationTokenSource cancellationTokenSource; // main cancellation
|
||||
object canellationTokenSourceOrQueue; // external from AddCancellationTriggerOnDestory
|
||||
|
||||
public CancellationToken CancellationToken
|
||||
{
|
||||
get
|
||||
{
|
||||
if (cancellationTokenSource == null)
|
||||
{
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
return cancellationTokenSource.Token;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>This function is called when the MonoBehaviour will be destroyed.</summary>
|
||||
void OnDestroy()
|
||||
{
|
||||
called = true;
|
||||
promise?.TrySetResult();
|
||||
cancellationTokenSource?.Cancel();
|
||||
cancellationTokenSource?.Dispose();
|
||||
if (canellationTokenSourceOrQueue != null)
|
||||
{
|
||||
if (canellationTokenSourceOrQueue is CancellationTokenSource cts)
|
||||
{
|
||||
cts.Cancel();
|
||||
cts.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
var q = (MinimumQueue<CancellationTokenSource>)canellationTokenSourceOrQueue;
|
||||
while (q.Count != 0)
|
||||
{
|
||||
var c = q.Dequeue();
|
||||
c.Cancel();
|
||||
c.Dispose();
|
||||
}
|
||||
}
|
||||
canellationTokenSourceOrQueue = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>This function is called when the MonoBehaviour will be destroyed.</summary>
|
||||
public UniTask OnDestroyAsync()
|
||||
{
|
||||
if (called) return UniTask.CompletedTask;
|
||||
return new UniTask(promise ?? (promise = new UniTaskCompletionSource()));
|
||||
}
|
||||
|
||||
/// <summary>Add Cancellation Triggers on destroy</summary>
|
||||
public void AddCancellationTriggerOnDestory(CancellationTokenSource cts)
|
||||
{
|
||||
if (called)
|
||||
{
|
||||
cts.Cancel();
|
||||
cts.Dispose();
|
||||
}
|
||||
|
||||
if (canellationTokenSourceOrQueue == null)
|
||||
{
|
||||
canellationTokenSourceOrQueue = cts;
|
||||
}
|
||||
else if (canellationTokenSourceOrQueue is CancellationTokenSource c)
|
||||
{
|
||||
var q = new MinimumQueue<CancellationTokenSource>(4);
|
||||
q.Enqueue(c);
|
||||
q.Enqueue(cts);
|
||||
canellationTokenSourceOrQueue = q;
|
||||
}
|
||||
else
|
||||
{
|
||||
((MinimumQueue<CancellationTokenSource>)canellationTokenSourceOrQueue).Enqueue(cts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncDragTrigger : AsyncTriggerBase, IDragHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onDrag;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onDrags;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onDrag, onDrags);
|
||||
}
|
||||
|
||||
|
||||
void IDragHandler.OnDrag(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onDrag, onDrags, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnDragAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onDrag, ref onDrags, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52242547ba60ea74f8a2e3bbab5fcdfa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncDropTrigger : AsyncTriggerBase, IDropHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onDrop;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onDrops;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onDrop, onDrops);
|
||||
}
|
||||
|
||||
|
||||
void IDropHandler.OnDrop(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onDrop, onDrops, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnDropAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onDrop, ref onDrops, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42d65fd5e4be25f41a927eca25b0acf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncEnableDisableTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<AsyncUnit> onEnable;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onEnables;
|
||||
AsyncTriggerPromise<AsyncUnit> onDisable;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onDisables;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onEnable, onEnables, onDisable, onDisables);
|
||||
}
|
||||
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
TrySetResult(onEnable, onEnables, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnEnableAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onEnable, ref onEnables, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
TrySetResult(onDisable, onDisables, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnDisableAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onDisable, ref onDisables, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0bf9142b63b4cb43b693f0b83b3dbe7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncEndDragTrigger : AsyncTriggerBase, IEndDragHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onEndDrag;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onEndDrags;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onEndDrag, onEndDrags);
|
||||
}
|
||||
|
||||
|
||||
void IEndDragHandler.OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onEndDrag, onEndDrags, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnEndDragAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onEndDrag, ref onEndDrags, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8298d43de348acc4aa4e7dbf30472dbf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,264 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncEventTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<BaseEventData> onDeselect;
|
||||
AsyncTriggerPromiseDictionary<BaseEventData> onDeselects;
|
||||
AsyncTriggerPromise<AxisEventData> onMove;
|
||||
AsyncTriggerPromiseDictionary<AxisEventData> onMoves;
|
||||
AsyncTriggerPromise<PointerEventData> onPointerDown;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerDowns;
|
||||
AsyncTriggerPromise<PointerEventData> onPointerEnter;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerEnters;
|
||||
AsyncTriggerPromise<PointerEventData> onPointerExit;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerExits;
|
||||
AsyncTriggerPromise<PointerEventData> onPointerUp;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerUps;
|
||||
AsyncTriggerPromise<BaseEventData> onSelect;
|
||||
AsyncTriggerPromiseDictionary<BaseEventData> onSelects;
|
||||
AsyncTriggerPromise<PointerEventData> onPointerClick;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerClicks;
|
||||
AsyncTriggerPromise<BaseEventData> onSubmit;
|
||||
AsyncTriggerPromiseDictionary<BaseEventData> onSubmits;
|
||||
AsyncTriggerPromise<PointerEventData> onDrag;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onDrags;
|
||||
AsyncTriggerPromise<PointerEventData> onBeginDrag;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onBeginDrags;
|
||||
AsyncTriggerPromise<PointerEventData> onEndDrag;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onEndDrags;
|
||||
AsyncTriggerPromise<PointerEventData> onDrop;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onDrops;
|
||||
AsyncTriggerPromise<BaseEventData> onUpdateSelected;
|
||||
AsyncTriggerPromiseDictionary<BaseEventData> onUpdateSelecteds;
|
||||
AsyncTriggerPromise<PointerEventData> onInitializePotentialDrag;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onInitializePotentialDrags;
|
||||
AsyncTriggerPromise<BaseEventData> onCancel;
|
||||
AsyncTriggerPromiseDictionary<BaseEventData> onCancels;
|
||||
AsyncTriggerPromise<PointerEventData> onScroll;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onScrolls;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onDeselect, onDeselects, onMove, onMoves, onPointerDown, onPointerDowns, onPointerEnter, onPointerEnters, onPointerExit, onPointerExits, onPointerUp, onPointerUps, onSelect, onSelects, onPointerClick, onPointerClicks, onSubmit, onSubmits, onDrag, onDrags, onBeginDrag, onBeginDrags, onEndDrag, onEndDrags, onDrop, onDrops, onUpdateSelected, onUpdateSelecteds, onInitializePotentialDrag, onInitializePotentialDrags, onCancel, onCancels, onScroll, onScrolls);
|
||||
}
|
||||
|
||||
void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
TrySetResult(onDeselect, onDeselects, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<BaseEventData> OnDeselectAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onDeselect, ref onDeselects, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnMove(AxisEventData eventData)
|
||||
{
|
||||
TrySetResult(onMove, onMoves, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<AxisEventData> OnMoveAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onMove, ref onMoves, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onPointerDown, onPointerDowns, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnPointerDownAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onPointerDown, ref onPointerDowns, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onPointerEnter, onPointerEnters, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnPointerEnterAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onPointerEnter, ref onPointerEnters, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onPointerExit, onPointerExits, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnPointerExitAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onPointerExit, ref onPointerExits, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onPointerUp, onPointerUps, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnPointerUpAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onPointerUp, ref onPointerUps, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
TrySetResult(onSelect, onSelects, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<BaseEventData> OnSelectAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onSelect, ref onSelects, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onPointerClick, onPointerClicks, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnPointerClickAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onPointerClick, ref onPointerClicks, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
TrySetResult(onSubmit, onSubmits, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<BaseEventData> OnSubmitAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onSubmit, ref onSubmits, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onDrag, onDrags, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnDragAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onDrag, ref onDrags, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onBeginDrag, onBeginDrags, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnBeginDragAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onBeginDrag, ref onBeginDrags, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onEndDrag, onEndDrags, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnEndDragAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onEndDrag, ref onEndDrags, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnDrop(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onDrop, onDrops, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnDropAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onDrop, ref onDrops, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnUpdateSelected(BaseEventData eventData)
|
||||
{
|
||||
TrySetResult(onUpdateSelected, onUpdateSelecteds, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<BaseEventData> OnUpdateSelectedAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onUpdateSelected, ref onUpdateSelecteds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnInitializePotentialDrag(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onInitializePotentialDrag, onInitializePotentialDrags, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnInitializePotentialDragAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onInitializePotentialDrag, ref onInitializePotentialDrags, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnCancel(BaseEventData eventData)
|
||||
{
|
||||
TrySetResult(onCancel, onCancels, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<BaseEventData> OnCancelAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onCancel, ref onCancels, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnScroll(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onScroll, onScrolls, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnScrollAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onScroll, ref onScrolls, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89997820797ad6d43b17971a8bd0d8fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncFixedUpdateTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<AsyncUnit> fixedUpdate;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> fixedUpdates;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(fixedUpdate, fixedUpdates);
|
||||
}
|
||||
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
TrySetResult(fixedUpdate, fixedUpdates, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask FixedUpdateAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref fixedUpdate, ref fixedUpdates, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c74b906c4294aaa4e900f6e7f8b36df6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncInitializePotentialDragTrigger : AsyncTriggerBase, IInitializePotentialDragHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onInitializePotentialDrag;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onInitializePotentialDrags;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onInitializePotentialDrag, onInitializePotentialDrags);
|
||||
}
|
||||
|
||||
|
||||
void IInitializePotentialDragHandler.OnInitializePotentialDrag(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onInitializePotentialDrag, onInitializePotentialDrags, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnInitializePotentialDragAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onInitializePotentialDrag, ref onInitializePotentialDrags, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae0733adc239a324f8b934ffb119abd8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncJointTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<float> onJointBreak;
|
||||
AsyncTriggerPromiseDictionary<float> onJointBreaks;
|
||||
AsyncTriggerPromise<Joint2D> onJointBreak2D;
|
||||
AsyncTriggerPromiseDictionary<Joint2D> onJointBreak2Ds;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onJointBreak, onJointBreaks, onJointBreak2D, onJointBreak2Ds);
|
||||
}
|
||||
|
||||
|
||||
void OnJointBreak(float breakForce)
|
||||
{
|
||||
TrySetResult(onJointBreak, onJointBreaks, breakForce);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<float> OnJointBreakAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onJointBreak, ref onJointBreaks, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnJointBreak2D(Joint2D brokenJoint)
|
||||
{
|
||||
TrySetResult(onJointBreak2D, onJointBreak2Ds, brokenJoint);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Joint2D> OnJointBreak2DAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onJointBreak2D, ref onJointBreak2Ds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04dc74e7b2368094f9153921804a1fb7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncLateUpdateTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<AsyncUnit> lateUpdate;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> lateUpdates;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(lateUpdate, lateUpdates);
|
||||
}
|
||||
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
TrySetResult(lateUpdate, lateUpdates, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask LateUpdateAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref lateUpdate, ref lateUpdates, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4fb2b4c09cb4ec4a82b934f2038eb36
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,129 +0,0 @@
|
||||
|
||||
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncMouseTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<AsyncUnit> onMouseDown;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onMouseDowns;
|
||||
AsyncTriggerPromise<AsyncUnit> onMouseDrag;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onMouseDrags;
|
||||
AsyncTriggerPromise<AsyncUnit> onMouseEnter;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onMouseEnters;
|
||||
AsyncTriggerPromise<AsyncUnit> onMouseExit;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onMouseExits;
|
||||
AsyncTriggerPromise<AsyncUnit> onMouseOver;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onMouseOvers;
|
||||
AsyncTriggerPromise<AsyncUnit> onMouseUp;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onMouseUps;
|
||||
AsyncTriggerPromise<AsyncUnit> onMouseUpAsButton;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onMouseUpAsButtons;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onMouseDown, onMouseDowns, onMouseDrag, onMouseDrags, onMouseEnter, onMouseEnters, onMouseExit, onMouseExits, onMouseOver, onMouseOvers, onMouseUp, onMouseUps, onMouseUpAsButton, onMouseUpAsButtons);
|
||||
}
|
||||
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
TrySetResult(onMouseDown, onMouseDowns, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnMouseDownAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onMouseDown, ref onMouseDowns, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnMouseDrag()
|
||||
{
|
||||
TrySetResult(onMouseDrag, onMouseDrags, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnMouseDragAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onMouseDrag, ref onMouseDrags, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnMouseEnter()
|
||||
{
|
||||
TrySetResult(onMouseEnter, onMouseEnters, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnMouseEnterAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onMouseEnter, ref onMouseEnters, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnMouseExit()
|
||||
{
|
||||
TrySetResult(onMouseExit, onMouseExits, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnMouseExitAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onMouseExit, ref onMouseExits, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnMouseOver()
|
||||
{
|
||||
TrySetResult(onMouseOver, onMouseOvers, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnMouseOverAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onMouseOver, ref onMouseOvers, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnMouseUp()
|
||||
{
|
||||
TrySetResult(onMouseUp, onMouseUps, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnMouseUpAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onMouseUp, ref onMouseUps, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnMouseUpAsButton()
|
||||
{
|
||||
TrySetResult(onMouseUpAsButton, onMouseUpAsButtons, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnMouseUpAsButtonAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onMouseUpAsButton, ref onMouseUpAsButtons, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57ad5120e9c4d424484c963791467272
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncMoveTrigger : AsyncTriggerBase, IMoveHandler
|
||||
{
|
||||
AsyncTriggerPromise<AxisEventData> onMove;
|
||||
AsyncTriggerPromiseDictionary<AxisEventData> onMoves;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onMove, onMoves);
|
||||
}
|
||||
|
||||
|
||||
void IMoveHandler.OnMove(AxisEventData eventData)
|
||||
{
|
||||
TrySetResult(onMove, onMoves, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<AxisEventData> OnMoveAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onMove, ref onMoves, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1699926e875c24d4aa34bc8817f96f0e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncParticleTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<GameObject> onParticleCollision;
|
||||
AsyncTriggerPromiseDictionary<GameObject> onParticleCollisions;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onParticleCollision, onParticleCollisions);
|
||||
}
|
||||
|
||||
|
||||
void OnParticleCollision(GameObject other)
|
||||
{
|
||||
TrySetResult(onParticleCollision, onParticleCollisions, other);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<GameObject> OnParticleCollisionAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onParticleCollision, ref onParticleCollisions, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27d3f2efd47fb1d4fb2e9130f97ea8aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncPointerClickTrigger : AsyncTriggerBase, IPointerClickHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onPointerClick;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerClicks;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onPointerClick, onPointerClicks);
|
||||
}
|
||||
|
||||
|
||||
void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onPointerClick, onPointerClicks, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnPointerClickAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onPointerClick, ref onPointerClicks, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f8865abf2db3d248b3730cdb18bb8b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncPointerDownTrigger : AsyncTriggerBase, IPointerDownHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onPointerDown;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerDowns;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onPointerDown, onPointerDowns);
|
||||
}
|
||||
|
||||
|
||||
void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onPointerDown, onPointerDowns, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnPointerDownAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onPointerDown, ref onPointerDowns, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c5132395605eaa498a7efedee5acdd7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncPointerEnterTrigger : AsyncTriggerBase, IPointerEnterHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onPointerEnter;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerEnters;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onPointerEnter, onPointerEnters);
|
||||
}
|
||||
|
||||
|
||||
void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onPointerEnter, onPointerEnters, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnPointerEnterAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onPointerEnter, ref onPointerEnters, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18887d476d48533498efd14224a2f651
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncPointerExitTrigger : AsyncTriggerBase, IPointerExitHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onPointerExit;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerExits;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onPointerExit, onPointerExits);
|
||||
}
|
||||
|
||||
|
||||
void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onPointerExit, onPointerExits, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnPointerExitAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onPointerExit, ref onPointerExits, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e3ed09876a11a84794795809ebee243
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncPointerUpTrigger : AsyncTriggerBase, IPointerUpHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onPointerUp;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onPointerUps;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onPointerUp, onPointerUps);
|
||||
}
|
||||
|
||||
|
||||
void IPointerUpHandler.OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onPointerUp, onPointerUps, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnPointerUpAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onPointerUp, ref onPointerUps, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a0493ea32f81314cbbaf2b635ba3167
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncRectTransformTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<AsyncUnit> onRectTransformDimensionsChange;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onRectTransformDimensionsChanges;
|
||||
AsyncTriggerPromise<AsyncUnit> onRectTransformRemoved;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onRectTransformRemoveds;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onRectTransformDimensionsChange, onRectTransformDimensionsChanges, onRectTransformRemoved, onRectTransformRemoveds);
|
||||
}
|
||||
|
||||
|
||||
void OnRectTransformDimensionsChange()
|
||||
{
|
||||
TrySetResult(onRectTransformDimensionsChange, onRectTransformDimensionsChanges, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnRectTransformDimensionsChangeAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onRectTransformDimensionsChange, ref onRectTransformDimensionsChanges, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnRectTransformRemoved()
|
||||
{
|
||||
TrySetResult(onRectTransformRemoved, onRectTransformRemoveds, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnRectTransformRemovedAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onRectTransformRemoved, ref onRectTransformRemoveds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfe3470221c66c84397c0783c62b24e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncScrollTrigger : AsyncTriggerBase, IScrollHandler
|
||||
{
|
||||
AsyncTriggerPromise<PointerEventData> onScroll;
|
||||
AsyncTriggerPromiseDictionary<PointerEventData> onScrolls;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onScroll, onScrolls);
|
||||
}
|
||||
|
||||
|
||||
void IScrollHandler.OnScroll(PointerEventData eventData)
|
||||
{
|
||||
TrySetResult(onScroll, onScrolls, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<PointerEventData> OnScrollAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onScroll, ref onScrolls, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c751e9d3deb97d4d8691a8a583c2afd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncSelectTrigger : AsyncTriggerBase, ISelectHandler
|
||||
{
|
||||
AsyncTriggerPromise<BaseEventData> onSelect;
|
||||
AsyncTriggerPromiseDictionary<BaseEventData> onSelects;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onSelect, onSelects);
|
||||
}
|
||||
|
||||
|
||||
void ISelectHandler.OnSelect(BaseEventData eventData)
|
||||
{
|
||||
TrySetResult(onSelect, onSelects, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<BaseEventData> OnSelectAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onSelect, ref onSelects, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcc2347251a4fc5498a03f0c17382920
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,64 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncStartTrigger : MonoBehaviour
|
||||
{
|
||||
bool awakeCalled = false;
|
||||
bool called = false;
|
||||
UniTaskCompletionSource promise;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
awakeCalled = true;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
called = true;
|
||||
promise?.TrySetResult();
|
||||
}
|
||||
|
||||
public UniTask StartAsync()
|
||||
{
|
||||
if (called) return UniTask.CompletedTask;
|
||||
if (!awakeCalled)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this));
|
||||
}
|
||||
return new UniTask(promise ?? (promise = new UniTaskCompletionSource()));
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
promise?.TrySetCanceled();
|
||||
}
|
||||
|
||||
class AwakeMonitor : IPlayerLoopItem
|
||||
{
|
||||
readonly AsyncStartTrigger trigger;
|
||||
|
||||
public AwakeMonitor(AsyncStartTrigger trigger)
|
||||
{
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (trigger.awakeCalled) return false;
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger.OnDestroy();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncSubmitTrigger : AsyncTriggerBase, ISubmitHandler
|
||||
{
|
||||
AsyncTriggerPromise<BaseEventData> onSubmit;
|
||||
AsyncTriggerPromiseDictionary<BaseEventData> onSubmits;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onSubmit, onSubmits);
|
||||
}
|
||||
|
||||
|
||||
void ISubmitHandler.OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
TrySetResult(onSubmit, onSubmits, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<BaseEventData> OnSubmitAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onSubmit, ref onSubmits, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97e85abc2d7ec0c44adfbe5ee971aad3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,69 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncTransformChangedTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<AsyncUnit> onBeforeTransformParentChanged;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onBeforeTransformParentChangeds;
|
||||
AsyncTriggerPromise<AsyncUnit> onTransformParentChanged;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onTransformParentChangeds;
|
||||
AsyncTriggerPromise<AsyncUnit> onTransformChildrenChanged;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onTransformChildrenChangeds;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onBeforeTransformParentChanged, onBeforeTransformParentChangeds, onTransformParentChanged, onTransformParentChangeds, onTransformChildrenChanged, onTransformChildrenChangeds);
|
||||
}
|
||||
|
||||
|
||||
void OnBeforeTransformParentChanged()
|
||||
{
|
||||
TrySetResult(onBeforeTransformParentChanged, onBeforeTransformParentChangeds, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnBeforeTransformParentChangedAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onBeforeTransformParentChanged, ref onBeforeTransformParentChangeds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnTransformParentChanged()
|
||||
{
|
||||
TrySetResult(onTransformParentChanged, onTransformParentChangeds, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnTransformParentChangedAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onTransformParentChanged, ref onTransformParentChangeds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnTransformChildrenChanged()
|
||||
{
|
||||
TrySetResult(onTransformChildrenChanged, onTransformChildrenChangeds, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnTransformChildrenChangedAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onTransformChildrenChanged, ref onTransformChildrenChangeds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 053f983cd760f5e4394be8fd657243c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,69 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncTrigger2DTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<Collider2D> onTriggerEnter2D;
|
||||
AsyncTriggerPromiseDictionary<Collider2D> onTriggerEnter2Ds;
|
||||
AsyncTriggerPromise<Collider2D> onTriggerExit2D;
|
||||
AsyncTriggerPromiseDictionary<Collider2D> onTriggerExit2Ds;
|
||||
AsyncTriggerPromise<Collider2D> onTriggerStay2D;
|
||||
AsyncTriggerPromiseDictionary<Collider2D> onTriggerStay2Ds;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onTriggerEnter2D, onTriggerEnter2Ds, onTriggerExit2D, onTriggerExit2Ds, onTriggerStay2D, onTriggerStay2Ds);
|
||||
}
|
||||
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
TrySetResult(onTriggerEnter2D, onTriggerEnter2Ds, other);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collider2D> OnTriggerEnter2DAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onTriggerEnter2D, ref onTriggerEnter2Ds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
TrySetResult(onTriggerExit2D, onTriggerExit2Ds, other);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collider2D> OnTriggerExit2DAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onTriggerExit2D, ref onTriggerExit2Ds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnTriggerStay2D(Collider2D other)
|
||||
{
|
||||
TrySetResult(onTriggerStay2D, onTriggerStay2Ds, other);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collider2D> OnTriggerStay2DAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onTriggerStay2D, ref onTriggerStay2Ds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 102f8eba36bc2a54e878e67aca9686e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,271 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UniRx.Async.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
public interface ICancelablePromise
|
||||
{
|
||||
CancellationToken RegisteredCancellationToken { get; }
|
||||
bool TrySetCanceled();
|
||||
}
|
||||
|
||||
public class AsyncTriggerPromise<T> : ReusablePromise<T>, IPromise<T>, ICancelablePromise
|
||||
{
|
||||
public CancellationToken RegisteredCancellationToken { get; private set; }
|
||||
|
||||
public AsyncTriggerPromise()
|
||||
: this(CancellationToken.None)
|
||||
{
|
||||
}
|
||||
|
||||
public AsyncTriggerPromise(CancellationToken cancellationToken)
|
||||
{
|
||||
this.RegisteredCancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this);
|
||||
}
|
||||
|
||||
public override T GetResult()
|
||||
{
|
||||
if (Status == AwaiterStatus.Pending) return RawResult;
|
||||
return base.GetResult();
|
||||
}
|
||||
|
||||
public override bool TrySetResult(T result)
|
||||
{
|
||||
if (Status == AwaiterStatus.Pending)
|
||||
{
|
||||
// keep status as Pending.
|
||||
this.ForceSetResult(result);
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TrySetCanceled()
|
||||
{
|
||||
if (Status == AwaiterStatus.Canceled) return false;
|
||||
TaskTracker.RemoveTracking(this);
|
||||
return base.TrySetCanceled();
|
||||
}
|
||||
}
|
||||
|
||||
public interface ICancellationTokenKeyDictionary
|
||||
{
|
||||
void Remove(CancellationToken token);
|
||||
}
|
||||
|
||||
public class AsyncTriggerPromiseDictionary<TPromiseType> :
|
||||
Dictionary<CancellationToken, AsyncTriggerPromise<TPromiseType>>,
|
||||
ICancellationTokenKeyDictionary,
|
||||
IEnumerable<ICancelablePromise>
|
||||
{
|
||||
public AsyncTriggerPromiseDictionary()
|
||||
: base(CancellationTokenEqualityComparer.Default)
|
||||
{
|
||||
}
|
||||
|
||||
IEnumerator<ICancelablePromise> IEnumerable<ICancelablePromise>.GetEnumerator()
|
||||
{
|
||||
return Values.GetEnumerator();
|
||||
}
|
||||
|
||||
void ICancellationTokenKeyDictionary.Remove(CancellationToken token)
|
||||
{
|
||||
this.Remove(token);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class AsyncTriggerBase : MonoBehaviour
|
||||
{
|
||||
static readonly Action<object> Callback = CancelCallback;
|
||||
|
||||
bool calledAwake = false;
|
||||
bool destroyCalled = false;
|
||||
CancellationTokenRegistration[] registeredCancellations;
|
||||
int registeredCancellationsCount;
|
||||
|
||||
protected abstract IEnumerable<ICancelablePromise> GetPromises();
|
||||
|
||||
static protected IEnumerable<ICancelablePromise> Concat(ICancelablePromise p1, IEnumerable<ICancelablePromise> p1s)
|
||||
{
|
||||
if (p1 != null) yield return p1;
|
||||
if (p1s != null) foreach (var item in p1s) yield return item;
|
||||
}
|
||||
|
||||
static protected IEnumerable<ICancelablePromise> Concat(
|
||||
ICancelablePromise p1, IEnumerable<ICancelablePromise> p1s,
|
||||
ICancelablePromise p2, IEnumerable<ICancelablePromise> p2s)
|
||||
{
|
||||
if (p1 != null) yield return p1;
|
||||
if (p1s != null) foreach (var item in p1s) yield return item;
|
||||
if (p2 != null) yield return p2;
|
||||
if (p2s != null) foreach (var item in p2s) yield return item;
|
||||
}
|
||||
|
||||
static protected IEnumerable<ICancelablePromise> Concat(
|
||||
ICancelablePromise p1, IEnumerable<ICancelablePromise> p1s,
|
||||
ICancelablePromise p2, IEnumerable<ICancelablePromise> p2s,
|
||||
ICancelablePromise p3, IEnumerable<ICancelablePromise> p3s)
|
||||
{
|
||||
if (p1 != null) yield return p1;
|
||||
if (p1s != null) foreach (var item in p1s) yield return item;
|
||||
if (p2 != null) yield return p2;
|
||||
if (p2s != null) foreach (var item in p2s) yield return item;
|
||||
if (p3 != null) yield return p3;
|
||||
if (p3s != null) foreach (var item in p3s) yield return item;
|
||||
}
|
||||
|
||||
static protected IEnumerable<ICancelablePromise> Concat(
|
||||
ICancelablePromise p1, IEnumerable<ICancelablePromise> p1s,
|
||||
ICancelablePromise p2, IEnumerable<ICancelablePromise> p2s,
|
||||
ICancelablePromise p3, IEnumerable<ICancelablePromise> p3s,
|
||||
ICancelablePromise p4, IEnumerable<ICancelablePromise> p4s)
|
||||
{
|
||||
if (p1 != null) yield return p1;
|
||||
if (p1s != null) foreach (var item in p1s) yield return item;
|
||||
if (p2 != null) yield return p2;
|
||||
if (p2s != null) foreach (var item in p2s) yield return item;
|
||||
if (p3 != null) yield return p3;
|
||||
if (p3s != null) foreach (var item in p3s) yield return item;
|
||||
if (p4 != null) yield return p4;
|
||||
if (p4s != null) foreach (var item in p4s) yield return item;
|
||||
}
|
||||
|
||||
// otherwise...
|
||||
static protected IEnumerable<ICancelablePromise> Concat(params object[] promises)
|
||||
{
|
||||
foreach (var item in promises)
|
||||
{
|
||||
if (item is ICancelablePromise p)
|
||||
{
|
||||
yield return p;
|
||||
}
|
||||
else if (item is IEnumerable<ICancelablePromise> ps)
|
||||
{
|
||||
foreach (var p2 in ps)
|
||||
{
|
||||
yield return p2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected UniTask<T> GetOrAddPromise<T>(ref AsyncTriggerPromise<T> promise, ref AsyncTriggerPromiseDictionary<T> promises, CancellationToken cancellationToken)
|
||||
{
|
||||
if (destroyCalled) return UniTask.FromCanceled<T>();
|
||||
|
||||
if (!cancellationToken.CanBeCanceled)
|
||||
{
|
||||
if (promise == null)
|
||||
{
|
||||
promise = new AsyncTriggerPromise<T>();
|
||||
if (!calledAwake)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this));
|
||||
}
|
||||
}
|
||||
return promise.Task;
|
||||
}
|
||||
|
||||
if (promises == null) promises = new AsyncTriggerPromiseDictionary<T>();
|
||||
|
||||
if (promises.TryGetValue(cancellationToken, out var cancellablePromise))
|
||||
{
|
||||
return cancellablePromise.Task;
|
||||
}
|
||||
|
||||
cancellablePromise = new AsyncTriggerPromise<T>();
|
||||
promises.Add(cancellationToken, cancellablePromise);
|
||||
if (!calledAwake)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this));
|
||||
}
|
||||
|
||||
var registrationToken = cancellationToken.RegisterWithoutCaptureExecutionContext(Callback, Tuple.Create((ICancellationTokenKeyDictionary)promises, (ICancelablePromise)cancellablePromise));
|
||||
if (registeredCancellations == null)
|
||||
{
|
||||
registeredCancellations = ArrayPool<CancellationTokenRegistration>.Shared.Rent(4);
|
||||
}
|
||||
ArrayPoolUtil.EnsureCapacity(ref registeredCancellations, registeredCancellationsCount + 1, ArrayPool<CancellationTokenRegistration>.Shared);
|
||||
registeredCancellations[registeredCancellationsCount++] = registrationToken;
|
||||
|
||||
return cancellablePromise.Task;
|
||||
}
|
||||
|
||||
static void CancelCallback(object state)
|
||||
{
|
||||
var tuple = (Tuple<ICancellationTokenKeyDictionary, ICancelablePromise>)state;
|
||||
var dict = tuple.Item1;
|
||||
var promise = tuple.Item2;
|
||||
|
||||
promise.TrySetCanceled();
|
||||
dict.Remove(promise.RegisteredCancellationToken);
|
||||
}
|
||||
|
||||
protected void TrySetResult<T>(ReusablePromise<T> promise, AsyncTriggerPromiseDictionary<T> promises, T value)
|
||||
{
|
||||
if (promise != null)
|
||||
{
|
||||
promise.TrySetResult(value);
|
||||
}
|
||||
if (promises != null)
|
||||
{
|
||||
PromiseHelper.TrySetResultAll(promises.Values, value);
|
||||
}
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
calledAwake = true;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (destroyCalled) return;
|
||||
destroyCalled = true;
|
||||
foreach (var item in GetPromises())
|
||||
{
|
||||
item.TrySetCanceled();
|
||||
}
|
||||
if (registeredCancellations != null)
|
||||
{
|
||||
for (int i = 0; i < registeredCancellationsCount; i++)
|
||||
{
|
||||
registeredCancellations[i].Dispose();
|
||||
registeredCancellations[i] = default(CancellationTokenRegistration);
|
||||
}
|
||||
ArrayPool<CancellationTokenRegistration>.Shared.Return(registeredCancellations);
|
||||
}
|
||||
}
|
||||
|
||||
class AwakeMonitor : IPlayerLoopItem
|
||||
{
|
||||
readonly AsyncTriggerBase trigger;
|
||||
|
||||
public AwakeMonitor(AsyncTriggerBase trigger)
|
||||
{
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (trigger.calledAwake) return false;
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger.OnDestroy();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,511 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
public static class AsyncTriggerExtensions
|
||||
{
|
||||
// Util.
|
||||
|
||||
static T GetOrAddComponent<T>(GameObject gameObject)
|
||||
where T : Component
|
||||
{
|
||||
var component = gameObject.GetComponent<T>();
|
||||
if (component == null)
|
||||
{
|
||||
component = gameObject.AddComponent<T>();
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
// Special for single operation.
|
||||
|
||||
/// <summary>This function is called when the MonoBehaviour will be destroyed.</summary>
|
||||
public static UniTask OnDestroyAsync(this GameObject gameObject)
|
||||
{
|
||||
return gameObject.GetAsyncDestroyTrigger().OnDestroyAsync();
|
||||
}
|
||||
|
||||
/// <summary>This function is called when the MonoBehaviour will be destroyed.</summary>
|
||||
public static UniTask OnDestroyAsync(this Component component)
|
||||
{
|
||||
return component.GetAsyncDestroyTrigger().OnDestroyAsync();
|
||||
}
|
||||
|
||||
/// <summary>This CancellationToken is canceled when the MonoBehaviour will be destroyed.</summary>
|
||||
public static CancellationToken GetCancellationTokenOnDestroy(this GameObject gameObject)
|
||||
{
|
||||
return gameObject.GetAsyncDestroyTrigger().CancellationToken;
|
||||
}
|
||||
|
||||
/// <summary>This CancellationToken is canceled when the MonoBehaviour will be destroyed.</summary>
|
||||
public static CancellationToken GetCancellationTokenOnDestroy(this Component component)
|
||||
{
|
||||
return component.GetAsyncDestroyTrigger().CancellationToken;
|
||||
}
|
||||
|
||||
public static UniTask StartAsync(this GameObject gameObject)
|
||||
{
|
||||
return gameObject.GetAsyncStartTrigger().StartAsync();
|
||||
}
|
||||
|
||||
public static UniTask StartAsync(this Component component)
|
||||
{
|
||||
return component.GetAsyncStartTrigger().StartAsync();
|
||||
}
|
||||
|
||||
public static UniTask AwakeAsync(this GameObject gameObject)
|
||||
{
|
||||
return gameObject.GetAsyncAwakeTrigger().AwakeAsync();
|
||||
}
|
||||
|
||||
public static UniTask AwakeAsync(this Component component)
|
||||
{
|
||||
return component.GetAsyncAwakeTrigger().AwakeAsync();
|
||||
}
|
||||
|
||||
// Get Triggers.
|
||||
|
||||
/// <summary>Get for OnAnimatorIKAsync | OnAnimatorMoveAsync.</summary>
|
||||
public static AsyncAnimatorTrigger GetAsyncAnimatorTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncAnimatorTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnAnimatorIKAsync | OnAnimatorMoveAsync.</summary>
|
||||
public static AsyncAnimatorTrigger GetAsyncAnimatorTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncAnimatorTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for AwakeAsync.</summary>
|
||||
public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncAwakeTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for AwakeAsync.</summary>
|
||||
public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncAwakeTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnBeginDragAsync.</summary>
|
||||
public static AsyncBeginDragTrigger GetAsyncBeginDragTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncBeginDragTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnBeginDragAsync.</summary>
|
||||
public static AsyncBeginDragTrigger GetAsyncBeginDragTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncBeginDragTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnCancelAsync.</summary>
|
||||
public static AsyncCancelTrigger GetAsyncCancelTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncCancelTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnCancelAsync.</summary>
|
||||
public static AsyncCancelTrigger GetAsyncCancelTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncCancelTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnCanvasGroupChangedAsync.</summary>
|
||||
public static AsyncCanvasGroupChangedTrigger GetAsyncCanvasGroupChangedTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncCanvasGroupChangedTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnCanvasGroupChangedAsync.</summary>
|
||||
public static AsyncCanvasGroupChangedTrigger GetAsyncCanvasGroupChangedTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncCanvasGroupChangedTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnCollisionEnter2DAsync | OnCollisionExit2DAsync | OnCollisionStay2DAsync.</summary>
|
||||
public static AsyncCollision2DTrigger GetAsyncCollision2DTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncCollision2DTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnCollisionEnter2DAsync | OnCollisionExit2DAsync | OnCollisionStay2DAsync.</summary>
|
||||
public static AsyncCollision2DTrigger GetAsyncCollision2DTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncCollision2DTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnCollisionEnterAsync | OnCollisionExitAsync | OnCollisionStayAsync.</summary>
|
||||
public static AsyncCollisionTrigger GetAsyncCollisionTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncCollisionTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnCollisionEnterAsync | OnCollisionExitAsync | OnCollisionStayAsync.</summary>
|
||||
public static AsyncCollisionTrigger GetAsyncCollisionTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncCollisionTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnDeselectAsync.</summary>
|
||||
public static AsyncDeselectTrigger GetAsyncDeselectTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncDeselectTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnDeselectAsync.</summary>
|
||||
public static AsyncDeselectTrigger GetAsyncDeselectTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncDeselectTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnDestroyAsync.</summary>
|
||||
public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncDestroyTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnDestroyAsync.</summary>
|
||||
public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncDestroyTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnDragAsync.</summary>
|
||||
public static AsyncDragTrigger GetAsyncDragTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncDragTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnDragAsync.</summary>
|
||||
public static AsyncDragTrigger GetAsyncDragTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncDragTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnDropAsync.</summary>
|
||||
public static AsyncDropTrigger GetAsyncDropTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncDropTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnDropAsync.</summary>
|
||||
public static AsyncDropTrigger GetAsyncDropTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncDropTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnEnableAsync | OnDisableAsync.</summary>
|
||||
public static AsyncEnableDisableTrigger GetAsyncEnableDisableTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncEnableDisableTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnEnableAsync | OnDisableAsync.</summary>
|
||||
public static AsyncEnableDisableTrigger GetAsyncEnableDisableTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncEnableDisableTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnEndDragAsync.</summary>
|
||||
public static AsyncEndDragTrigger GetAsyncEndDragTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncEndDragTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnEndDragAsync.</summary>
|
||||
public static AsyncEndDragTrigger GetAsyncEndDragTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncEndDragTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for FixedUpdateAsync.</summary>
|
||||
public static AsyncFixedUpdateTrigger GetAsyncFixedUpdateTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncFixedUpdateTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for FixedUpdateAsync.</summary>
|
||||
public static AsyncFixedUpdateTrigger GetAsyncFixedUpdateTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncFixedUpdateTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnInitializePotentialDragAsync.</summary>
|
||||
public static AsyncInitializePotentialDragTrigger GetAsyncInitializePotentialDragTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncInitializePotentialDragTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnInitializePotentialDragAsync.</summary>
|
||||
public static AsyncInitializePotentialDragTrigger GetAsyncInitializePotentialDragTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncInitializePotentialDragTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnJointBreakAsync.</summary>
|
||||
public static AsyncJointTrigger GetAsyncJointTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncJointTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnJointBreakAsync.</summary>
|
||||
public static AsyncJointTrigger GetAsyncJointTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncJointTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for LateUpdateAsync.</summary>
|
||||
public static AsyncLateUpdateTrigger GetAsyncLateUpdateTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncLateUpdateTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for LateUpdateAsync.</summary>
|
||||
public static AsyncLateUpdateTrigger GetAsyncLateUpdateTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncLateUpdateTrigger();
|
||||
}
|
||||
|
||||
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
|
||||
|
||||
/// <summary>Get for OnMouseDownAsync | OnMouseDragAsync | OnMouseEnterAsync | OnMouseExitAsync | OnMouseOverAsync | OnMouseUpAsync | OnMouseUpAsButtonAsync.</summary>
|
||||
public static AsyncMouseTrigger GetAsyncMouseTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncMouseTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnMouseDownAsync | OnMouseDragAsync | OnMouseEnterAsync | OnMouseExitAsync | OnMouseOverAsync | OnMouseUpAsync | OnMouseUpAsButtonAsync.</summary>
|
||||
public static AsyncMouseTrigger GetAsyncMouseTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncMouseTrigger();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>Get for OnMoveAsync.</summary>
|
||||
public static AsyncMoveTrigger GetAsyncMoveTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncMoveTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnMoveAsync.</summary>
|
||||
public static AsyncMoveTrigger GetAsyncMoveTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncMoveTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnParticleCollisionAsync | OnParticleTriggerAsync.</summary>
|
||||
public static AsyncParticleTrigger GetAsyncParticleTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncParticleTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnParticleCollisionAsync | OnParticleTriggerAsync.</summary>
|
||||
public static AsyncParticleTrigger GetAsyncParticleTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncParticleTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnPointerClickAsync.</summary>
|
||||
public static AsyncPointerClickTrigger GetAsyncPointerClickTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncPointerClickTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnPointerClickAsync.</summary>
|
||||
public static AsyncPointerClickTrigger GetAsyncPointerClickTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncPointerClickTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnPointerDownAsync.</summary>
|
||||
public static AsyncPointerDownTrigger GetAsyncPointerDownTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncPointerDownTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnPointerDownAsync.</summary>
|
||||
public static AsyncPointerDownTrigger GetAsyncPointerDownTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncPointerDownTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnPointerEnterAsync.</summary>
|
||||
public static AsyncPointerEnterTrigger GetAsyncPointerEnterTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncPointerEnterTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnPointerEnterAsync.</summary>
|
||||
public static AsyncPointerEnterTrigger GetAsyncPointerEnterTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncPointerEnterTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnPointerExitAsync.</summary>
|
||||
public static AsyncPointerExitTrigger GetAsyncPointerExitTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncPointerExitTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnPointerExitAsync.</summary>
|
||||
public static AsyncPointerExitTrigger GetAsyncPointerExitTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncPointerExitTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnPointerUpAsync.</summary>
|
||||
public static AsyncPointerUpTrigger GetAsyncPointerUpTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncPointerUpTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnPointerUpAsync.</summary>
|
||||
public static AsyncPointerUpTrigger GetAsyncPointerUpTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncPointerUpTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnRectTransformDimensionsChange | OnRectTransformDimensionsChangeAsync | OnRectTransformRemoved | OnRectTransformRemovedAsync.</summary>
|
||||
public static AsyncRectTransformTrigger GetAsyncRectTransformTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncRectTransformTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnRectTransformDimensionsChange | OnRectTransformDimensionsChangeAsync | OnRectTransformRemoved | OnRectTransformRemovedAsync.</summary>
|
||||
public static AsyncRectTransformTrigger GetAsyncRectTransformTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncRectTransformTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnScrollAsync.</summary>
|
||||
public static AsyncScrollTrigger GetAsyncScrollTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncScrollTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnScrollAsync.</summary>
|
||||
public static AsyncScrollTrigger GetAsyncScrollTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncScrollTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnSelectAsync.</summary>
|
||||
public static AsyncSelectTrigger GetAsyncSelectTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncSelectTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnSelectAsync.</summary>
|
||||
public static AsyncSelectTrigger GetAsyncSelectTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncSelectTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for StartAsync.</summary>
|
||||
public static AsyncStartTrigger GetAsyncStartTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncStartTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for StartAsync.</summary>
|
||||
public static AsyncStartTrigger GetAsyncStartTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncStartTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnSubmitAsync.</summary>
|
||||
public static AsyncSubmitTrigger GetAsyncSubmitTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncSubmitTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnSubmitAsync.</summary>
|
||||
public static AsyncSubmitTrigger GetAsyncSubmitTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncSubmitTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnBeforeTransformParentChangedAsync | OnTransformParentChangedAsync | OnTransformChildrenChangedAsync.</summary>
|
||||
public static AsyncTransformChangedTrigger GetAsyncTransformChangedTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncTransformChangedTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnBeforeTransformParentChangedAsync | OnTransformParentChangedAsync | OnTransformChildrenChangedAsync.</summary>
|
||||
public static AsyncTransformChangedTrigger GetAsyncTransformChangedTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncTransformChangedTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnTriggerEnter2DAsync | OnTriggerExit2DAsync | OnTriggerStay2DAsync.</summary>
|
||||
public static AsyncTrigger2DTrigger GetAsyncTrigger2DTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncTrigger2DTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnTriggerEnter2DAsync | OnTriggerExit2DAsync | OnTriggerStay2DAsync.</summary>
|
||||
public static AsyncTrigger2DTrigger GetAsyncTrigger2DTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncTrigger2DTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnTriggerEnterAsync | OnTriggerExitAsync | OnTriggerStayAsync.</summary>
|
||||
public static AsyncTriggerTrigger GetAsyncTriggerTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncTriggerTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnTriggerEnterAsync | OnTriggerExitAsync | OnTriggerStayAsync.</summary>
|
||||
public static AsyncTriggerTrigger GetAsyncTriggerTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncTriggerTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnUpdateSelectedAsync.</summary>
|
||||
public static AsyncUpdateSelectedTrigger GetAsyncUpdateSelectedTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncUpdateSelectedTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnUpdateSelectedAsync.</summary>
|
||||
public static AsyncUpdateSelectedTrigger GetAsyncUpdateSelectedTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncUpdateSelectedTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for UpdateAsync.</summary>
|
||||
public static AsyncUpdateTrigger GetAsyncUpdateTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncUpdateTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for UpdateAsync.</summary>
|
||||
public static AsyncUpdateTrigger GetAsyncUpdateTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncUpdateTrigger();
|
||||
}
|
||||
|
||||
/// <summary>Get for OnBecameInvisibleAsync | OnBecameVisibleAsync.</summary>
|
||||
public static AsyncVisibleTrigger GetAsyncVisibleTrigger(this GameObject gameObject)
|
||||
{
|
||||
return GetOrAddComponent<AsyncVisibleTrigger>(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>Get for OnBecameInvisibleAsync | OnBecameVisibleAsync.</summary>
|
||||
public static AsyncVisibleTrigger GetAsyncVisibleTrigger(this Component component)
|
||||
{
|
||||
return component.gameObject.GetAsyncVisibleTrigger();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,69 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncTriggerTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<Collider> onTriggerEnter;
|
||||
AsyncTriggerPromiseDictionary<Collider> onTriggerEnters;
|
||||
AsyncTriggerPromise<Collider> onTriggerExit;
|
||||
AsyncTriggerPromiseDictionary<Collider> onTriggerExits;
|
||||
AsyncTriggerPromise<Collider> onTriggerStay;
|
||||
AsyncTriggerPromiseDictionary<Collider> onTriggerStays;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onTriggerEnter, onTriggerEnters, onTriggerExit, onTriggerExits, onTriggerStay, onTriggerStays);
|
||||
}
|
||||
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
TrySetResult(onTriggerEnter, onTriggerEnters, other);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collider> OnTriggerEnterAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onTriggerEnter, ref onTriggerEnters, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnTriggerExit(Collider other)
|
||||
{
|
||||
TrySetResult(onTriggerExit, onTriggerExits, other);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collider> OnTriggerExitAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onTriggerExit, ref onTriggerExits, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnTriggerStay(Collider other)
|
||||
{
|
||||
TrySetResult(onTriggerStay, onTriggerStays, other);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<Collider> OnTriggerStayAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onTriggerStay, ref onTriggerStays, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46bbbbaa910762c4786906e10b6b7b8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncUpdateSelectedTrigger : AsyncTriggerBase, IUpdateSelectedHandler
|
||||
{
|
||||
AsyncTriggerPromise<BaseEventData> onUpdateSelected;
|
||||
AsyncTriggerPromiseDictionary<BaseEventData> onUpdateSelecteds;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onUpdateSelected, onUpdateSelecteds);
|
||||
}
|
||||
|
||||
|
||||
void IUpdateSelectedHandler.OnUpdateSelected(BaseEventData eventData)
|
||||
{
|
||||
TrySetResult(onUpdateSelected, onUpdateSelecteds, eventData);
|
||||
}
|
||||
|
||||
|
||||
public UniTask<BaseEventData> OnUpdateSelectedAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onUpdateSelected, ref onUpdateSelecteds, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba5b0a4234e164e41b85f10b709d72e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncUpdateTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<AsyncUnit> update;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> updates;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(update, updates);
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
TrySetResult(update, updates, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask UpdateAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref update, ref updates, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6053bbe25af0d6439712f7c5fc4afc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +0,0 @@
|
||||
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UniRx.Async.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class AsyncVisibleTrigger : AsyncTriggerBase
|
||||
{
|
||||
AsyncTriggerPromise<AsyncUnit> onBecameInvisible;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onBecameInvisibles;
|
||||
AsyncTriggerPromise<AsyncUnit> onBecameVisible;
|
||||
AsyncTriggerPromiseDictionary<AsyncUnit> onBecameVisibles;
|
||||
|
||||
|
||||
protected override IEnumerable<ICancelablePromise> GetPromises()
|
||||
{
|
||||
return Concat(onBecameInvisible, onBecameInvisibles, onBecameVisible, onBecameVisibles);
|
||||
}
|
||||
|
||||
|
||||
void OnBecameInvisible()
|
||||
{
|
||||
TrySetResult(onBecameInvisible, onBecameInvisibles, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnBecameInvisibleAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onBecameInvisible, ref onBecameInvisibles, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
void OnBecameVisible()
|
||||
{
|
||||
TrySetResult(onBecameVisible, onBecameVisibles, AsyncUnit.Default);
|
||||
}
|
||||
|
||||
|
||||
public UniTask OnBecameVisibleAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return GetOrAddPromise(ref onBecameVisible, ref onBecameVisibles, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57ebfef2a87c49c46ad6454db136f3ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"name": "UniRx.Async",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using UniRx.Async.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public partial struct UniTask
|
||||
{
|
||||
public static YieldAwaitable Yield(PlayerLoopTiming timing = PlayerLoopTiming.Update)
|
||||
{
|
||||
// optimized for single continuation
|
||||
return new YieldAwaitable(timing);
|
||||
}
|
||||
|
||||
public static UniTask Yield(PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
{
|
||||
return new UniTask(new YieldPromise(timing, cancellationToken));
|
||||
}
|
||||
|
||||
public static UniTask<int> DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (delayFrameCount < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount);
|
||||
}
|
||||
|
||||
var source = new DelayFramePromise(delayFrameCount, delayTiming, cancellationToken);
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public static UniTask Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var delayTimeSpan = TimeSpan.FromMilliseconds(millisecondsDelay);
|
||||
if (delayTimeSpan < TimeSpan.Zero)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayTimeSpan:" + delayTimeSpan);
|
||||
}
|
||||
|
||||
return (ignoreTimeScale)
|
||||
? new DelayIgnoreTimeScalePromise(delayTimeSpan, delayTiming, cancellationToken).Task
|
||||
: new DelayPromise(delayTimeSpan, delayTiming, cancellationToken).Task;
|
||||
}
|
||||
|
||||
public static UniTask Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (delayTimeSpan < TimeSpan.Zero)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayTimeSpan:" + delayTimeSpan);
|
||||
}
|
||||
|
||||
return (ignoreTimeScale)
|
||||
? new DelayIgnoreTimeScalePromise(delayTimeSpan, delayTiming, cancellationToken).Task
|
||||
: new DelayPromise(delayTimeSpan, delayTiming, cancellationToken).Task;
|
||||
}
|
||||
|
||||
class YieldPromise : PlayerLoopReusablePromiseBase
|
||||
{
|
||||
public YieldPromise(PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 2)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
Complete();
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
TrySetCanceled();
|
||||
}
|
||||
else
|
||||
{
|
||||
TrySetResult();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class DelayFramePromise : PlayerLoopReusablePromiseBase<int>
|
||||
{
|
||||
readonly int delayFrameCount;
|
||||
int currentFrameCount;
|
||||
|
||||
public DelayFramePromise(int delayFrameCount, PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 2)
|
||||
{
|
||||
this.delayFrameCount = delayFrameCount;
|
||||
this.currentFrameCount = 0;
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
currentFrameCount = 0;
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
Complete();
|
||||
TrySetCanceled();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentFrameCount == delayFrameCount)
|
||||
{
|
||||
Complete();
|
||||
TrySetResult(currentFrameCount);
|
||||
return false;
|
||||
}
|
||||
|
||||
currentFrameCount++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class DelayPromise : PlayerLoopReusablePromiseBase
|
||||
{
|
||||
readonly float delayFrameTimeSpan;
|
||||
float elapsed;
|
||||
|
||||
public DelayPromise(TimeSpan delayFrameTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 2)
|
||||
{
|
||||
this.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds;
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
this.elapsed = 0.0f;
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
Complete();
|
||||
TrySetCanceled();
|
||||
return false;
|
||||
}
|
||||
|
||||
elapsed += Time.deltaTime;
|
||||
if (elapsed >= delayFrameTimeSpan)
|
||||
{
|
||||
Complete();
|
||||
TrySetResult();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class DelayIgnoreTimeScalePromise : PlayerLoopReusablePromiseBase
|
||||
{
|
||||
readonly float delayFrameTimeSpan;
|
||||
float elapsed;
|
||||
|
||||
public DelayIgnoreTimeScalePromise(TimeSpan delayFrameTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 2)
|
||||
{
|
||||
this.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds;
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
this.elapsed = 0.0f;
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
Complete();
|
||||
TrySetCanceled();
|
||||
return false;
|
||||
}
|
||||
|
||||
elapsed += Time.unscaledDeltaTime;
|
||||
|
||||
if (elapsed >= delayFrameTimeSpan)
|
||||
{
|
||||
Complete();
|
||||
TrySetResult();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct YieldAwaitable
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
|
||||
public YieldAwaitable(PlayerLoopTiming timing)
|
||||
{
|
||||
this.timing = timing;
|
||||
}
|
||||
|
||||
public Awaiter GetAwaiter()
|
||||
{
|
||||
return new Awaiter(timing);
|
||||
}
|
||||
|
||||
public UniTask ToUniTask()
|
||||
{
|
||||
return UniTask.Yield(timing, CancellationToken.None);
|
||||
}
|
||||
|
||||
public struct Awaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
|
||||
public Awaiter(PlayerLoopTiming timing)
|
||||
{
|
||||
this.timing = timing;
|
||||
}
|
||||
|
||||
public bool IsCompleted => false;
|
||||
|
||||
public void GetResult() { }
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
PlayerLoopHelper.AddContinuation(timing, continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
PlayerLoopHelper.AddContinuation(timing, continuation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,235 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UniRx.Async.Internal;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public partial struct UniTask
|
||||
{
|
||||
public static UniTask WaitUntil(Func<bool> predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var promise = new WaitUntilPromise(predicate, timing, cancellationToken);
|
||||
return promise.Task;
|
||||
}
|
||||
|
||||
public static UniTask WaitWhile(Func<bool> predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var promise = new WaitWhilePromise(predicate, timing, cancellationToken);
|
||||
return promise.Task;
|
||||
}
|
||||
|
||||
public static UniTask<U> WaitUntilValueChanged<T, U>(T target, Func<T, U> monitorFunction, PlayerLoopTiming monitorTiming = PlayerLoopTiming.Update, IEqualityComparer<U> equalityComparer = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||
where T : class
|
||||
{
|
||||
var unityObject = target as UnityEngine.Object;
|
||||
var isUnityObject = !object.ReferenceEquals(target, null); // don't use (unityObject == null)
|
||||
|
||||
return (isUnityObject)
|
||||
? new WaitUntilValueChangedUnityObjectPromise<T, U>(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken).Task
|
||||
: new WaitUntilValueChangedStandardObjectPromise<T, U>(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken).Task;
|
||||
}
|
||||
|
||||
class WaitUntilPromise : PlayerLoopReusablePromiseBase
|
||||
{
|
||||
readonly Func<bool> predicate;
|
||||
|
||||
public WaitUntilPromise(Func<bool> predicate, PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 1)
|
||||
{
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
Complete();
|
||||
TrySetCanceled();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = default(bool);
|
||||
try
|
||||
{
|
||||
result = predicate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Complete();
|
||||
TrySetException(ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
Complete();
|
||||
TrySetResult();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class WaitWhilePromise : PlayerLoopReusablePromiseBase
|
||||
{
|
||||
readonly Func<bool> predicate;
|
||||
|
||||
public WaitWhilePromise(Func<bool> predicate, PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 1)
|
||||
{
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
Complete();
|
||||
TrySetCanceled();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = default(bool);
|
||||
try
|
||||
{
|
||||
result = predicate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Complete();
|
||||
TrySetException(ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
Complete();
|
||||
TrySetResult();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// where T : UnityEngine.Object, can not add constraint
|
||||
class WaitUntilValueChangedUnityObjectPromise<T, U> : PlayerLoopReusablePromiseBase<U>
|
||||
{
|
||||
readonly T target;
|
||||
readonly Func<T, U> monitorFunction;
|
||||
readonly IEqualityComparer<U> equalityComparer;
|
||||
U currentValue;
|
||||
|
||||
public WaitUntilValueChangedUnityObjectPromise(T target, Func<T, U> monitorFunction, IEqualityComparer<U> equalityComparer, PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 1)
|
||||
{
|
||||
this.target = target;
|
||||
this.monitorFunction = monitorFunction;
|
||||
this.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault<U>();
|
||||
this.currentValue = monitorFunction(target);
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested || target == null) // destroyed = cancel.
|
||||
{
|
||||
Complete();
|
||||
TrySetCanceled();
|
||||
return false;
|
||||
}
|
||||
|
||||
U nextValue = default(U);
|
||||
try
|
||||
{
|
||||
nextValue = monitorFunction(target);
|
||||
if (equalityComparer.Equals(currentValue, nextValue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Complete();
|
||||
TrySetException(ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
Complete();
|
||||
currentValue = nextValue;
|
||||
TrySetResult(nextValue);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class WaitUntilValueChangedStandardObjectPromise<T, U> : PlayerLoopReusablePromiseBase<U>
|
||||
where T : class
|
||||
{
|
||||
readonly WeakReference<T> target;
|
||||
readonly Func<T, U> monitorFunction;
|
||||
readonly IEqualityComparer<U> equalityComparer;
|
||||
U currentValue;
|
||||
|
||||
public WaitUntilValueChangedStandardObjectPromise(T target, Func<T, U> monitorFunction, IEqualityComparer<U> equalityComparer, PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 1)
|
||||
{
|
||||
this.target = new WeakReference<T>(target, false); // wrap in WeakReference.
|
||||
this.monitorFunction = monitorFunction;
|
||||
this.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault<U>();
|
||||
this.currentValue = monitorFunction(target);
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested || !target.TryGetTarget(out var t))
|
||||
{
|
||||
Complete();
|
||||
TrySetCanceled();
|
||||
return false;
|
||||
}
|
||||
|
||||
U nextValue = default(U);
|
||||
try
|
||||
{
|
||||
nextValue = monitorFunction(t);
|
||||
if (equalityComparer.Equals(currentValue, nextValue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Complete();
|
||||
TrySetException(ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
Complete();
|
||||
currentValue = nextValue;
|
||||
TrySetResult(nextValue);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,298 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Threading;
|
||||
using UniRx.Async.Internal;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public partial struct UniTask
|
||||
{
|
||||
// UniTask
|
||||
|
||||
public static async UniTask<T[]> WhenAll<T>(params UniTask<T>[] tasks)
|
||||
{
|
||||
return await new WhenAllPromise<T>(tasks, tasks.Length);
|
||||
}
|
||||
|
||||
public static async UniTask<T[]> WhenAll<T>(IEnumerable<UniTask<T>> tasks)
|
||||
{
|
||||
WhenAllPromise<T> promise;
|
||||
using (var span = ArrayPoolUtil.Materialize(tasks))
|
||||
{
|
||||
promise = new WhenAllPromise<T>(span.Array, span.Length);
|
||||
}
|
||||
|
||||
return await promise;
|
||||
}
|
||||
|
||||
public static async UniTask WhenAll(params UniTask[] tasks)
|
||||
{
|
||||
await new WhenAllPromise(tasks, tasks.Length);
|
||||
}
|
||||
|
||||
public static async UniTask WhenAll(IEnumerable<UniTask> tasks)
|
||||
{
|
||||
WhenAllPromise promise;
|
||||
using (var span = ArrayPoolUtil.Materialize(tasks))
|
||||
{
|
||||
promise = new WhenAllPromise(span.Array, span.Length);
|
||||
}
|
||||
|
||||
await promise;
|
||||
}
|
||||
|
||||
class WhenAllPromise<T>
|
||||
{
|
||||
readonly T[] result;
|
||||
int completeCount;
|
||||
Action whenComplete;
|
||||
ExceptionDispatchInfo exception;
|
||||
|
||||
public WhenAllPromise(UniTask<T>[] tasks, int tasksLength)
|
||||
{
|
||||
this.completeCount = 0;
|
||||
this.whenComplete = null;
|
||||
this.exception = null;
|
||||
this.result = new T[tasksLength];
|
||||
|
||||
for (int i = 0; i < tasksLength; i++)
|
||||
{
|
||||
if (tasks[i].IsCompleted)
|
||||
{
|
||||
T value = default(T);
|
||||
try
|
||||
{
|
||||
value = tasks[i].Result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryCallContinuation();
|
||||
continue;
|
||||
}
|
||||
|
||||
result[i] = value;
|
||||
var count = Interlocked.Increment(ref completeCount);
|
||||
if (count == result.Length)
|
||||
{
|
||||
TryCallContinuation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RunTask(tasks[i], i).Forget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TryCallContinuation()
|
||||
{
|
||||
var action = Interlocked.Exchange(ref whenComplete, null);
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
async UniTaskVoid RunTask(UniTask<T> task, int index)
|
||||
{
|
||||
T value = default(T);
|
||||
try
|
||||
{
|
||||
value = await task;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryCallContinuation();
|
||||
return;
|
||||
}
|
||||
|
||||
result[index] = value;
|
||||
var count = Interlocked.Increment(ref completeCount);
|
||||
if (count == result.Length)
|
||||
{
|
||||
TryCallContinuation();
|
||||
}
|
||||
}
|
||||
|
||||
public Awaiter GetAwaiter()
|
||||
{
|
||||
return new Awaiter(this);
|
||||
}
|
||||
|
||||
public struct Awaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
WhenAllPromise<T> parent;
|
||||
|
||||
public Awaiter(WhenAllPromise<T> parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
return parent.exception != null || parent.result.Length == parent.completeCount;
|
||||
}
|
||||
}
|
||||
|
||||
public T[] GetResult()
|
||||
{
|
||||
if (parent.exception != null)
|
||||
{
|
||||
parent.exception.Throw();
|
||||
}
|
||||
|
||||
return parent.result;
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
parent.whenComplete = continuation;
|
||||
if (IsCompleted)
|
||||
{
|
||||
var action = Interlocked.Exchange(ref parent.whenComplete, null);
|
||||
if (action != null)
|
||||
{
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WhenAllPromise
|
||||
{
|
||||
int completeCount;
|
||||
int resultLength;
|
||||
Action whenComplete;
|
||||
ExceptionDispatchInfo exception;
|
||||
|
||||
public WhenAllPromise(UniTask[] tasks, int tasksLength)
|
||||
{
|
||||
this.completeCount = 0;
|
||||
this.whenComplete = null;
|
||||
this.exception = null;
|
||||
this.resultLength = tasksLength;
|
||||
|
||||
for (int i = 0; i < tasksLength; i++)
|
||||
{
|
||||
if (tasks[i].IsCompleted)
|
||||
{
|
||||
try
|
||||
{
|
||||
tasks[i].GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryCallContinuation();
|
||||
continue;
|
||||
}
|
||||
|
||||
var count = Interlocked.Increment(ref completeCount);
|
||||
if (count == resultLength)
|
||||
{
|
||||
TryCallContinuation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RunTask(tasks[i], i).Forget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TryCallContinuation()
|
||||
{
|
||||
var action = Interlocked.Exchange(ref whenComplete, null);
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
async UniTaskVoid RunTask(UniTask task, int index)
|
||||
{
|
||||
try
|
||||
{
|
||||
await task;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryCallContinuation();
|
||||
return;
|
||||
}
|
||||
|
||||
var count = Interlocked.Increment(ref completeCount);
|
||||
if (count == resultLength)
|
||||
{
|
||||
TryCallContinuation();
|
||||
}
|
||||
}
|
||||
|
||||
public Awaiter GetAwaiter()
|
||||
{
|
||||
return new Awaiter(this);
|
||||
}
|
||||
|
||||
public struct Awaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
WhenAllPromise parent;
|
||||
|
||||
public Awaiter(WhenAllPromise parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
return parent.exception != null || parent.resultLength == parent.completeCount;
|
||||
}
|
||||
}
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
if (parent.exception != null)
|
||||
{
|
||||
parent.exception.Throw();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
parent.whenComplete = continuation;
|
||||
if (IsCompleted)
|
||||
{
|
||||
var action = Interlocked.Exchange(ref parent.whenComplete, null);
|
||||
if (action != null)
|
||||
{
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,374 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public partial struct UniTask
|
||||
{
|
||||
// UniTask
|
||||
|
||||
public static async UniTask<(bool hasResultLeft, T0 result)> WhenAny<T0>(UniTask<T0> task0, UniTask task1)
|
||||
{
|
||||
return await new UnitWhenAnyPromise<T0>(task0, task1);
|
||||
}
|
||||
|
||||
public static async UniTask<(int winArgumentIndex, T result)> WhenAny<T>(params UniTask<T>[] tasks)
|
||||
{
|
||||
return await new WhenAnyPromise<T>(tasks);
|
||||
}
|
||||
|
||||
/// <summary>Return value is winArgumentIndex</summary>
|
||||
public static async UniTask<int> WhenAny(params UniTask[] tasks)
|
||||
{
|
||||
return await new WhenAnyPromise(tasks);
|
||||
}
|
||||
|
||||
class UnitWhenAnyPromise<T0>
|
||||
{
|
||||
T0 result0;
|
||||
ExceptionDispatchInfo exception;
|
||||
Action whenComplete;
|
||||
int completeCount;
|
||||
int winArgumentIndex;
|
||||
|
||||
bool IsCompleted => exception != null || Volatile.Read(ref winArgumentIndex) != -1;
|
||||
|
||||
public UnitWhenAnyPromise(UniTask<T0> task0, UniTask task1)
|
||||
{
|
||||
this.whenComplete = null;
|
||||
this.exception = null;
|
||||
this.completeCount = 0;
|
||||
this.winArgumentIndex = -1;
|
||||
this.result0 = default(T0);
|
||||
|
||||
RunTask0(task0).Forget();
|
||||
RunTask1(task1).Forget();
|
||||
}
|
||||
|
||||
void TryCallContinuation()
|
||||
{
|
||||
var action = Interlocked.Exchange(ref whenComplete, null);
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
async UniTaskVoid RunTask0(UniTask<T0> task)
|
||||
{
|
||||
T0 value;
|
||||
try
|
||||
{
|
||||
value = await task;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryCallContinuation();
|
||||
return;
|
||||
}
|
||||
|
||||
var count = Interlocked.Increment(ref completeCount);
|
||||
if (count == 1)
|
||||
{
|
||||
result0 = value;
|
||||
Volatile.Write(ref winArgumentIndex, 0);
|
||||
TryCallContinuation();
|
||||
}
|
||||
}
|
||||
|
||||
async UniTaskVoid RunTask1(UniTask task)
|
||||
{
|
||||
try
|
||||
{
|
||||
await task;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryCallContinuation();
|
||||
return;
|
||||
}
|
||||
|
||||
var count = Interlocked.Increment(ref completeCount);
|
||||
if (count == 1)
|
||||
{
|
||||
Volatile.Write(ref winArgumentIndex, 1);
|
||||
TryCallContinuation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Awaiter GetAwaiter()
|
||||
{
|
||||
return new Awaiter(this);
|
||||
}
|
||||
|
||||
public struct Awaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
UnitWhenAnyPromise<T0> parent;
|
||||
|
||||
public Awaiter(UnitWhenAnyPromise<T0> parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
return parent.IsCompleted;
|
||||
}
|
||||
}
|
||||
|
||||
public (bool, T0) GetResult()
|
||||
{
|
||||
if (parent.exception != null)
|
||||
{
|
||||
parent.exception.Throw();
|
||||
}
|
||||
|
||||
return (parent.winArgumentIndex == 0, parent.result0);
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
parent.whenComplete = continuation;
|
||||
if (IsCompleted)
|
||||
{
|
||||
var action = Interlocked.Exchange(ref parent.whenComplete, null);
|
||||
if (action != null)
|
||||
{
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class WhenAnyPromise<T>
|
||||
{
|
||||
T result;
|
||||
int completeCount;
|
||||
int winArgumentIndex;
|
||||
Action whenComplete;
|
||||
ExceptionDispatchInfo exception;
|
||||
|
||||
public bool IsComplete => exception != null || Volatile.Read(ref winArgumentIndex) != -1;
|
||||
|
||||
public WhenAnyPromise(UniTask<T>[] tasks)
|
||||
{
|
||||
this.completeCount = 0;
|
||||
this.winArgumentIndex = -1;
|
||||
this.whenComplete = null;
|
||||
this.exception = null;
|
||||
this.result = default(T);
|
||||
|
||||
for (int i = 0; i < tasks.Length; i++)
|
||||
{
|
||||
RunTask(tasks[i], i).Forget();
|
||||
}
|
||||
}
|
||||
|
||||
async UniTaskVoid RunTask(UniTask<T> task, int index)
|
||||
{
|
||||
T value;
|
||||
try
|
||||
{
|
||||
value = await task;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryCallContinuation();
|
||||
return;
|
||||
}
|
||||
|
||||
var count = Interlocked.Increment(ref completeCount);
|
||||
if (count == 1)
|
||||
{
|
||||
result = value;
|
||||
Volatile.Write(ref winArgumentIndex, index);
|
||||
TryCallContinuation();
|
||||
}
|
||||
}
|
||||
|
||||
void TryCallContinuation()
|
||||
{
|
||||
var action = Interlocked.Exchange(ref whenComplete, null);
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public Awaiter GetAwaiter()
|
||||
{
|
||||
return new Awaiter(this);
|
||||
}
|
||||
|
||||
public struct Awaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
WhenAnyPromise<T> parent;
|
||||
|
||||
public Awaiter(WhenAnyPromise<T> parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
return parent.IsComplete;
|
||||
}
|
||||
}
|
||||
|
||||
public (int, T) GetResult()
|
||||
{
|
||||
if (parent.exception != null)
|
||||
{
|
||||
parent.exception.Throw();
|
||||
}
|
||||
|
||||
return (parent.winArgumentIndex, parent.result);
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
parent.whenComplete = continuation;
|
||||
if (IsCompleted)
|
||||
{
|
||||
var action = Interlocked.Exchange(ref parent.whenComplete, null);
|
||||
if (action != null)
|
||||
{
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WhenAnyPromise
|
||||
{
|
||||
int completeCount;
|
||||
int winArgumentIndex;
|
||||
Action whenComplete;
|
||||
ExceptionDispatchInfo exception;
|
||||
|
||||
public bool IsComplete => exception != null || Volatile.Read(ref winArgumentIndex) != -1;
|
||||
|
||||
public WhenAnyPromise(UniTask[] tasks)
|
||||
{
|
||||
this.completeCount = 0;
|
||||
this.winArgumentIndex = -1;
|
||||
this.whenComplete = null;
|
||||
this.exception = null;
|
||||
|
||||
for (int i = 0; i < tasks.Length; i++)
|
||||
{
|
||||
RunTask(tasks[i], i).Forget();
|
||||
}
|
||||
}
|
||||
|
||||
async UniTaskVoid RunTask(UniTask task, int index)
|
||||
{
|
||||
try
|
||||
{
|
||||
await task;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryCallContinuation();
|
||||
return;
|
||||
}
|
||||
|
||||
var count = Interlocked.Increment(ref completeCount);
|
||||
if (count == 1)
|
||||
{
|
||||
Volatile.Write(ref winArgumentIndex, index);
|
||||
TryCallContinuation();
|
||||
}
|
||||
}
|
||||
|
||||
void TryCallContinuation()
|
||||
{
|
||||
var action = Interlocked.Exchange(ref whenComplete, null);
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public Awaiter GetAwaiter()
|
||||
{
|
||||
return new Awaiter(this);
|
||||
}
|
||||
|
||||
public struct Awaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
WhenAnyPromise parent;
|
||||
|
||||
public Awaiter(WhenAnyPromise parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
return parent.IsComplete;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetResult()
|
||||
{
|
||||
if (parent.exception != null)
|
||||
{
|
||||
parent.exception.Throw();
|
||||
}
|
||||
|
||||
return parent.winArgumentIndex;
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
parent.whenComplete = continuation;
|
||||
if (IsCompleted)
|
||||
{
|
||||
var action = Interlocked.Exchange(ref parent.whenComplete, null);
|
||||
if (action != null)
|
||||
{
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,479 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UniRx.Async.CompilerServices;
|
||||
using UniRx.Async.Internal;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
/// <summary>
|
||||
/// Lightweight unity specified task-like object.
|
||||
/// </summary>
|
||||
[AsyncMethodBuilder(typeof(AsyncUniTaskMethodBuilder))]
|
||||
public partial struct UniTask : IEquatable<UniTask>
|
||||
{
|
||||
static readonly UniTask<AsyncUnit> DefaultAsyncUnitTask = new UniTask<AsyncUnit>(AsyncUnit.Default);
|
||||
|
||||
readonly IAwaiter awaiter;
|
||||
|
||||
[DebuggerHidden]
|
||||
public UniTask(IAwaiter awaiter)
|
||||
{
|
||||
this.awaiter = awaiter;
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public UniTask(Func<UniTask> factory)
|
||||
{
|
||||
this.awaiter = new LazyPromise(factory);
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public AwaiterStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return awaiter == null ? AwaiterStatus.Succeeded : awaiter.Status;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
return awaiter == null ? true : awaiter.IsCompleted;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public void GetResult()
|
||||
{
|
||||
if (awaiter != null)
|
||||
{
|
||||
awaiter.GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public Awaiter GetAwaiter()
|
||||
{
|
||||
return new Awaiter(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns (bool IsCanceled) instead of throws OperationCanceledException.
|
||||
/// </summary>
|
||||
public UniTask<bool> SuppressCancellationThrow()
|
||||
{
|
||||
var status = Status;
|
||||
if (status == AwaiterStatus.Succeeded) return CompletedTasks.False;
|
||||
if (status == AwaiterStatus.Canceled) return CompletedTasks.True;
|
||||
return new UniTask<bool>(new IsCanceledAwaiter(awaiter));
|
||||
}
|
||||
|
||||
public bool Equals(UniTask other)
|
||||
{
|
||||
if (this.awaiter == null && other.awaiter == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (this.awaiter != null && other.awaiter != null)
|
||||
{
|
||||
return this.awaiter == other.awaiter;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
if (this.awaiter == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.awaiter.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (this.awaiter == null) ? "()"
|
||||
: (this.awaiter.Status == AwaiterStatus.Succeeded) ? "()"
|
||||
: "(" + this.awaiter.Status + ")";
|
||||
}
|
||||
|
||||
public static implicit operator UniTask<AsyncUnit>(UniTask task)
|
||||
{
|
||||
if (task.awaiter != null)
|
||||
{
|
||||
if (task.awaiter.IsCompleted)
|
||||
{
|
||||
return DefaultAsyncUnitTask;
|
||||
}
|
||||
else
|
||||
{
|
||||
// UniTask<T> -> UniTask is free but UniTask -> UniTask<T> requires wrapping cost.
|
||||
return new UniTask<AsyncUnit>(new AsyncUnitAwaiter(task.awaiter));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return DefaultAsyncUnitTask;
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncUnitAwaiter : IAwaiter<AsyncUnit>
|
||||
{
|
||||
readonly IAwaiter awaiter;
|
||||
|
||||
public AsyncUnitAwaiter(IAwaiter awaiter)
|
||||
{
|
||||
this.awaiter = awaiter;
|
||||
}
|
||||
|
||||
public bool IsCompleted => awaiter.IsCompleted;
|
||||
|
||||
public AwaiterStatus Status => awaiter.Status;
|
||||
|
||||
public AsyncUnit GetResult()
|
||||
{
|
||||
awaiter.GetResult();
|
||||
return AsyncUnit.Default;
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
awaiter.OnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
awaiter.UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
awaiter.GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
class IsCanceledAwaiter : IAwaiter<bool>
|
||||
{
|
||||
readonly IAwaiter awaiter;
|
||||
|
||||
public IsCanceledAwaiter(IAwaiter awaiter)
|
||||
{
|
||||
this.awaiter = awaiter;
|
||||
}
|
||||
|
||||
public bool IsCompleted => awaiter.IsCompleted;
|
||||
|
||||
public AwaiterStatus Status => awaiter.Status;
|
||||
|
||||
public bool GetResult()
|
||||
{
|
||||
if (awaiter.Status == AwaiterStatus.Canceled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
awaiter.GetResult();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
awaiter.OnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
awaiter.UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
awaiter.GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
public struct Awaiter : IAwaiter
|
||||
{
|
||||
readonly UniTask task;
|
||||
|
||||
[DebuggerHidden]
|
||||
public Awaiter(UniTask task)
|
||||
{
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public bool IsCompleted => task.IsCompleted;
|
||||
|
||||
[DebuggerHidden]
|
||||
public AwaiterStatus Status => task.Status;
|
||||
|
||||
[DebuggerHidden]
|
||||
public void GetResult() => task.GetResult();
|
||||
|
||||
[DebuggerHidden]
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
if (task.awaiter != null)
|
||||
{
|
||||
task.awaiter.OnCompleted(continuation);
|
||||
}
|
||||
else
|
||||
{
|
||||
continuation();
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
if (task.awaiter != null)
|
||||
{
|
||||
task.awaiter.UnsafeOnCompleted(continuation);
|
||||
}
|
||||
else
|
||||
{
|
||||
continuation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lightweight unity specified task-like object.
|
||||
/// </summary>
|
||||
[AsyncMethodBuilder(typeof(AsyncUniTaskMethodBuilder<>))]
|
||||
public struct UniTask<T> : IEquatable<UniTask<T>>
|
||||
{
|
||||
readonly T result;
|
||||
readonly IAwaiter<T> awaiter;
|
||||
|
||||
[DebuggerHidden]
|
||||
public UniTask(T result)
|
||||
{
|
||||
this.result = result;
|
||||
this.awaiter = null;
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public UniTask(IAwaiter<T> awaiter)
|
||||
{
|
||||
this.result = default(T);
|
||||
this.awaiter = awaiter;
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public UniTask(Func<UniTask<T>> factory)
|
||||
{
|
||||
this.result = default(T);
|
||||
this.awaiter = new LazyPromise<T>(factory);
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public AwaiterStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return awaiter == null ? AwaiterStatus.Succeeded : awaiter.Status;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
return awaiter == null ? true : awaiter.IsCompleted;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public T Result
|
||||
{
|
||||
get
|
||||
{
|
||||
if (awaiter == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return awaiter.GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public Awaiter GetAwaiter()
|
||||
{
|
||||
return new Awaiter(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns (bool IsCanceled, T Result) instead of throws OperationCanceledException.
|
||||
/// </summary>
|
||||
public UniTask<(bool IsCanceled, T Result)> SuppressCancellationThrow()
|
||||
{
|
||||
var status = Status;
|
||||
if (status == AwaiterStatus.Succeeded)
|
||||
{
|
||||
return new UniTask<(bool, T)>((false, Result));
|
||||
}
|
||||
else if (status == AwaiterStatus.Canceled)
|
||||
{
|
||||
return new UniTask<(bool, T)>((true, default(T)));
|
||||
}
|
||||
return new UniTask<(bool, T)>(new IsCanceledAwaiter(awaiter));
|
||||
}
|
||||
|
||||
public bool Equals(UniTask<T> other)
|
||||
{
|
||||
if (this.awaiter == null && other.awaiter == null)
|
||||
{
|
||||
return EqualityComparer<T>.Default.Equals(this.result, other.result);
|
||||
}
|
||||
else if (this.awaiter != null && other.awaiter != null)
|
||||
{
|
||||
return this.awaiter == other.awaiter;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
if (this.awaiter == null)
|
||||
{
|
||||
if (result == null) return 0;
|
||||
return result.GetHashCode();
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.awaiter.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (this.awaiter == null) ? result.ToString()
|
||||
: (this.awaiter.Status == AwaiterStatus.Succeeded) ? this.awaiter.GetResult().ToString()
|
||||
: "(" + this.awaiter.Status + ")";
|
||||
}
|
||||
|
||||
public static implicit operator UniTask(UniTask<T> task)
|
||||
{
|
||||
if (task.awaiter != null)
|
||||
{
|
||||
return new UniTask(task.awaiter);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new UniTask();
|
||||
}
|
||||
}
|
||||
|
||||
class IsCanceledAwaiter : IAwaiter<(bool, T)>
|
||||
{
|
||||
readonly IAwaiter<T> awaiter;
|
||||
|
||||
public IsCanceledAwaiter(IAwaiter<T> awaiter)
|
||||
{
|
||||
this.awaiter = awaiter;
|
||||
}
|
||||
|
||||
public bool IsCompleted => awaiter.IsCompleted;
|
||||
|
||||
public AwaiterStatus Status => awaiter.Status;
|
||||
|
||||
public (bool, T) GetResult()
|
||||
{
|
||||
if (awaiter.Status == AwaiterStatus.Canceled)
|
||||
{
|
||||
return (true, default(T));
|
||||
}
|
||||
return (false, awaiter.GetResult());
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
awaiter.OnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
awaiter.UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
awaiter.GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
public struct Awaiter : IAwaiter<T>
|
||||
{
|
||||
readonly UniTask<T> task;
|
||||
|
||||
[DebuggerHidden]
|
||||
public Awaiter(UniTask<T> task)
|
||||
{
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public bool IsCompleted => task.IsCompleted;
|
||||
|
||||
[DebuggerHidden]
|
||||
public AwaiterStatus Status => task.Status;
|
||||
|
||||
[DebuggerHidden]
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
[DebuggerHidden]
|
||||
public T GetResult() => task.Result;
|
||||
|
||||
[DebuggerHidden]
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
if (task.awaiter != null)
|
||||
{
|
||||
task.awaiter.OnCompleted(continuation);
|
||||
}
|
||||
else
|
||||
{
|
||||
continuation();
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
if (task.awaiter != null)
|
||||
{
|
||||
task.awaiter.UnsafeOnCompleted(continuation);
|
||||
}
|
||||
else
|
||||
{
|
||||
continuation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,413 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Threading;
|
||||
using UniRx.Async.Internal;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
internal class ExceptionHolder
|
||||
{
|
||||
ExceptionDispatchInfo exception;
|
||||
bool calledGet = false;
|
||||
|
||||
public ExceptionHolder(ExceptionDispatchInfo exception)
|
||||
{
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public ExceptionDispatchInfo GetException()
|
||||
{
|
||||
if (!calledGet)
|
||||
{
|
||||
calledGet = true;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
return exception;
|
||||
}
|
||||
|
||||
~ExceptionHolder()
|
||||
{
|
||||
UniTaskScheduler.PublishUnobservedTaskException(exception.SourceException);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IResolvePromise
|
||||
{
|
||||
bool TrySetResult();
|
||||
}
|
||||
|
||||
public interface IResolvePromise<T>
|
||||
{
|
||||
bool TrySetResult(T value);
|
||||
}
|
||||
|
||||
public interface IRejectPromise
|
||||
{
|
||||
bool TrySetException(Exception exception);
|
||||
}
|
||||
|
||||
public interface ICancelPromise
|
||||
{
|
||||
bool TrySetCanceled();
|
||||
}
|
||||
|
||||
public interface IPromise<T> : IResolvePromise<T>, IRejectPromise, ICancelPromise
|
||||
{
|
||||
}
|
||||
|
||||
public interface IPromise : IResolvePromise, IRejectPromise, ICancelPromise
|
||||
{
|
||||
}
|
||||
|
||||
public class UniTaskCompletionSource : IAwaiter, IPromise
|
||||
{
|
||||
// State(= AwaiterStatus)
|
||||
const int Pending = 0;
|
||||
const int Succeeded = 1;
|
||||
const int Faulted = 2;
|
||||
const int Canceled = 3;
|
||||
|
||||
int state = 0;
|
||||
bool handled = false;
|
||||
ExceptionHolder exception;
|
||||
object continuation; // action or list
|
||||
|
||||
AwaiterStatus IAwaiter.Status => (AwaiterStatus)state;
|
||||
|
||||
bool IAwaiter.IsCompleted => state != Pending;
|
||||
|
||||
public UniTask Task => new UniTask(this);
|
||||
|
||||
public UniTaskCompletionSource()
|
||||
{
|
||||
TaskTracker.TrackActiveTask(this, 2);
|
||||
}
|
||||
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
internal void MarkHandled()
|
||||
{
|
||||
if (!handled)
|
||||
{
|
||||
handled = true;
|
||||
TaskTracker.RemoveTracking(this);
|
||||
}
|
||||
}
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
MarkHandled();
|
||||
|
||||
if (state == Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (state == Faulted)
|
||||
{
|
||||
exception.GetException().Throw();
|
||||
}
|
||||
else if (state == Canceled)
|
||||
{
|
||||
if (exception != null)
|
||||
{
|
||||
exception.GetException().Throw(); // guranteed operation canceled exception.
|
||||
}
|
||||
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
else // Pending
|
||||
{
|
||||
throw new NotSupportedException("UniTask does not allow call GetResult directly when task not completed. Please use 'await'.");
|
||||
}
|
||||
}
|
||||
|
||||
void ICriticalNotifyCompletion.UnsafeOnCompleted(Action action)
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref continuation, (object)action, null) == null)
|
||||
{
|
||||
if (state != Pending)
|
||||
{
|
||||
TryInvokeContinuation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var c = continuation;
|
||||
if (c is Action)
|
||||
{
|
||||
var list = new List<Action>();
|
||||
list.Add((Action)c);
|
||||
list.Add(action);
|
||||
if (Interlocked.CompareExchange(ref continuation, list, c) == c)
|
||||
{
|
||||
goto TRYINVOKE;
|
||||
}
|
||||
}
|
||||
|
||||
var l = (List<Action>)continuation;
|
||||
lock (l)
|
||||
{
|
||||
l.Add(action);
|
||||
}
|
||||
|
||||
TRYINVOKE:
|
||||
if (state != Pending)
|
||||
{
|
||||
TryInvokeContinuation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TryInvokeContinuation()
|
||||
{
|
||||
var c = Interlocked.Exchange(ref continuation, null);
|
||||
if (c != null)
|
||||
{
|
||||
if (c is Action)
|
||||
{
|
||||
((Action)c).Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
var l = (List<Action>)c;
|
||||
var cnt = l.Count;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
l[i].Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool TrySetResult()
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref state, Succeeded, Pending) == Pending)
|
||||
{
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TrySetException(Exception exception)
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref state, Faulted, Pending) == Pending)
|
||||
{
|
||||
this.exception = new ExceptionHolder(ExceptionDispatchInfo.Capture(exception));
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TrySetCanceled()
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref state, Canceled, Pending) == Pending)
|
||||
{
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TrySetCanceled(OperationCanceledException exception)
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref state, Canceled, Pending) == Pending)
|
||||
{
|
||||
this.exception = new ExceptionHolder(ExceptionDispatchInfo.Capture(exception));
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void INotifyCompletion.OnCompleted(Action continuation)
|
||||
{
|
||||
((ICriticalNotifyCompletion)this).UnsafeOnCompleted(continuation);
|
||||
}
|
||||
}
|
||||
|
||||
public class UniTaskCompletionSource<T> : IAwaiter<T>, IPromise<T>
|
||||
{
|
||||
// State(= AwaiterStatus)
|
||||
const int Pending = 0;
|
||||
const int Succeeded = 1;
|
||||
const int Faulted = 2;
|
||||
const int Canceled = 3;
|
||||
|
||||
int state = 0;
|
||||
T value;
|
||||
bool handled = false;
|
||||
ExceptionHolder exception;
|
||||
object continuation; // action or list
|
||||
|
||||
bool IAwaiter.IsCompleted => state != Pending;
|
||||
|
||||
public UniTask<T> Task => new UniTask<T>(this);
|
||||
public UniTask UnitTask => new UniTask(this);
|
||||
|
||||
AwaiterStatus IAwaiter.Status => (AwaiterStatus)state;
|
||||
|
||||
public UniTaskCompletionSource()
|
||||
{
|
||||
TaskTracker.TrackActiveTask(this, 2);
|
||||
}
|
||||
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
internal void MarkHandled()
|
||||
{
|
||||
if (!handled)
|
||||
{
|
||||
handled = true;
|
||||
TaskTracker.RemoveTracking(this);
|
||||
}
|
||||
}
|
||||
|
||||
T IAwaiter<T>.GetResult()
|
||||
{
|
||||
MarkHandled();
|
||||
|
||||
if (state == Succeeded)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
else if (state == Faulted)
|
||||
{
|
||||
exception.GetException().Throw();
|
||||
}
|
||||
else if (state == Canceled)
|
||||
{
|
||||
if (exception != null)
|
||||
{
|
||||
exception.GetException().Throw(); // guranteed operation canceled exception.
|
||||
}
|
||||
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
else // Pending
|
||||
{
|
||||
throw new NotSupportedException("UniTask does not allow call GetResult directly when task not completed. Please use 'await'.");
|
||||
}
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
void ICriticalNotifyCompletion.UnsafeOnCompleted(Action action)
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref continuation, (object)action, null) == null)
|
||||
{
|
||||
if (state != Pending)
|
||||
{
|
||||
TryInvokeContinuation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var c = continuation;
|
||||
if (c is Action)
|
||||
{
|
||||
var list = new List<Action>();
|
||||
list.Add((Action)c);
|
||||
list.Add(action);
|
||||
if (Interlocked.CompareExchange(ref continuation, list, c) == c)
|
||||
{
|
||||
goto TRYINVOKE;
|
||||
}
|
||||
}
|
||||
|
||||
var l = (List<Action>)continuation;
|
||||
lock (l)
|
||||
{
|
||||
l.Add(action);
|
||||
}
|
||||
|
||||
TRYINVOKE:
|
||||
if (state != Pending)
|
||||
{
|
||||
TryInvokeContinuation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TryInvokeContinuation()
|
||||
{
|
||||
var c = Interlocked.Exchange(ref continuation, null);
|
||||
if (c != null)
|
||||
{
|
||||
if (c is Action)
|
||||
{
|
||||
((Action)c).Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
var l = (List<Action>)c;
|
||||
var cnt = l.Count;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
l[i].Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool TrySetResult(T value)
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref state, Succeeded, Pending) == Pending)
|
||||
{
|
||||
this.value = value;
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TrySetException(Exception exception)
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref state, Faulted, Pending) == Pending)
|
||||
{
|
||||
this.exception = new ExceptionHolder(ExceptionDispatchInfo.Capture(exception));
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TrySetCanceled()
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref state, Canceled, Pending) == Pending)
|
||||
{
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TrySetCanceled(OperationCanceledException exception)
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref state, Canceled, Pending) == Pending)
|
||||
{
|
||||
this.exception = new ExceptionHolder(ExceptionDispatchInfo.Capture(exception));
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
((IAwaiter<T>)this).GetResult();
|
||||
}
|
||||
|
||||
void INotifyCompletion.OnCompleted(Action continuation)
|
||||
{
|
||||
((ICriticalNotifyCompletion)this).UnsafeOnCompleted(continuation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,53 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public static partial class UniTaskExtensions
|
||||
{
|
||||
// shorthand of WhenAll
|
||||
|
||||
public static UniTask.Awaiter GetAwaiter(this IEnumerable<UniTask> tasks)
|
||||
{
|
||||
return UniTask.WhenAll(tasks).GetAwaiter();
|
||||
}
|
||||
|
||||
public static UniTask<T[]>.Awaiter GetAwaiter<T>(this IEnumerable<UniTask<T>> tasks)
|
||||
{
|
||||
return UniTask.WhenAll(tasks).GetAwaiter();
|
||||
}
|
||||
|
||||
public static UniTask<(T1 result1, T2 result2)>.Awaiter GetAwaiter<T1, T2>(this (UniTask<T1> task1, UniTask<T2> task2) tasks)
|
||||
{
|
||||
return UniTask.WhenAll(tasks.task1, tasks.task2).GetAwaiter();
|
||||
}
|
||||
|
||||
public static UniTask<(T1 result1, T2 result2, T3 result3)> WhenAll<T1, T2, T3>(this (UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3) tasks)
|
||||
{
|
||||
return UniTask.WhenAll<T1, T2, T3>(tasks.task1, tasks.task2, tasks.task3);
|
||||
}
|
||||
|
||||
public static UniTask<(T1 result1, T2 result2, T3 result3, T4 result4)> WhenAll<T1, T2, T3, T4>(this (UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4) tasks)
|
||||
{
|
||||
return UniTask.WhenAll<T1, T2, T3, T4>(tasks.task1, tasks.task2, tasks.task3, tasks.task4);
|
||||
}
|
||||
|
||||
public static UniTask<(T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)> WhenAll<T1, T2, T3, T4, T5>(this (UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5) tasks)
|
||||
{
|
||||
return UniTask.WhenAll<T1, T2, T3, T4, T5>(tasks.task1, tasks.task2, tasks.task3, tasks.task4, tasks.task5);
|
||||
}
|
||||
|
||||
public static UniTask<(T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)> WhenAll<T1, T2, T3, T4, T5, T6>(this (UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6) tasks)
|
||||
{
|
||||
return UniTask.WhenAll<T1, T2, T3, T4, T5, T6>(tasks.task1, tasks.task2, tasks.task3, tasks.task4, tasks.task5, tasks.task6);
|
||||
}
|
||||
|
||||
public static UniTask<(T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)> WhenAll<T1, T2, T3, T4, T5, T6, T7>(this (UniTask<T1> task1, UniTask<T2> task2, UniTask<T3> task3, UniTask<T4> task4, UniTask<T5> task5, UniTask<T6> task6, UniTask<T7> task7) tasks)
|
||||
{
|
||||
return UniTask.WhenAll<T1, T2, T3, T4, T5, T6, T7>(tasks.task1, tasks.task2, tasks.task3, tasks.task4, tasks.task5, tasks.task6, tasks.task7);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,140 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) && ENABLE_MANAGED_JOBS
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using UniRx.Async.Internal;
|
||||
using Unity.Jobs;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public static partial class UnityAsyncExtensions
|
||||
{
|
||||
public static IAwaiter GetAwaiter(this JobHandle jobHandle)
|
||||
{
|
||||
var awaiter = new JobHandleAwaiter(jobHandle, CancellationToken.None);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, awaiter);
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.PreUpdate, awaiter);
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter);
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.PreLateUpdate, awaiter);
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.PostLateUpdate, awaiter);
|
||||
}
|
||||
return awaiter;
|
||||
}
|
||||
|
||||
public static UniTask ToUniTask(this JobHandle jobHandle, CancellationToken cancellation = default(CancellationToken))
|
||||
{
|
||||
var awaiter = new JobHandleAwaiter(jobHandle, cancellation);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, awaiter);
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.PreUpdate, awaiter);
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter);
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.PreLateUpdate, awaiter);
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.PostLateUpdate, awaiter);
|
||||
}
|
||||
return new UniTask(awaiter);
|
||||
}
|
||||
|
||||
public static UniTask ConfigureAwait(this JobHandle jobHandle, PlayerLoopTiming waitTiming, CancellationToken cancellation = default(CancellationToken))
|
||||
{
|
||||
var awaiter = new JobHandleAwaiter(jobHandle, cancellation);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(waitTiming, awaiter);
|
||||
}
|
||||
return new UniTask(awaiter);
|
||||
}
|
||||
|
||||
class JobHandleAwaiter : IAwaiter, IPlayerLoopItem
|
||||
{
|
||||
JobHandle jobHandle;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
Action continuation;
|
||||
|
||||
public JobHandleAwaiter(JobHandle jobHandle, CancellationToken cancellationToken, int skipFrame = 2)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: jobHandle.IsCompleted ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
||||
this.jobHandle = jobHandle;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.status = AwaiterStatus.Pending;
|
||||
this.continuation = null;
|
||||
|
||||
TaskTracker.TrackActiveTask(this, skipFrame);
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (status == AwaiterStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
||||
Error.ThrowNotYetCompleted();
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
// Call jobHandle.Complete after finished.
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, new JobHandleAwaiter(jobHandle, CancellationToken.None, 1));
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (jobHandle.IsCompleted)
|
||||
{
|
||||
jobHandle.Complete();
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
||||
// cleanup
|
||||
TaskTracker.RemoveTracking(this);
|
||||
this.continuation = null;
|
||||
this.cancellationToken = CancellationToken.None;
|
||||
this.jobHandle = default(JobHandle);
|
||||
|
||||
if (cont != null) cont.Invoke();
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||
this.continuation = continuation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,898 +0,0 @@
|
||||
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using UniRx.Async.Internal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public static partial class UnityAsyncExtensions
|
||||
{
|
||||
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation)
|
||||
{
|
||||
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
|
||||
return new AsyncOperationAwaiter(asyncOperation);
|
||||
}
|
||||
|
||||
public static UniTask ToUniTask(this AsyncOperation asyncOperation)
|
||||
{
|
||||
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
|
||||
return new UniTask(new AsyncOperationAwaiter(asyncOperation));
|
||||
}
|
||||
|
||||
public static UniTask ConfigureAwait(this AsyncOperation asyncOperation, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken))
|
||||
{
|
||||
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
|
||||
|
||||
var awaiter = new AsyncOperationConfiguredAwaiter(asyncOperation, progress, cancellation);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(timing, awaiter);
|
||||
}
|
||||
return new UniTask(awaiter);
|
||||
}
|
||||
|
||||
public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest resourceRequest)
|
||||
{
|
||||
Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest));
|
||||
return new ResourceRequestAwaiter(resourceRequest);
|
||||
}
|
||||
|
||||
public static UniTask<UnityEngine.Object> ToUniTask(this ResourceRequest resourceRequest)
|
||||
{
|
||||
Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest));
|
||||
return new UniTask<UnityEngine.Object>(new ResourceRequestAwaiter(resourceRequest));
|
||||
}
|
||||
|
||||
public static UniTask<UnityEngine.Object> ConfigureAwait(this ResourceRequest resourceRequest, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken))
|
||||
{
|
||||
Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest));
|
||||
|
||||
var awaiter = new ResourceRequestConfiguredAwaiter(resourceRequest, progress, cancellation);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(timing, awaiter);
|
||||
}
|
||||
return new UniTask<UnityEngine.Object>(awaiter);
|
||||
}
|
||||
|
||||
public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest resourceRequest)
|
||||
{
|
||||
Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest));
|
||||
return new AssetBundleRequestAwaiter(resourceRequest);
|
||||
}
|
||||
|
||||
public static UniTask<UnityEngine.Object> ToUniTask(this AssetBundleRequest resourceRequest)
|
||||
{
|
||||
Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest));
|
||||
return new UniTask<UnityEngine.Object>(new AssetBundleRequestAwaiter(resourceRequest));
|
||||
}
|
||||
|
||||
public static UniTask<UnityEngine.Object> ConfigureAwait(this AssetBundleRequest resourceRequest, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken))
|
||||
{
|
||||
Error.ThrowArgumentNullException(resourceRequest, nameof(resourceRequest));
|
||||
|
||||
var awaiter = new AssetBundleRequestConfiguredAwaiter(resourceRequest, progress, cancellation);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(timing, awaiter);
|
||||
}
|
||||
return new UniTask<UnityEngine.Object>(awaiter);
|
||||
}
|
||||
|
||||
#if ENABLE_WWW
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
#pragma warning disable CS0618
|
||||
#endif
|
||||
|
||||
public static IAwaiter GetAwaiter(this WWW www)
|
||||
{
|
||||
Error.ThrowArgumentNullException(www, nameof(www));
|
||||
|
||||
var awaiter = new WWWConfiguredAwaiter(www, null, CancellationToken.None);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter);
|
||||
}
|
||||
return awaiter;
|
||||
}
|
||||
|
||||
public static UniTask ToUniTask(this WWW www)
|
||||
{
|
||||
Error.ThrowArgumentNullException(www, nameof(www));
|
||||
|
||||
var awaiter = new WWWConfiguredAwaiter(www, null, CancellationToken.None);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter);
|
||||
}
|
||||
return new UniTask(awaiter);
|
||||
}
|
||||
|
||||
public static UniTask ConfigureAwait(this WWW www, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken))
|
||||
{
|
||||
Error.ThrowArgumentNullException(www, nameof(www));
|
||||
|
||||
var awaiter = new WWWConfiguredAwaiter(www, progress, cancellation);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(timing, awaiter);
|
||||
}
|
||||
return new UniTask(awaiter);
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
#pragma warning restore CS0618
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLE_UNITYWEBREQUEST
|
||||
|
||||
public static UnityWebRequestAsyncOperationAwaiter GetAwaiter(this UnityWebRequestAsyncOperation asyncOperation)
|
||||
{
|
||||
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
|
||||
return new UnityWebRequestAsyncOperationAwaiter(asyncOperation);
|
||||
}
|
||||
|
||||
public static UniTask<UnityWebRequest> ToUniTask(this UnityWebRequestAsyncOperation asyncOperation)
|
||||
{
|
||||
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
|
||||
return new UniTask<UnityWebRequest>(new UnityWebRequestAsyncOperationAwaiter(asyncOperation));
|
||||
}
|
||||
|
||||
public static UniTask<UnityWebRequest> ConfigureAwait(this UnityWebRequestAsyncOperation asyncOperation, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken))
|
||||
{
|
||||
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
|
||||
|
||||
var awaiter = new UnityWebRequestAsyncOperationConfiguredAwaiter(asyncOperation, progress, cancellation);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(timing, awaiter);
|
||||
}
|
||||
return new UniTask<UnityWebRequest>(awaiter);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
public struct AsyncOperationAwaiter : IAwaiter
|
||||
{
|
||||
AsyncOperation asyncOperation;
|
||||
Action<AsyncOperation> continuationAction;
|
||||
AwaiterStatus status;
|
||||
|
||||
public AsyncOperationAwaiter(AsyncOperation asyncOperation)
|
||||
{
|
||||
this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending;
|
||||
this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation;
|
||||
this.continuationAction = null;
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return;
|
||||
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
// first timing of call
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error.ThrowNotYetCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
if (continuationAction != null)
|
||||
{
|
||||
asyncOperation.completed -= continuationAction;
|
||||
asyncOperation = null; // remove reference.
|
||||
continuationAction = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
asyncOperation = null; // remove reference.
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction);
|
||||
continuationAction = continuation.AsFuncOfT<AsyncOperation>();
|
||||
asyncOperation.completed += continuationAction;
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncOperationConfiguredAwaiter : IAwaiter, IPlayerLoopItem
|
||||
{
|
||||
AsyncOperation asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
Action continuation;
|
||||
|
||||
public AsyncOperationConfiguredAwaiter(AsyncOperation asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
||||
this.asyncOperation = asyncOperation;
|
||||
this.progress = progress;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.continuation = null;
|
||||
|
||||
TaskTracker.TrackActiveTask(this, 2);
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (status == AwaiterStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
||||
Error.ThrowNotYetCompleted();
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progress != null)
|
||||
{
|
||||
progress.Report(asyncOperation.progress);
|
||||
}
|
||||
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
||||
// cleanup
|
||||
TaskTracker.RemoveTracking(this);
|
||||
this.continuation = null;
|
||||
this.cancellationToken = CancellationToken.None;
|
||||
this.progress = null;
|
||||
this.asyncOperation = null;
|
||||
|
||||
if (cont != null) cont.Invoke();
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||
this.continuation = continuation;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ResourceRequestAwaiter : IAwaiter<UnityEngine.Object>
|
||||
{
|
||||
ResourceRequest asyncOperation;
|
||||
Action<AsyncOperation> continuationAction;
|
||||
AwaiterStatus status;
|
||||
UnityEngine.Object result;
|
||||
|
||||
public ResourceRequestAwaiter(ResourceRequest asyncOperation)
|
||||
{
|
||||
this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending;
|
||||
this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation;
|
||||
this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.asset : null;
|
||||
this.continuationAction = null;
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
public UnityEngine.Object GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
// first timing of call
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error.ThrowNotYetCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
this.result = asyncOperation.asset;
|
||||
|
||||
if (continuationAction != null)
|
||||
{
|
||||
asyncOperation.completed -= continuationAction;
|
||||
asyncOperation = null; // remove reference.
|
||||
continuationAction = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
asyncOperation = null; // remove reference.
|
||||
}
|
||||
|
||||
return this.result;
|
||||
}
|
||||
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction);
|
||||
continuationAction = continuation.AsFuncOfT<AsyncOperation>();
|
||||
asyncOperation.completed += continuationAction;
|
||||
}
|
||||
}
|
||||
|
||||
class ResourceRequestConfiguredAwaiter : IAwaiter<UnityEngine.Object>, IPlayerLoopItem
|
||||
{
|
||||
ResourceRequest asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
Action continuation;
|
||||
UnityEngine.Object result;
|
||||
|
||||
public ResourceRequestConfiguredAwaiter(ResourceRequest asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
|
||||
if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.asset;
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
||||
this.asyncOperation = asyncOperation;
|
||||
this.progress = progress;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.continuation = null;
|
||||
this.result = null;
|
||||
|
||||
TaskTracker.TrackActiveTask(this, 2);
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
public UnityEngine.Object GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
||||
return Error.ThrowNotYetCompleted<UnityEngine.Object>();
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progress != null)
|
||||
{
|
||||
progress.Report(asyncOperation.progress);
|
||||
}
|
||||
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
this.result = asyncOperation.asset;
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
||||
// cleanup
|
||||
TaskTracker.RemoveTracking(this);
|
||||
this.continuation = null;
|
||||
this.cancellationToken = CancellationToken.None;
|
||||
this.progress = null;
|
||||
this.asyncOperation = null;
|
||||
|
||||
if (cont != null) cont.Invoke();
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||
this.continuation = continuation;
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||
this.continuation = continuation;
|
||||
}
|
||||
}
|
||||
|
||||
public struct AssetBundleRequestAwaiter : IAwaiter<UnityEngine.Object>
|
||||
{
|
||||
AssetBundleRequest asyncOperation;
|
||||
Action<AsyncOperation> continuationAction;
|
||||
AwaiterStatus status;
|
||||
UnityEngine.Object result;
|
||||
|
||||
public AssetBundleRequestAwaiter(AssetBundleRequest asyncOperation)
|
||||
{
|
||||
this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending;
|
||||
this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation;
|
||||
this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.asset : null;
|
||||
this.continuationAction = null;
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
public UnityEngine.Object GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
// first timing of call
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error.ThrowNotYetCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
this.result = asyncOperation.asset;
|
||||
|
||||
if (continuationAction != null)
|
||||
{
|
||||
asyncOperation.completed -= continuationAction;
|
||||
asyncOperation = null; // remove reference.
|
||||
continuationAction = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
asyncOperation = null; // remove reference.
|
||||
}
|
||||
|
||||
return this.result;
|
||||
}
|
||||
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction);
|
||||
continuationAction = continuation.AsFuncOfT<AsyncOperation>();
|
||||
asyncOperation.completed += continuationAction;
|
||||
}
|
||||
}
|
||||
|
||||
class AssetBundleRequestConfiguredAwaiter : IAwaiter<UnityEngine.Object>, IPlayerLoopItem
|
||||
{
|
||||
AssetBundleRequest asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
Action continuation;
|
||||
UnityEngine.Object result;
|
||||
|
||||
public AssetBundleRequestConfiguredAwaiter(AssetBundleRequest asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
|
||||
if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.asset;
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
||||
this.asyncOperation = asyncOperation;
|
||||
this.progress = progress;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.continuation = null;
|
||||
this.result = null;
|
||||
|
||||
TaskTracker.TrackActiveTask(this, 2);
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
public UnityEngine.Object GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
||||
return Error.ThrowNotYetCompleted<UnityEngine.Object>();
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progress != null)
|
||||
{
|
||||
progress.Report(asyncOperation.progress);
|
||||
}
|
||||
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
this.result = asyncOperation.asset;
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
||||
// cleanup
|
||||
TaskTracker.RemoveTracking(this);
|
||||
this.continuation = null;
|
||||
this.cancellationToken = CancellationToken.None;
|
||||
this.progress = null;
|
||||
this.asyncOperation = null;
|
||||
|
||||
if (cont != null) cont.Invoke();
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||
this.continuation = continuation;
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||
this.continuation = continuation;
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_WWW
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
#pragma warning disable CS0618
|
||||
#endif
|
||||
|
||||
class WWWConfiguredAwaiter : IAwaiter, IPlayerLoopItem
|
||||
{
|
||||
WWW asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
Action continuation;
|
||||
|
||||
public WWWConfiguredAwaiter(WWW asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
||||
this.asyncOperation = asyncOperation;
|
||||
this.progress = progress;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.continuation = null;
|
||||
|
||||
TaskTracker.TrackActiveTask(this, 2);
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (status == AwaiterStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
||||
Error.ThrowNotYetCompleted();
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progress != null)
|
||||
{
|
||||
progress.Report(asyncOperation.progress);
|
||||
}
|
||||
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
||||
// cleanup
|
||||
TaskTracker.RemoveTracking(this);
|
||||
this.continuation = null;
|
||||
this.cancellationToken = CancellationToken.None;
|
||||
this.progress = null;
|
||||
this.asyncOperation = null;
|
||||
|
||||
if (cont != null) cont.Invoke();
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||
this.continuation = continuation;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
#pragma warning restore CS0618
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLE_UNITYWEBREQUEST
|
||||
|
||||
public struct UnityWebRequestAsyncOperationAwaiter : IAwaiter<UnityWebRequest>
|
||||
{
|
||||
UnityWebRequestAsyncOperation asyncOperation;
|
||||
Action<AsyncOperation> continuationAction;
|
||||
AwaiterStatus status;
|
||||
UnityWebRequest result;
|
||||
|
||||
public UnityWebRequestAsyncOperationAwaiter(UnityWebRequestAsyncOperation asyncOperation)
|
||||
{
|
||||
this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending;
|
||||
this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation;
|
||||
this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.webRequest : null;
|
||||
this.continuationAction = null;
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
public UnityWebRequest GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
// first timing of call
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error.ThrowNotYetCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
this.result = asyncOperation.webRequest;
|
||||
|
||||
if (continuationAction != null)
|
||||
{
|
||||
asyncOperation.completed -= continuationAction;
|
||||
asyncOperation = null; // remove reference.
|
||||
continuationAction = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
asyncOperation = null; // remove reference.
|
||||
}
|
||||
|
||||
|
||||
return this.result;
|
||||
}
|
||||
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(continuationAction);
|
||||
continuationAction = continuation.AsFuncOfT<AsyncOperation>();
|
||||
asyncOperation.completed += continuationAction;
|
||||
}
|
||||
}
|
||||
|
||||
class UnityWebRequestAsyncOperationConfiguredAwaiter : IAwaiter<UnityWebRequest>, IPlayerLoopItem
|
||||
{
|
||||
UnityWebRequestAsyncOperation asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
Action continuation;
|
||||
UnityWebRequest result;
|
||||
|
||||
public UnityWebRequestAsyncOperationConfiguredAwaiter(UnityWebRequestAsyncOperation asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
|
||||
if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.webRequest;
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
||||
this.asyncOperation = asyncOperation;
|
||||
this.progress = progress;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.continuation = null;
|
||||
this.result = null;
|
||||
|
||||
TaskTracker.TrackActiveTask(this, 2);
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
public UnityWebRequest GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
||||
return Error.ThrowNotYetCompleted<UnityWebRequest>();
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progress != null)
|
||||
{
|
||||
progress.Report(asyncOperation.progress);
|
||||
}
|
||||
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
this.result = asyncOperation.webRequest;
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
||||
// cleanup
|
||||
TaskTracker.RemoveTracking(this);
|
||||
this.continuation = null;
|
||||
this.cancellationToken = CancellationToken.None;
|
||||
this.progress = null;
|
||||
this.asyncOperation = null;
|
||||
|
||||
if (cont != null) cont.Invoke();
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||
this.continuation = continuation;
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||
this.continuation = continuation;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user