commit
b8260d4e91
|
@ -1,114 +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 >>
|
|
||||||
go:
|
|
||||||
docker:
|
|
||||||
- image: circleci/golang
|
|
||||||
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
|
|
||||||
# upload to github by ghr
|
|
||||||
upload-github:
|
|
||||||
executor: go
|
|
||||||
steps:
|
|
||||||
- attach_workspace:
|
|
||||||
at: .
|
|
||||||
- run: go get github.com/tcnksm/ghr
|
|
||||||
- run: ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} ${CIRCLE_TAG} .
|
|
||||||
- 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-test:
|
|
||||||
unity_version: 2019.1.2f1
|
|
||||||
unity_license: ${UNITY_LICENSE_2019_1}
|
|
||||||
filters:
|
|
||||||
tags:
|
|
||||||
only: /.*/
|
|
||||||
# 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}
|
|
||||||
- build-and-create-package:
|
|
||||||
unity_version: 2019.1.2f1
|
|
||||||
unity_license: ${UNITY_LICENSE_2019_1}
|
|
||||||
filters:
|
|
||||||
tags:
|
|
||||||
only: /^\d\.\d\.\d.*/
|
|
||||||
branches:
|
|
||||||
ignore: /.*/
|
|
||||||
- upload-github:
|
|
||||||
requires:
|
|
||||||
- build-and-create-package
|
|
||||||
filters:
|
|
||||||
tags:
|
|
||||||
only: /^\d\.\d\.\d.*/
|
|
||||||
branches:
|
|
||||||
ignore: /.*/
|
|
|
@ -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
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 and pack
|
||||||
|
- run: dotnet build -c Release -p:Version=${{ env.GIT_TAG }}
|
||||||
|
- run: dotnet test -c Release --no-build
|
||||||
|
- run: dotnet pack ./src/UniTask.NetCore/UniTask.NetCore.csproj -c Release --no-build -p:Version=${{ env.GIT_TAG }}
|
||||||
|
|
||||||
|
# Store artifacts.
|
||||||
|
- uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: nuget
|
||||||
|
path: ./src/UniTask.NetCore/bin/Release/UniTask.${{ 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/UniTask
|
||||||
|
|
||||||
|
# Store artifacts.
|
||||||
|
- uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: UniTask.unitypackage.zip
|
||||||
|
path: ./src/UniTask/*.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: ./UniTask.${{ env.GIT_TAG }}.unitypackage/UniTask.${{ env.GIT_TAG }}.unitypackage
|
||||||
|
asset_name: UniTask.${{ env.GIT_TAG }}.unitypackage
|
||||||
|
asset_content_type: application/octet-stream
|
|
@ -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"
|
|
@ -147,3 +147,15 @@ Assembly-CSharp-Editor\.csproj
|
||||||
UniRx\.Async\.unitypackage
|
UniRx\.Async\.unitypackage
|
||||||
|
|
||||||
UniRx.Async.Tests.Editor.csproj
|
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
|
||||||
|
|
||||||
|
src/UniTask/UniTask.Linq.csproj
|
||||||
|
|
|
@ -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" || Path.GetExtension(x) == ".meta")
|
|
||||||
.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,60 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
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;
|
|
||||||
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
okButton.onClick.AddListener(() =>
|
|
||||||
{
|
|
||||||
FooAsync().Forget();
|
|
||||||
});
|
|
||||||
cancelButton.onClick.AddListener(() =>
|
|
||||||
{
|
|
||||||
BarAsync().Forget();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async UniTask<int> FooAsync()
|
|
||||||
{
|
|
||||||
// use F10, will crash.
|
|
||||||
var loop = int.Parse("9");
|
|
||||||
await UniTask.DelayFrame(loop);
|
|
||||||
|
|
||||||
Debug.Log("OK");
|
|
||||||
await UniTask.DelayFrame(loop);
|
|
||||||
|
|
||||||
Debug.Log("Again");
|
|
||||||
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
async UniTaskVoid BarAsync()
|
|
||||||
{
|
|
||||||
var loop = int.Parse("10");
|
|
||||||
|
|
||||||
|
|
||||||
var foo = await UniTask.FromResult(100);
|
|
||||||
|
|
||||||
Debug.Log("OK");
|
|
||||||
|
|
||||||
|
|
||||||
Debug.Log("Again");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,76 +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
|
|
||||||
{
|
|
||||||
public static class CancellationTokenExtensions
|
|
||||||
{
|
|
||||||
static readonly Action<object> cancellationTokenCallback = Callback;
|
|
||||||
|
|
||||||
public static (UniTask, CancellationTokenRegistration) ToUniTask(this CancellationToken cts)
|
|
||||||
{
|
|
||||||
if (cts.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
return (UniTask.FromCanceled(cts), default(CancellationTokenRegistration));
|
|
||||||
}
|
|
||||||
|
|
||||||
var promise = new UniTaskCompletionSource<AsyncUnit>();
|
|
||||||
return (promise.Task, cts.RegisterWithoutCaptureExecutionContext(cancellationTokenCallback, promise));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Callback(object state)
|
|
||||||
{
|
|
||||||
var promise = (UniTaskCompletionSource<AsyncUnit>)state;
|
|
||||||
promise.TrySetResult(AsyncUnit.Default);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CancellationTokenRegistration RegisterWithoutCaptureExecutionContext(this CancellationToken cancellationToken, Action callback)
|
|
||||||
{
|
|
||||||
var restoreFlow = false;
|
|
||||||
if (!ExecutionContext.IsFlowSuppressed())
|
|
||||||
{
|
|
||||||
ExecutionContext.SuppressFlow();
|
|
||||||
restoreFlow = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return cancellationToken.Register(callback, false);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (restoreFlow)
|
|
||||||
{
|
|
||||||
ExecutionContext.RestoreFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CancellationTokenRegistration RegisterWithoutCaptureExecutionContext(this CancellationToken cancellationToken, Action<object> callback, object state)
|
|
||||||
{
|
|
||||||
var restoreFlow = false;
|
|
||||||
if (!ExecutionContext.IsFlowSuppressed())
|
|
||||||
{
|
|
||||||
ExecutionContext.SuppressFlow();
|
|
||||||
restoreFlow = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return cancellationToken.Register(callback, state, false);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (restoreFlow)
|
|
||||||
{
|
|
||||||
ExecutionContext.RestoreFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -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,23 +0,0 @@
|
||||||
#if NET_4_6 || NET_STANDARD_2_0 || CSHARP_7_OR_LATER
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace UniRx.Async.Internal
|
|
||||||
{
|
|
||||||
internal static class FuncExtensions
|
|
||||||
{
|
|
||||||
// avoid lambda capture
|
|
||||||
|
|
||||||
internal static Action<T> AsFuncOfT<T>(this Action action)
|
|
||||||
{
|
|
||||||
return new Action<T>(action.Invoke);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Invoke<T>(this Action action, T unused)
|
|
||||||
{
|
|
||||||
action();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#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,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: a8cfc99b5928c0242919aac2121b02bb
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,152 +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.Threading;
|
|
||||||
|
|
||||||
namespace UniRx.Async.Internal
|
|
||||||
{
|
|
||||||
// public for add user custom.
|
|
||||||
|
|
||||||
public static class TaskTracker
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
|
|
||||||
static int trackingId = 0;
|
|
||||||
|
|
||||||
public const string EnableAutoReloadKey = "UniTaskTrackerWindow_EnableAutoReloadKey";
|
|
||||||
public const string EnableTrackingKey = "UniTaskTrackerWindow_EnableTrackingKey";
|
|
||||||
public const string EnableStackTraceKey = "UniTaskTrackerWindow_EnableStackTraceKey";
|
|
||||||
|
|
||||||
public static class EditorEnableState
|
|
||||||
{
|
|
||||||
static bool enableAutoReload;
|
|
||||||
public static bool EnableAutoReload
|
|
||||||
{
|
|
||||||
get { return enableAutoReload; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
enableAutoReload = value;
|
|
||||||
UnityEditor.EditorPrefs.SetBool(EnableAutoReloadKey, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool enableTracking;
|
|
||||||
public static bool EnableTracking
|
|
||||||
{
|
|
||||||
get { return enableTracking; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
enableTracking = value;
|
|
||||||
UnityEditor.EditorPrefs.SetBool(EnableTrackingKey, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool enableStackTrace;
|
|
||||||
public static bool EnableStackTrace
|
|
||||||
{
|
|
||||||
get { return enableStackTrace; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
enableStackTrace = value;
|
|
||||||
UnityEditor.EditorPrefs.SetBool(EnableStackTraceKey, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static List<KeyValuePair<IAwaiter, (int trackingId, DateTime addTime, string stackTrace)>> listPool = new List<KeyValuePair<IAwaiter, (int trackingId, DateTime addTime, string stackTrace)>>();
|
|
||||||
|
|
||||||
static readonly WeakDictionary<IAwaiter, (int trackingId, DateTime addTime, string stackTrace)> tracking = new WeakDictionary<IAwaiter, (int trackingId, DateTime addTime, string stackTrace)>();
|
|
||||||
|
|
||||||
[Conditional("UNITY_EDITOR")]
|
|
||||||
public static void TrackActiveTask(IAwaiter task, int skipFrame = 1)
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
dirty = true;
|
|
||||||
if (!EditorEnableState.EnableTracking) return;
|
|
||||||
var stackTrace = EditorEnableState.EnableStackTrace ? new StackTrace(skipFrame, true).CleanupAsyncStackTrace() : "";
|
|
||||||
tracking.TryAdd(task, (Interlocked.Increment(ref trackingId), DateTime.UtcNow, stackTrace));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
[Conditional("UNITY_EDITOR")]
|
|
||||||
public static void TrackActiveTask(IAwaiter task, string stackTrace)
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
dirty = true;
|
|
||||||
if (!EditorEnableState.EnableTracking) return;
|
|
||||||
var success = tracking.TryAdd(task, (Interlocked.Increment(ref trackingId), DateTime.UtcNow, stackTrace));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string CaptureStackTrace(int skipFrame)
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
if (!EditorEnableState.EnableTracking) return "";
|
|
||||||
var stackTrace = EditorEnableState.EnableStackTrace ? new StackTrace(skipFrame + 1, true).CleanupAsyncStackTrace() : "";
|
|
||||||
return stackTrace;
|
|
||||||
#else
|
|
||||||
return null;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
[Conditional("UNITY_EDITOR")]
|
|
||||||
public static void RemoveTracking(IAwaiter task)
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
dirty = true;
|
|
||||||
if (!EditorEnableState.EnableTracking) return;
|
|
||||||
var success = tracking.TryRemove(task);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool dirty;
|
|
||||||
|
|
||||||
public static bool CheckAndResetDirty()
|
|
||||||
{
|
|
||||||
var current = dirty;
|
|
||||||
dirty = false;
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>(trackingId, awaiterType, awaiterStatus, createdTime, stackTrace)</summary>
|
|
||||||
public static void ForEachActiveTask(Action<int, string, AwaiterStatus, DateTime, string> action)
|
|
||||||
{
|
|
||||||
lock (listPool)
|
|
||||||
{
|
|
||||||
var count = tracking.ToList(ref listPool, clear: false);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
string typeName = null;
|
|
||||||
var keyType = listPool[i].Key.GetType();
|
|
||||||
if (keyType.IsNested)
|
|
||||||
{
|
|
||||||
typeName = keyType.DeclaringType.Name + "." + keyType.Name;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
typeName = keyType.Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
action(listPool[i].Value.trackingId, typeName, listPool[i].Key.Status, listPool[i].Value.addTime, listPool[i].Value.stackTrace);
|
|
||||||
listPool[i] = new KeyValuePair<IAwaiter, (int trackingId, DateTime addTime, string stackTrace)>(null, (0, default(DateTime), null)); // clear
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
listPool.Clear();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,192 +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
|
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
using UnityEditor;
|
|
||||||
#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)
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
EditorApplication.playModeStateChanged += (state) =>
|
|
||||||
{
|
|
||||||
if (state == PlayModeStateChange.EnteredEditMode ||
|
|
||||||
state == PlayModeStateChange.EnteredPlayMode) return;
|
|
||||||
|
|
||||||
if (runner != null)
|
|
||||||
runner.Clear();
|
|
||||||
if (cq != null)
|
|
||||||
cq.Clear();
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var yieldLoop = new PlayerLoopSystem
|
|
||||||
{
|
|
||||||
type = loopRunnerYieldType,
|
|
||||||
updateDelegate = cq.Run
|
|
||||||
};
|
|
||||||
|
|
||||||
var runnerLoop = new PlayerLoopSystem
|
|
||||||
{
|
|
||||||
type = loopRunnerType,
|
|
||||||
updateDelegate = runner.Run
|
|
||||||
};
|
|
||||||
|
|
||||||
var source = loopSystem.subSystemList // Remove items from previous initializations.
|
|
||||||
.Where(ls => ls.type != loopRunnerYieldType && ls.type != loopRunnerType).ToArray();
|
|
||||||
var dest = new PlayerLoopSystem[source.Length + 2];
|
|
||||||
Array.Copy(source, 0, dest, 2, source.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 UNITY_EDITOR && UNITY_2019_3_OR_NEWER
|
|
||||||
// When domain reload is disabled, re-initialization is required when entering play mode;
|
|
||||||
// otherwise, pending tasks will leak between play mode sessions.
|
|
||||||
var domainReloadDisabled = UnityEditor.EditorSettings.enterPlayModeOptionsEnabled &&
|
|
||||||
UnityEditor.EditorSettings.enterPlayModeOptions.HasFlag(UnityEditor.EnterPlayModeOptions.DisableDomainReload);
|
|
||||||
if (!domainReloadDisabled && runners != null) return;
|
|
||||||
#else
|
|
||||||
if (runners != null) return; // already initialized
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var playerLoop =
|
|
||||||
#if UNITY_2019_3_OR_NEWER
|
|
||||||
PlayerLoop.GetCurrentPlayerLoop();
|
|
||||||
#else
|
|
||||||
PlayerLoop.GetDefaultPlayerLoop();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Initialize(ref playerLoop);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
[InitializeOnLoadMethod]
|
|
||||||
static void InitOnEditor()
|
|
||||||
{
|
|
||||||
//Execute the play mode init method
|
|
||||||
Init();
|
|
||||||
|
|
||||||
//register an Editor update delegate, used to forcing playerLoop update
|
|
||||||
EditorApplication.update += ForceEditorPlayerLoopUpdate;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static void ForceEditorPlayerLoopUpdate()
|
|
||||||
{
|
|
||||||
if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling ||
|
|
||||||
EditorApplication.isUpdating)
|
|
||||||
{
|
|
||||||
// Not in Edit mode, don't interfere
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//force unity to update PlayerLoop callbacks
|
|
||||||
EditorApplication.QueuePlayerLoopUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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 AddCancellationTriggerOnDestroy
|
|
||||||
|
|
||||||
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 AddCancellationTriggerOnDestroy(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,518 +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;
|
|
||||||
using UniRx.Async.Triggers;
|
|
||||||
|
|
||||||
namespace UniRx.Async
|
|
||||||
{
|
|
||||||
public static class UniTaskCancellationExtensions
|
|
||||||
{
|
|
||||||
/// <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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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,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,121 +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
|
|
||||||
{
|
|
||||||
public partial struct UniTask
|
|
||||||
{
|
|
||||||
static readonly UniTask CanceledUniTask = new Func<UniTask>(() =>
|
|
||||||
{
|
|
||||||
var promise = new UniTaskCompletionSource<AsyncUnit>();
|
|
||||||
promise.TrySetCanceled();
|
|
||||||
promise.MarkHandled();
|
|
||||||
return new UniTask(promise);
|
|
||||||
})();
|
|
||||||
|
|
||||||
public static UniTask CompletedTask
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return new UniTask();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UniTask FromException(Exception ex)
|
|
||||||
{
|
|
||||||
var promise = new UniTaskCompletionSource<AsyncUnit>();
|
|
||||||
promise.TrySetException(ex);
|
|
||||||
promise.MarkHandled();
|
|
||||||
return new UniTask(promise);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UniTask<T> FromException<T>(Exception ex)
|
|
||||||
{
|
|
||||||
var promise = new UniTaskCompletionSource<T>();
|
|
||||||
promise.TrySetException(ex);
|
|
||||||
promise.MarkHandled();
|
|
||||||
return new UniTask<T>(promise);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UniTask<T> FromResult<T>(T value)
|
|
||||||
{
|
|
||||||
return new UniTask<T>(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UniTask FromCanceled()
|
|
||||||
{
|
|
||||||
return CanceledUniTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UniTask<T> FromCanceled<T>()
|
|
||||||
{
|
|
||||||
return CanceledUniTaskCache<T>.Task;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UniTask FromCanceled(CancellationToken token)
|
|
||||||
{
|
|
||||||
var promise = new UniTaskCompletionSource<AsyncUnit>();
|
|
||||||
promise.TrySetException(new OperationCanceledException(token));
|
|
||||||
promise.MarkHandled();
|
|
||||||
return new UniTask(promise);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UniTask<T> FromCanceled<T>(CancellationToken token)
|
|
||||||
{
|
|
||||||
var promise = new UniTaskCompletionSource<T>();
|
|
||||||
promise.TrySetException(new OperationCanceledException(token));
|
|
||||||
promise.MarkHandled();
|
|
||||||
return new UniTask<T>(promise);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>shorthand of new UniTask[T](Func[UniTask[T]] factory)</summary>
|
|
||||||
public static UniTask<T> Lazy<T>(Func<UniTask<T>> factory)
|
|
||||||
{
|
|
||||||
return new UniTask<T>(factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// helper of create add UniTaskVoid to delegate.
|
|
||||||
/// For example: FooEvent += () => UniTask.Void(async () => { /* */ })
|
|
||||||
/// </summary>
|
|
||||||
public static void Void(Func<UniTask> asyncAction)
|
|
||||||
{
|
|
||||||
asyncAction().Forget();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// helper of create add UniTaskVoid to delegate.
|
|
||||||
/// For example: FooEvent += (sender, e) => UniTask.Void(async arg => { /* */ }, (sender, e))
|
|
||||||
/// </summary>
|
|
||||||
public static void Void<T>(Func<T, UniTask> asyncAction, T state)
|
|
||||||
{
|
|
||||||
asyncAction(state).Forget();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class CanceledUniTaskCache<T>
|
|
||||||
{
|
|
||||||
public static readonly UniTask<T> Task;
|
|
||||||
|
|
||||||
static CanceledUniTaskCache()
|
|
||||||
{
|
|
||||||
var promise = new UniTaskCompletionSource<T>();
|
|
||||||
promise.TrySetCanceled();
|
|
||||||
promise.MarkHandled();
|
|
||||||
Task = new UniTask<T>(promise);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static class CompletedTasks
|
|
||||||
{
|
|
||||||
public static readonly UniTask<bool> True = UniTask.FromResult(true);
|
|
||||||
public static readonly UniTask<bool> False = UniTask.FromResult(false);
|
|
||||||
public static readonly UniTask<int> Zero = UniTask.FromResult(0);
|
|
||||||
public static readonly UniTask<int> MinusOne = UniTask.FromResult(-1);
|
|
||||||
public static readonly UniTask<int> One = UniTask.FromResult(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,176 +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 System.Threading.Tasks;
|
|
||||||
using UniRx.Async.Internal;
|
|
||||||
|
|
||||||
namespace UniRx.Async
|
|
||||||
{
|
|
||||||
public partial struct UniTask
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// If running on mainthread, do nothing. Otherwise, same as UniTask.Yield(PlayerLoopTiming.Update).
|
|
||||||
/// </summary>
|
|
||||||
public static SwitchToMainThreadAwaitable SwitchToMainThread()
|
|
||||||
{
|
|
||||||
return new SwitchToMainThreadAwaitable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SwitchToThreadPoolAwaitable SwitchToThreadPool()
|
|
||||||
{
|
|
||||||
return new SwitchToThreadPoolAwaitable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SwitchToTaskPoolAwaitable SwitchToTaskPool()
|
|
||||||
{
|
|
||||||
return new SwitchToTaskPoolAwaitable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SwitchToSynchronizationContextAwaitable SwitchToSynchronizationContext(SynchronizationContext syncContext)
|
|
||||||
{
|
|
||||||
Error.ThrowArgumentNullException(syncContext, nameof(syncContext));
|
|
||||||
return new SwitchToSynchronizationContextAwaitable(syncContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct SwitchToMainThreadAwaitable
|
|
||||||
{
|
|
||||||
public Awaiter GetAwaiter() => new Awaiter();
|
|
||||||
|
|
||||||
public struct Awaiter : ICriticalNotifyCompletion
|
|
||||||
{
|
|
||||||
public bool IsCompleted
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var currentThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
|
|
||||||
if (PlayerLoopHelper.MainThreadId == currentThreadId)
|
|
||||||
{
|
|
||||||
return true; // run immediate.
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false; // register continuation.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GetResult() { }
|
|
||||||
|
|
||||||
public void OnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
PlayerLoopHelper.AddContinuation(PlayerLoopTiming.Update, continuation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnsafeOnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
PlayerLoopHelper.AddContinuation(PlayerLoopTiming.Update, continuation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct SwitchToThreadPoolAwaitable
|
|
||||||
{
|
|
||||||
public Awaiter GetAwaiter() => new Awaiter();
|
|
||||||
|
|
||||||
public struct Awaiter : ICriticalNotifyCompletion
|
|
||||||
{
|
|
||||||
static readonly WaitCallback switchToCallback = Callback;
|
|
||||||
|
|
||||||
public bool IsCompleted => false;
|
|
||||||
public void GetResult() { }
|
|
||||||
|
|
||||||
public void OnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
ThreadPool.UnsafeQueueUserWorkItem(switchToCallback, continuation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnsafeOnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
ThreadPool.UnsafeQueueUserWorkItem(switchToCallback, continuation);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Callback(object state)
|
|
||||||
{
|
|
||||||
var continuation = (Action)state;
|
|
||||||
continuation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct SwitchToTaskPoolAwaitable
|
|
||||||
{
|
|
||||||
public Awaiter GetAwaiter() => new Awaiter();
|
|
||||||
|
|
||||||
public struct Awaiter : ICriticalNotifyCompletion
|
|
||||||
{
|
|
||||||
static readonly Action<object> switchToCallback = Callback;
|
|
||||||
|
|
||||||
public bool IsCompleted => false;
|
|
||||||
public void GetResult() { }
|
|
||||||
|
|
||||||
public void OnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
Task.Factory.StartNew(switchToCallback, continuation, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnsafeOnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
Task.Factory.StartNew(switchToCallback, continuation, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Callback(object state)
|
|
||||||
{
|
|
||||||
var continuation = (Action)state;
|
|
||||||
continuation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct SwitchToSynchronizationContextAwaitable
|
|
||||||
{
|
|
||||||
readonly SynchronizationContext synchronizationContext;
|
|
||||||
|
|
||||||
public SwitchToSynchronizationContextAwaitable(SynchronizationContext synchronizationContext)
|
|
||||||
{
|
|
||||||
this.synchronizationContext = synchronizationContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Awaiter GetAwaiter() => new Awaiter(synchronizationContext);
|
|
||||||
|
|
||||||
public struct Awaiter : ICriticalNotifyCompletion
|
|
||||||
{
|
|
||||||
static readonly SendOrPostCallback switchToCallback = Callback;
|
|
||||||
readonly SynchronizationContext synchronizationContext;
|
|
||||||
|
|
||||||
public Awaiter(SynchronizationContext synchronizationContext)
|
|
||||||
{
|
|
||||||
this.synchronizationContext = synchronizationContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsCompleted => false;
|
|
||||||
public void GetResult() { }
|
|
||||||
|
|
||||||
public void OnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
synchronizationContext.Post(switchToCallback, continuation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnsafeOnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
synchronizationContext.Post(switchToCallback, continuation);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Callback(object state)
|
|
||||||
{
|
|
||||||
var continuation = (Action)state;
|
|
||||||
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
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue