mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-16 12:00:10 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
887db5b281 | ||
|
|
fee5518a82 | ||
|
|
551128e64c | ||
|
|
c65ae8d18e | ||
|
|
c1f75d9ebd | ||
|
|
73a5ff6648 | ||
|
|
1c264f380e | ||
|
|
f02bfa0a1e | ||
|
|
9d684006fc | ||
|
|
c49f1ed028 |
36
README.md
36
README.md
@@ -520,7 +520,7 @@ Async LINQ is enabled when `using Cysharp.Threading.Tasks.Linq;`, and `UniTaskAs
|
|||||||
|
|
||||||
It's closer to UniRx (Reactive Extensions), but UniTaskAsyncEnumerable is a pull-based asynchronous stream, whereas Rx was a push-based asynchronous stream. Note that although similar, the characteristics are different and the details behave differently along with them.
|
It's closer to UniRx (Reactive Extensions), but UniTaskAsyncEnumerable is a pull-based asynchronous stream, whereas Rx was a push-based asynchronous stream. Note that although similar, the characteristics are different and the details behave differently along with them.
|
||||||
|
|
||||||
`UniTaskAsyncEnumerable` is the entry point like `Enumerbale`. In addition to the standard query operators, there are other generators for Unity such as `EveryUpdate`, `Timer`, `TimerFrame`, `Interval`, `IntervalFrame`, and `EveryValueChanged`. And also added additional UniTask original query operators like `Append`, `Prepend`, `DistinctUntilChanged`, `ToHashSet`, `Buffer`, `CombineLatest`, `Do`, `Never`, `ForEachAsync`, `Pairwise`, `Publish`, `Queue`, `Return`, `SkipUntilCanceled`, `TakeUntilCanceled`, `TakeLast`, `Subscribe`.
|
`UniTaskAsyncEnumerable` is the entry point like `Enumerbale`. In addition to the standard query operators, there are other generators for Unity such as `EveryUpdate`, `Timer`, `TimerFrame`, `Interval`, `IntervalFrame`, and `EveryValueChanged`. And also added additional UniTask original query operators like `Append`, `Prepend`, `DistinctUntilChanged`, `ToHashSet`, `Buffer`, `CombineLatest`, `Do`, `Never`, `ForEachAsync`, `Pairwise`, `Publish`, `Queue`, `Return`, `SkipUntil`, `TakeUntil`, `SkipUntilCanceled`, `TakeUntilCanceled`, `TakeLast`, `Subscribe`.
|
||||||
|
|
||||||
The method with Func as an argument has three additional overloads, `***Await`, `***AwaitWithCancellation`.
|
The method with Func as an argument has three additional overloads, `***Await`, `***AwaitWithCancellation`.
|
||||||
|
|
||||||
@@ -532,6 +532,38 @@ SelectAwaitWithCancellation(Func<T, CancellationToken, UniTask<TR>> selector)
|
|||||||
|
|
||||||
If you want to use the `async` method inside the func, use the `***Await` or `***AwaitWithCancellation`.
|
If you want to use the `async` method inside the func, use the `***Await` or `***AwaitWithCancellation`.
|
||||||
|
|
||||||
|
How to create async iterator, C# 8.0 supports async iterator(`async yield return`) but it only allows `IAsyncEnumerable<T>` and of course requires C# 8.0. UniTask supports `UniTaskAsyncEnumerable.Create` method to create custom async iterator.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// IAsyncEnumerable, C# 8.0 version of async iterator. ( do not use this style, IAsyncEnumerable is not controled in UniTask).
|
||||||
|
public async IAsyncEnumerable<int> MyEveryUpdate([EnumeratorCancellation]CancellationToken cancelationToken)
|
||||||
|
{
|
||||||
|
var frameCount = 0;
|
||||||
|
await UniTask.Yield();
|
||||||
|
while (!token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
yield return frameCount++;
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UniTaskAsyncEnumerable.Create and use `await writer.YieldAsync` instead of `yield return`.
|
||||||
|
public IUniTaskAsyncEnumerable<int> MyEveryUpdate()
|
||||||
|
{
|
||||||
|
// writer(IAsyncWriter<T>) has `YieldAsync(value)` method.
|
||||||
|
return UniTaskAsyncEnumerable.Create<int>(async (writer, token) =>
|
||||||
|
{
|
||||||
|
var frameCount = 0;
|
||||||
|
await UniTask.Yield();
|
||||||
|
while (!token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
await writer.YieldAsync(frameCount++); // instead of `yield return`
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Awaitable Events
|
Awaitable Events
|
||||||
---
|
---
|
||||||
All uGUI component implements `***AsAsyncEnumerable` to convert asynchronous streams of events.
|
All uGUI component implements `***AsAsyncEnumerable` to convert asynchronous streams of events.
|
||||||
@@ -812,7 +844,7 @@ After Unity 2019.3.4f1, Unity 2020.1a21, that support path query parameter of gi
|
|||||||
|
|
||||||
or add `"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask"` to `Packages/manifest.json`.
|
or add `"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask"` to `Packages/manifest.json`.
|
||||||
|
|
||||||
If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#2.0.22`. For example `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.0.22`.
|
If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#2.0.24`. For example `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.0.24`.
|
||||||
|
|
||||||
### Install via OpenUPM
|
### Install via OpenUPM
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Cysharp.Threading.Tasks;
|
#pragma warning disable CS1998
|
||||||
|
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
@@ -56,6 +58,24 @@ namespace NetCoreSandbox
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
public async UniTask MethodFooAsync()
|
||||||
|
{
|
||||||
|
await MethodBarAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async UniTask MethodBarAsync()
|
||||||
|
|
||||||
|
{
|
||||||
|
Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Throw()
|
||||||
|
{
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public struct TestAwaiter : ICriticalNotifyCompletion
|
public struct TestAwaiter : ICriticalNotifyCompletion
|
||||||
{
|
{
|
||||||
@@ -275,53 +295,25 @@ namespace NetCoreSandbox
|
|||||||
//await new ComparisonBenchmarks().ViaUniTaskT();
|
//await new ComparisonBenchmarks().ViaUniTaskT();
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
// await new AllocationCheck().ViaUniTaskVoid();
|
|
||||||
|
|
||||||
// AsyncTest().Forge
|
var e = UniTaskAsyncEnumerable.Create<int>(async (writer, token) =>
|
||||||
|
|
||||||
Console.WriteLine("A?");
|
|
||||||
var a = await new ZeroAllocAsyncAwaitInDotNetCore().NanikaAsync(1, 2);
|
|
||||||
Console.WriteLine("RET:" + a);
|
|
||||||
await WhereSelect();
|
|
||||||
|
|
||||||
SynchronizationContext.SetSynchronizationContext(new MySyncContext());
|
|
||||||
|
|
||||||
await Aaa();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//AsyncTest().Forget();
|
|
||||||
|
|
||||||
// AsyncTest().Forget();
|
|
||||||
|
|
||||||
ThreadPool.SetMinThreads(100, 100);
|
|
||||||
|
|
||||||
//List<UniTask<int>> list = new List<UniTask<int>>();
|
|
||||||
for (int i = 0; i < short.MaxValue; i++)
|
|
||||||
{
|
{
|
||||||
//// list.Add(AsyncTest());
|
for (int i = 0; i < 5; i++)
|
||||||
await YieldCore();
|
{
|
||||||
|
Console.WriteLine($"Start {i}");
|
||||||
|
await writer.YieldAsync(i);
|
||||||
|
Console.WriteLine($"End {i}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var ee = e.GetAsyncEnumerator();
|
||||||
|
while (await ee.MoveNextAsync())
|
||||||
|
{
|
||||||
|
Console.WriteLine("ForEach " + ee.Current);
|
||||||
}
|
}
|
||||||
//await UniTask.WhenAll(list);
|
|
||||||
|
|
||||||
//Console.WriteLine("TOGO");
|
|
||||||
|
|
||||||
//var a = await AsyncTest();
|
|
||||||
//var b = AsyncTest();
|
|
||||||
//var c = AsyncTest();
|
|
||||||
await YieldCore();
|
|
||||||
|
|
||||||
//await b;
|
|
||||||
//await c;
|
|
||||||
|
|
||||||
|
|
||||||
//foreach (var item in Cysharp.Threading.Tasks.Internal.TaskPool.GetCacheSizeInfo())
|
|
||||||
//{
|
|
||||||
// Console.WriteLine(item);
|
|
||||||
//}
|
|
||||||
|
|
||||||
Console.ReadLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async UniTask YieldCore()
|
static async UniTask YieldCore()
|
||||||
|
|||||||
170
src/UniTask.NetCoreTests/Linq/CreateTest.cs
Normal file
170
src/UniTask.NetCoreTests/Linq/CreateTest.cs
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
#pragma warning disable CS1998
|
||||||
|
#pragma warning disable CS0162
|
||||||
|
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using Cysharp.Threading.Tasks.Linq;
|
||||||
|
using FluentAssertions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace NetCoreTests.Linq
|
||||||
|
{
|
||||||
|
public class CreateTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task SyncCreation()
|
||||||
|
{
|
||||||
|
var from = 10;
|
||||||
|
var count = 100;
|
||||||
|
|
||||||
|
var xs = await UniTaskAsyncEnumerable.Create<int>(async (writer, token) =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
await writer.YieldAsync(from + i);
|
||||||
|
}
|
||||||
|
}).ToArrayAsync();
|
||||||
|
|
||||||
|
var ys = await Range(from, count).AsUniTaskAsyncEnumerable().ToArrayAsync();
|
||||||
|
|
||||||
|
xs.Should().BeEquivalentTo(ys);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SyncManually()
|
||||||
|
{
|
||||||
|
var list = new List<int>();
|
||||||
|
var xs = UniTaskAsyncEnumerable.Create<int>(async (writer, token) =>
|
||||||
|
{
|
||||||
|
list.Add(100);
|
||||||
|
await writer.YieldAsync(10);
|
||||||
|
|
||||||
|
list.Add(200);
|
||||||
|
await writer.YieldAsync(20);
|
||||||
|
|
||||||
|
list.Add(300);
|
||||||
|
await writer.YieldAsync(30);
|
||||||
|
|
||||||
|
list.Add(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
list.Should().BeEmpty();
|
||||||
|
var e = xs.GetAsyncEnumerator();
|
||||||
|
|
||||||
|
list.Should().BeEmpty();
|
||||||
|
|
||||||
|
await e.MoveNextAsync();
|
||||||
|
list.Should().BeEquivalentTo(100);
|
||||||
|
e.Current.Should().Be(10);
|
||||||
|
|
||||||
|
await e.MoveNextAsync();
|
||||||
|
list.Should().BeEquivalentTo(100, 200);
|
||||||
|
e.Current.Should().Be(20);
|
||||||
|
|
||||||
|
await e.MoveNextAsync();
|
||||||
|
list.Should().BeEquivalentTo(100, 200, 300);
|
||||||
|
e.Current.Should().Be(30);
|
||||||
|
|
||||||
|
(await e.MoveNextAsync()).Should().BeFalse();
|
||||||
|
list.Should().BeEquivalentTo(100, 200, 300, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SyncExceptionFirst()
|
||||||
|
{
|
||||||
|
var from = 10;
|
||||||
|
var count = 100;
|
||||||
|
|
||||||
|
var xs = UniTaskAsyncEnumerable.Create<int>(async (writer, token) =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
throw new UniTaskTestException();
|
||||||
|
await writer.YieldAsync(from + i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<UniTaskTestException>(async () => await xs.ToArrayAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SyncException()
|
||||||
|
{
|
||||||
|
var from = 10;
|
||||||
|
var count = 100;
|
||||||
|
|
||||||
|
var xs = UniTaskAsyncEnumerable.Create<int>(async (writer, token) =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
await writer.YieldAsync(from + i);
|
||||||
|
|
||||||
|
if (i == 15)
|
||||||
|
{
|
||||||
|
throw new UniTaskTestException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<UniTaskTestException>(async () => await xs.ToArrayAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ASyncManually()
|
||||||
|
{
|
||||||
|
var list = new List<int>();
|
||||||
|
var xs = UniTaskAsyncEnumerable.Create<int>(async (writer, token) =>
|
||||||
|
{
|
||||||
|
await UniTask.Yield();
|
||||||
|
|
||||||
|
list.Add(100);
|
||||||
|
await writer.YieldAsync(10);
|
||||||
|
|
||||||
|
await UniTask.Yield();
|
||||||
|
|
||||||
|
list.Add(200);
|
||||||
|
await writer.YieldAsync(20);
|
||||||
|
|
||||||
|
await UniTask.Yield();
|
||||||
|
list.Add(300);
|
||||||
|
await UniTask.Yield();
|
||||||
|
await writer.YieldAsync(30);
|
||||||
|
|
||||||
|
await UniTask.Yield();
|
||||||
|
|
||||||
|
list.Add(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
list.Should().BeEmpty();
|
||||||
|
var e = xs.GetAsyncEnumerator();
|
||||||
|
|
||||||
|
list.Should().BeEmpty();
|
||||||
|
|
||||||
|
await e.MoveNextAsync();
|
||||||
|
list.Should().BeEquivalentTo(100);
|
||||||
|
e.Current.Should().Be(10);
|
||||||
|
|
||||||
|
await e.MoveNextAsync();
|
||||||
|
list.Should().BeEquivalentTo(100, 200);
|
||||||
|
e.Current.Should().Be(20);
|
||||||
|
|
||||||
|
await e.MoveNextAsync();
|
||||||
|
list.Should().BeEquivalentTo(100, 200, 300);
|
||||||
|
e.Current.Should().Be(30);
|
||||||
|
|
||||||
|
(await e.MoveNextAsync()).Should().BeFalse();
|
||||||
|
list.Should().BeEquivalentTo(100, 200, 300, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
async IAsyncEnumerable<int> Range(int from, int count)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
yield return from + i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
192
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/Create.cs
Normal file
192
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/Create.cs
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
using Cysharp.Threading.Tasks.Internal;
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace Cysharp.Threading.Tasks.Linq
|
||||||
|
{
|
||||||
|
public static partial class UniTaskAsyncEnumerable
|
||||||
|
{
|
||||||
|
public static IUniTaskAsyncEnumerable<T> Create<T>(Func<IAsyncWriter<T>, CancellationToken, UniTask> create)
|
||||||
|
{
|
||||||
|
Error.ThrowArgumentNullException(create, nameof(create));
|
||||||
|
return new Create<T>(create);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IAsyncWriter<T>
|
||||||
|
{
|
||||||
|
UniTask YieldAsync(T value);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class Create<T> : IUniTaskAsyncEnumerable<T>
|
||||||
|
{
|
||||||
|
readonly Func<IAsyncWriter<T>, CancellationToken, UniTask> create;
|
||||||
|
|
||||||
|
public Create(Func<IAsyncWriter<T>, CancellationToken, UniTask> create)
|
||||||
|
{
|
||||||
|
this.create = create;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return new _Create(create, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class _Create : MoveNextSource, IUniTaskAsyncEnumerator<T>
|
||||||
|
{
|
||||||
|
readonly Func<IAsyncWriter<T>, CancellationToken, UniTask> create;
|
||||||
|
readonly CancellationToken cancellationToken;
|
||||||
|
|
||||||
|
int state = -1;
|
||||||
|
AsyncWriter writer;
|
||||||
|
|
||||||
|
public _Create(Func<IAsyncWriter<T>, CancellationToken, UniTask> create, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
this.create = create;
|
||||||
|
this.cancellationToken = cancellationToken;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Current { get; private set; }
|
||||||
|
|
||||||
|
public UniTask DisposeAsync()
|
||||||
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTask<bool> MoveNextAsync()
|
||||||
|
{
|
||||||
|
if (state == -2) return default;
|
||||||
|
|
||||||
|
completionSource.Reset();
|
||||||
|
MoveNext();
|
||||||
|
return new UniTask<bool>(this, completionSource.Version);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MoveNext()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case -1: // init
|
||||||
|
{
|
||||||
|
writer = new AsyncWriter(this);
|
||||||
|
RunWriterTask(create(writer, cancellationToken)).Forget();
|
||||||
|
if (Volatile.Read(ref state) == -2)
|
||||||
|
{
|
||||||
|
return; // complete synchronously
|
||||||
|
}
|
||||||
|
state = 0; // wait YieldAsync, it set TrySetResult(true)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case 0:
|
||||||
|
writer.SignalWriter();
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
goto DONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
state = -2;
|
||||||
|
completionSource.TrySetException(ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DONE:
|
||||||
|
state = -2;
|
||||||
|
completionSource.TrySetResult(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async UniTaskVoid RunWriterTask(UniTask task)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await task;
|
||||||
|
goto DONE;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Volatile.Write(ref state, -2);
|
||||||
|
completionSource.TrySetException(ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DONE:
|
||||||
|
Volatile.Write(ref state, -2);
|
||||||
|
completionSource.TrySetResult(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TrySetCanceled(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
state = -2;
|
||||||
|
return completionSource.TrySetCanceled(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TrySetComplete()
|
||||||
|
{
|
||||||
|
state = -2;
|
||||||
|
return completionSource.TrySetResult(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TrySetException(Exception error)
|
||||||
|
{
|
||||||
|
state = -2;
|
||||||
|
return completionSource.TrySetException(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetResult(T value)
|
||||||
|
{
|
||||||
|
Current = value;
|
||||||
|
completionSource.TrySetResult(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class AsyncWriter : IUniTaskSource, IAsyncWriter<T>
|
||||||
|
{
|
||||||
|
readonly _Create enumerator;
|
||||||
|
|
||||||
|
UniTaskCompletionSourceCore<AsyncUnit> core;
|
||||||
|
|
||||||
|
public AsyncWriter(_Create enumerator)
|
||||||
|
{
|
||||||
|
this.enumerator = enumerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetResult(short token)
|
||||||
|
{
|
||||||
|
core.GetResult(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTaskStatus GetStatus(short token)
|
||||||
|
{
|
||||||
|
return core.GetStatus(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTaskStatus UnsafeGetStatus()
|
||||||
|
{
|
||||||
|
return core.UnsafeGetStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnCompleted(Action<object> continuation, object state, short token)
|
||||||
|
{
|
||||||
|
core.OnCompleted(continuation, state, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTask YieldAsync(T value)
|
||||||
|
{
|
||||||
|
core.Reset();
|
||||||
|
enumerator.SetResult(value);
|
||||||
|
return new UniTask(this, core.Version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SignalWriter()
|
||||||
|
{
|
||||||
|
core.TrySetResult(AsyncUnit.Default);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0202f723469f93945afa063bfb440d15
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -88,6 +88,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TResult Current { get; private set; }
|
public TResult Current { get; private set; }
|
||||||
@@ -156,6 +157,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,6 +197,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TResult Current { get; private set; }
|
public TResult Current { get; private set; }
|
||||||
@@ -263,6 +266,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,6 +306,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TResult Current { get; private set; }
|
public TResult Current { get; private set; }
|
||||||
@@ -382,6 +387,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -422,6 +428,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TResult Current { get; private set; }
|
public TResult Current { get; private set; }
|
||||||
@@ -502,6 +509,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -541,6 +549,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TResult Current { get; private set; }
|
public TResult Current { get; private set; }
|
||||||
@@ -621,6 +630,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -661,6 +671,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TResult Current { get; private set; }
|
public TResult Current { get; private set; }
|
||||||
@@ -741,6 +752,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TSource Current { get; private set; }
|
public TSource Current { get; private set; }
|
||||||
@@ -165,6 +166,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,6 +206,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TSource Current { get; private set; }
|
public TSource Current { get; private set; }
|
||||||
@@ -281,6 +284,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,6 +324,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TSource Current { get; private set; }
|
public TSource Current { get; private set; }
|
||||||
@@ -410,6 +415,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,6 +456,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TSource Current { get; private set; }
|
public TSource Current { get; private set; }
|
||||||
@@ -540,6 +547,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -579,6 +587,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TSource Current { get; private set; }
|
public TSource Current { get; private set; }
|
||||||
@@ -669,6 +678,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -709,6 +719,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
this.moveNextAction = MoveNext;
|
this.moveNextAction = MoveNext;
|
||||||
|
TaskTracker.TrackActiveTask(this, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TSource Current { get; private set; }
|
public TSource Current { get; private set; }
|
||||||
@@ -799,6 +810,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
return enumerator.DisposeAsync();
|
return enumerator.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
using Cysharp.Threading.Tasks.Internal;
|
using Cysharp.Threading.Tasks.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.ExceptionServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace Cysharp.Threading.Tasks
|
namespace Cysharp.Threading.Tasks
|
||||||
@@ -174,18 +175,34 @@ namespace Cysharp.Threading.Tasks
|
|||||||
return new UniTask<T>(new DeferPromise<T>(factory), 0);
|
return new UniTask<T>(new DeferPromise<T>(factory), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Never complete.
|
||||||
|
/// </summary>
|
||||||
|
public static UniTask Never(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return new UniTask<AsyncUnit>(new NeverPromise<AsyncUnit>(cancellationToken), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Never complete.
|
||||||
|
/// </summary>
|
||||||
|
public static UniTask<T> Never<T>(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return new UniTask<T>(new NeverPromise<T>(cancellationToken), 0);
|
||||||
|
}
|
||||||
|
|
||||||
sealed class ExceptionResultSource : IUniTaskSource
|
sealed class ExceptionResultSource : IUniTaskSource
|
||||||
{
|
{
|
||||||
readonly Exception exception;
|
readonly ExceptionDispatchInfo exception;
|
||||||
|
|
||||||
public ExceptionResultSource(Exception exception)
|
public ExceptionResultSource(Exception exception)
|
||||||
{
|
{
|
||||||
this.exception = exception;
|
this.exception = ExceptionDispatchInfo.Capture(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetResult(short token)
|
public void GetResult(short token)
|
||||||
{
|
{
|
||||||
throw exception;
|
exception.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UniTaskStatus GetStatus(short token)
|
public UniTaskStatus GetStatus(short token)
|
||||||
@@ -206,21 +223,22 @@ namespace Cysharp.Threading.Tasks
|
|||||||
|
|
||||||
sealed class ExceptionResultSource<T> : IUniTaskSource<T>
|
sealed class ExceptionResultSource<T> : IUniTaskSource<T>
|
||||||
{
|
{
|
||||||
readonly Exception exception;
|
readonly ExceptionDispatchInfo exception;
|
||||||
|
|
||||||
public ExceptionResultSource(Exception exception)
|
public ExceptionResultSource(Exception exception)
|
||||||
{
|
{
|
||||||
this.exception = exception;
|
this.exception = ExceptionDispatchInfo.Capture(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetResult(short token)
|
public T GetResult(short token)
|
||||||
{
|
{
|
||||||
throw exception;
|
exception.Throw();
|
||||||
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IUniTaskSource.GetResult(short token)
|
void IUniTaskSource.GetResult(short token)
|
||||||
{
|
{
|
||||||
throw exception;
|
exception.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UniTaskStatus GetStatus(short token)
|
public UniTaskStatus GetStatus(short token)
|
||||||
@@ -382,6 +400,54 @@ namespace Cysharp.Threading.Tasks
|
|||||||
return task.Status;
|
return task.Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed class NeverPromise<T> : IUniTaskSource<T>
|
||||||
|
{
|
||||||
|
static readonly Action<object> cancellationCallback = CancellationCallback;
|
||||||
|
|
||||||
|
CancellationToken cancellationToken;
|
||||||
|
UniTaskCompletionSourceCore<T> core;
|
||||||
|
|
||||||
|
public NeverPromise(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
this.cancellationToken = cancellationToken;
|
||||||
|
if (this.cancellationToken.CanBeCanceled)
|
||||||
|
{
|
||||||
|
this.cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CancellationCallback(object state)
|
||||||
|
{
|
||||||
|
var self = (NeverPromise<T>)state;
|
||||||
|
self.core.TrySetCanceled(self.cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetResult(short token)
|
||||||
|
{
|
||||||
|
return core.GetResult(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTaskStatus GetStatus(short token)
|
||||||
|
{
|
||||||
|
return core.GetStatus(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTaskStatus UnsafeGetStatus()
|
||||||
|
{
|
||||||
|
return core.UnsafeGetStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnCompleted(Action<object> continuation, object state, short token)
|
||||||
|
{
|
||||||
|
core.OnCompleted(continuation, state, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IUniTaskSource.GetResult(short token)
|
||||||
|
{
|
||||||
|
core.GetResult(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class CompletedTasks
|
internal static class CompletedTasks
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
ValidateToken(token);
|
ValidateToken(token);
|
||||||
if (completedCount == 0)
|
if (completedCount == 0)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("not yet completed.");
|
throw new InvalidOperationException("Not yet completed, UniTask only allow to use await.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error != null)
|
if (error != null)
|
||||||
@@ -288,7 +288,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
// It will cause call OnCompleted multiple time, invalid.
|
// It will cause call OnCompleted multiple time, invalid.
|
||||||
if (!ReferenceEquals(oldContinuation, UniTaskCompletionSourceCoreShared.s_sentinel))
|
if (!ReferenceEquals(oldContinuation, UniTaskCompletionSourceCoreShared.s_sentinel))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException("Already continuation registered, can not await twice or get Status after await.");
|
||||||
}
|
}
|
||||||
|
|
||||||
continuation(state);
|
continuation(state);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "com.cysharp.unitask",
|
"name": "com.cysharp.unitask",
|
||||||
"displayName": "UniTask",
|
"displayName": "UniTask",
|
||||||
"version": "2.0.22",
|
"version": "2.0.24",
|
||||||
"unity": "2018.4",
|
"unity": "2018.4",
|
||||||
"description": "Provides an efficient async/await integration to Unity.",
|
"description": "Provides an efficient async/await integration to Unity.",
|
||||||
"keywords": [ "async/await", "async", "Task", "UniTask" ],
|
"keywords": [ "async/await", "async", "Task", "UniTask" ],
|
||||||
|
|||||||
@@ -1,28 +1,52 @@
|
|||||||
using System;
|
using Cysharp.Threading.Tasks;
|
||||||
using System.Threading.Tasks;
|
using System;
|
||||||
using Cysharp.Threading.Tasks;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
|
||||||
|
|
||||||
|
/*UNniTastWhenAnyTester*/
|
||||||
|
|
||||||
|
[ExecuteInEditMode]
|
||||||
public class ExceptionExamples : MonoBehaviour
|
public class ExceptionExamples : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public bool apply = false;
|
||||||
private void Start()
|
|
||||||
|
private async UniTaskVoid Update()
|
||||||
{
|
{
|
||||||
|
if (apply)
|
||||||
//TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
|
{
|
||||||
|
apply = false;
|
||||||
//ThrowFromAsyncVoid();
|
await LaunchTasksAndDetectWhenAnyDone(5);
|
||||||
//_ = ThrowFromTask();
|
}
|
||||||
//_ = ThrowFromUniTask();
|
|
||||||
|
|
||||||
//ThrowFromNonAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task Test()
|
private async UniTask LaunchTasksAndDetectWhenAnyDone(int nbTasks)
|
||||||
{
|
{
|
||||||
var webRequest = UnityWebRequest.Get("http");
|
List<UniTask<int>> sleeptasks = new List<UniTask<int>>();
|
||||||
var request = webRequest.SendWebRequest();
|
for (int i = 0; i < nbTasks; i++)
|
||||||
await request;
|
{
|
||||||
|
sleeptasks.Add(SleepAndReturnTrue(i).ToAsyncLazy().Task);
|
||||||
|
}
|
||||||
|
while (sleeptasks.Count > 0)
|
||||||
|
{
|
||||||
|
Debug.Log(DateTime.Now.ToString() + " waiting for " + sleeptasks.Count + " tasks...");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
(int index, int taskID) = await UniTask.WhenAny(sleeptasks);
|
||||||
|
Debug.Log(DateTime.Now.ToString() + " Sleep task " + taskID + " done");
|
||||||
|
sleeptasks.RemoveAt(index);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
//Debug.Log("Error: " + e.Message);
|
||||||
|
//return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async UniTask<int> SleepAndReturnTrue(int taskIndex)
|
||||||
|
{
|
||||||
|
await UniTask.Delay(100);
|
||||||
|
return taskIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,6 +121,149 @@ NavMeshSettings:
|
|||||||
debug:
|
debug:
|
||||||
m_Flags: 0
|
m_Flags: 0
|
||||||
m_NavMeshData: {fileID: 0}
|
m_NavMeshData: {fileID: 0}
|
||||||
|
--- !u!1 &542336983
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 542336986}
|
||||||
|
- component: {fileID: 542336985}
|
||||||
|
- component: {fileID: 542336984}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: EventSystem
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!114 &542336984
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 542336983}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_HorizontalAxis: Horizontal
|
||||||
|
m_VerticalAxis: Vertical
|
||||||
|
m_SubmitButton: Submit
|
||||||
|
m_CancelButton: Cancel
|
||||||
|
m_InputActionsPerSecond: 10
|
||||||
|
m_RepeatDelay: 0.5
|
||||||
|
m_ForceModuleActive: 0
|
||||||
|
--- !u!114 &542336985
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 542336983}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_FirstSelected: {fileID: 0}
|
||||||
|
m_sendNavigationEvents: 1
|
||||||
|
m_DragThreshold: 10
|
||||||
|
--- !u!4 &542336986
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 542336983}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 1
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1 &730559310
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 730559311}
|
||||||
|
- component: {fileID: 730559313}
|
||||||
|
- component: {fileID: 730559312}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: Text
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &730559311
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 730559310}
|
||||||
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1587363385}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
|
m_AnchorMax: {x: 1, y: 1}
|
||||||
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
|
m_SizeDelta: {x: 0, y: 0}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!114 &730559312
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 730559310}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
|
||||||
|
m_RaycastTarget: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_FontData:
|
||||||
|
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
m_FontSize: 14
|
||||||
|
m_FontStyle: 0
|
||||||
|
m_BestFit: 0
|
||||||
|
m_MinSize: 10
|
||||||
|
m_MaxSize: 40
|
||||||
|
m_Alignment: 4
|
||||||
|
m_AlignByGeometry: 0
|
||||||
|
m_RichText: 1
|
||||||
|
m_HorizontalOverflow: 0
|
||||||
|
m_VerticalOverflow: 0
|
||||||
|
m_LineSpacing: 1
|
||||||
|
m_Text: Button
|
||||||
|
--- !u!222 &730559313
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 730559310}
|
||||||
|
m_CullTransparentMesh: 0
|
||||||
--- !u!1 &735985614
|
--- !u!1 &735985614
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -152,7 +295,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 329ff620b32b4ef4abdc99884242ee67, type: 3}
|
m_Script: {fileID: 11500000, guid: 329ff620b32b4ef4abdc99884242ee67, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
_unobservedExceptionLogType: 0
|
ButtonTest: {fileID: 1587363386}
|
||||||
--- !u!81 &735985616
|
--- !u!81 &735985616
|
||||||
AudioListener:
|
AudioListener:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -214,7 +357,225 @@ Transform:
|
|||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: -10}
|
m_LocalPosition: {x: 0, y: 0, z: -10}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children:
|
||||||
|
- {fileID: 1323586517}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1 &1323586516
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1323586517}
|
||||||
|
- component: {fileID: 1323586520}
|
||||||
|
- component: {fileID: 1323586519}
|
||||||
|
- component: {fileID: 1323586518}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: Canvas
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &1323586517
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1323586516}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 0, y: 0, z: 0}
|
||||||
|
m_Children:
|
||||||
|
- {fileID: 1587363385}
|
||||||
|
m_Father: {fileID: 735985618}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
|
m_AnchorMax: {x: 0, y: 0}
|
||||||
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
|
m_SizeDelta: {x: 0, y: 0}
|
||||||
|
m_Pivot: {x: 0, y: 0}
|
||||||
|
--- !u!114 &1323586518
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1323586516}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_IgnoreReversedGraphics: 1
|
||||||
|
m_BlockingObjects: 0
|
||||||
|
m_BlockingMask:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
--- !u!114 &1323586519
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1323586516}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_UiScaleMode: 0
|
||||||
|
m_ReferencePixelsPerUnit: 100
|
||||||
|
m_ScaleFactor: 1
|
||||||
|
m_ReferenceResolution: {x: 800, y: 600}
|
||||||
|
m_ScreenMatchMode: 0
|
||||||
|
m_MatchWidthOrHeight: 0
|
||||||
|
m_PhysicalUnit: 3
|
||||||
|
m_FallbackScreenDPI: 96
|
||||||
|
m_DefaultSpriteDPI: 96
|
||||||
|
m_DynamicPixelsPerUnit: 1
|
||||||
|
--- !u!223 &1323586520
|
||||||
|
Canvas:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1323586516}
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 3
|
||||||
|
m_RenderMode: 0
|
||||||
|
m_Camera: {fileID: 0}
|
||||||
|
m_PlaneDistance: 100
|
||||||
|
m_PixelPerfect: 0
|
||||||
|
m_ReceivesEvents: 1
|
||||||
|
m_OverrideSorting: 0
|
||||||
|
m_OverridePixelPerfect: 0
|
||||||
|
m_SortingBucketNormalizedSize: 0
|
||||||
|
m_AdditionalShaderChannelsFlag: 0
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_TargetDisplay: 0
|
||||||
|
--- !u!1 &1587363384
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1587363385}
|
||||||
|
- component: {fileID: 1587363388}
|
||||||
|
- component: {fileID: 1587363387}
|
||||||
|
- component: {fileID: 1587363386}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: Button
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &1587363385
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1587363384}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children:
|
||||||
|
- {fileID: 730559311}
|
||||||
|
m_Father: {fileID: 1323586517}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||||
|
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||||
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
|
m_SizeDelta: {x: 160, y: 30}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!114 &1587363386
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1587363384}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Navigation:
|
||||||
|
m_Mode: 3
|
||||||
|
m_SelectOnUp: {fileID: 0}
|
||||||
|
m_SelectOnDown: {fileID: 0}
|
||||||
|
m_SelectOnLeft: {fileID: 0}
|
||||||
|
m_SelectOnRight: {fileID: 0}
|
||||||
|
m_Transition: 1
|
||||||
|
m_Colors:
|
||||||
|
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||||
|
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
|
||||||
|
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||||
|
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
|
||||||
|
m_ColorMultiplier: 1
|
||||||
|
m_FadeDuration: 0.1
|
||||||
|
m_SpriteState:
|
||||||
|
m_HighlightedSprite: {fileID: 0}
|
||||||
|
m_PressedSprite: {fileID: 0}
|
||||||
|
m_SelectedSprite: {fileID: 0}
|
||||||
|
m_DisabledSprite: {fileID: 0}
|
||||||
|
m_AnimationTriggers:
|
||||||
|
m_NormalTrigger: Normal
|
||||||
|
m_HighlightedTrigger: Highlighted
|
||||||
|
m_PressedTrigger: Pressed
|
||||||
|
m_SelectedTrigger: Selected
|
||||||
|
m_DisabledTrigger: Disabled
|
||||||
|
m_Interactable: 1
|
||||||
|
m_TargetGraphic: {fileID: 1587363387}
|
||||||
|
m_OnClick:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
--- !u!114 &1587363387
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1587363384}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_RaycastTarget: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
|
m_Type: 1
|
||||||
|
m_PreserveAspect: 0
|
||||||
|
m_FillCenter: 1
|
||||||
|
m_FillMethod: 4
|
||||||
|
m_FillAmount: 1
|
||||||
|
m_FillClockwise: 1
|
||||||
|
m_FillOrigin: 0
|
||||||
|
m_UseSpriteMesh: 0
|
||||||
|
m_PixelsPerUnitMultiplier: 1
|
||||||
|
--- !u!222 &1587363388
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1587363384}
|
||||||
|
m_CullTransparentMesh: 0
|
||||||
|
|||||||
@@ -459,18 +459,41 @@ public class SandboxMain : MonoBehaviour
|
|||||||
PrepareCamera();
|
PrepareCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IUniTaskAsyncEnumerable<int> MyEveryUpdate()
|
||||||
|
{
|
||||||
|
return UniTaskAsyncEnumerable.Create<int>(async (writer, token) =>
|
||||||
|
{
|
||||||
|
var frameCount = 0;
|
||||||
|
await UniTask.Yield();
|
||||||
|
while (!token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
await writer.YieldAsync(frameCount++); // instead of `yield return`
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async UniTaskVoid Start()
|
async UniTaskVoid Start()
|
||||||
{
|
{
|
||||||
|
var cts = new CancellationTokenSource();
|
||||||
okButton.onClick.AddListener(() =>
|
okButton.onClick.AddListener(() =>
|
||||||
{
|
{
|
||||||
ShootAsync().Forget();
|
cts.Cancel();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Nanika();
|
//// Nanika();
|
||||||
|
|
||||||
|
|
||||||
|
//await UniTask.Yield();
|
||||||
|
|
||||||
|
|
||||||
|
await MyEveryUpdate().Select(x => x).Where(x => x % 2 == 0).ForEachAsync(x =>
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.Log(x + ":" + Time.frameCount);
|
||||||
|
}, cts.Token);
|
||||||
|
|
||||||
|
|
||||||
await UniTask.Yield();
|
|
||||||
// this.GetCancellationTokenOnDestroy()
|
// this.GetCancellationTokenOnDestroy()
|
||||||
|
|
||||||
//PlayerLoopInfo.Inject();
|
//PlayerLoopInfo.Inject();
|
||||||
@@ -992,17 +1015,17 @@ public class SandboxMain : MonoBehaviour
|
|||||||
|
|
||||||
void PrepareCamera()
|
void PrepareCamera()
|
||||||
{
|
{
|
||||||
Debug.Log("Support AsyncGPUReadback:" + SystemInfo.supportsAsyncGPUReadback);
|
//Debug.Log("Support AsyncGPUReadback:" + SystemInfo.supportsAsyncGPUReadback);
|
||||||
|
|
||||||
var width = 480;
|
//var width = 480;
|
||||||
var height = 240;
|
//var height = 240;
|
||||||
var depth = 24;
|
//var depth = 24;
|
||||||
|
|
||||||
mycamera.targetTexture = new RenderTexture(width, height, depth, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default)
|
//mycamera.targetTexture = new RenderTexture(width, height, depth, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default)
|
||||||
{
|
//{
|
||||||
antiAliasing = 8
|
// antiAliasing = 8
|
||||||
};
|
//};
|
||||||
mycamera.enabled = true;
|
//mycamera.enabled = true;
|
||||||
|
|
||||||
//myRenderTexture = new RenderTexture(width, height, depth, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default)
|
//myRenderTexture = new RenderTexture(width, height, depth, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default)
|
||||||
//{
|
//{
|
||||||
|
|||||||
Reference in New Issue
Block a user