export
parent
32a4e84513
commit
6c1b590fd8
|
@ -12,7 +12,7 @@ public static class PackageExporter
|
|||
public static void Export()
|
||||
{
|
||||
// configure
|
||||
var root = "UniTask";
|
||||
var root = "Plugins/UniTask";
|
||||
var exportPath = "./UniTask.unitypackage";
|
||||
|
||||
var path = Path.Combine(Application.dataPath, root);
|
||||
|
|
|
@ -136,19 +136,31 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
|||
// don't use boxed stateMachine.
|
||||
}
|
||||
|
||||
#if DEBUG || !UNITY_2018_3_OR_NEWER
|
||||
|
||||
object id;
|
||||
|
||||
// 9. For Debugger Attach
|
||||
[DebuggerHidden]
|
||||
public object ObjectIdForDebugger
|
||||
{
|
||||
get
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
id = new object();
|
||||
}
|
||||
return id;
|
||||
/*
|
||||
if (promise == null)
|
||||
{
|
||||
promise = AutoResetUniTaskCompletionSource.Create();
|
||||
}
|
||||
return promise;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
|
@ -281,18 +293,30 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
|||
// don't use boxed stateMachine.
|
||||
}
|
||||
|
||||
#if DEBUG || !UNITY_2018_3_OR_NEWER
|
||||
|
||||
object id;
|
||||
|
||||
// 9. For Debugger Attach
|
||||
[DebuggerHidden]
|
||||
public object ObjectIdForDebugger
|
||||
{
|
||||
get
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
id = new object();
|
||||
}
|
||||
return id;
|
||||
/*
|
||||
if (promise == null)
|
||||
{
|
||||
promise = AutoResetUniTaskCompletionSource<T>.Create();
|
||||
}
|
||||
return promise;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -106,7 +106,6 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
|||
object id;
|
||||
|
||||
// 9. For Debugger Attach
|
||||
[DebuggerHidden]
|
||||
public object ObjectIdForDebugger
|
||||
{
|
||||
get
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#if UNITASK_ADDRESSABLE_SUPPORT
|
||||
// asmdef Version Defines, enabled when com.unity.addressables is imported.
|
||||
|
||||
#if UNITASK_ADDRESSABLE_SUPPORT
|
||||
|
||||
using Cysharp.Threading.Tasks.Internal;
|
||||
using System;
|
||||
|
|
|
@ -356,11 +356,11 @@ namespace Cysharp.Threading.Tasks.Triggers
|
|||
}
|
||||
else
|
||||
{
|
||||
if (handlers != null)
|
||||
if (handlers == null)
|
||||
{
|
||||
handlers = new List<AsyncTriggerHandler<T>>();
|
||||
handlers.Add(handler);
|
||||
}
|
||||
handlers.Add(handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,11 +31,18 @@ namespace Cysharp.Threading.Tasks.Triggers
|
|||
static T GetOrAddComponent<T>(GameObject gameObject)
|
||||
where T : Component
|
||||
{
|
||||
#if UNITY_2019_2_OR_NEWER
|
||||
if (!gameObject.TryGetComponent<T>(out var component))
|
||||
{
|
||||
component = gameObject.AddComponent<T>();
|
||||
}
|
||||
#else
|
||||
var component = gameObject.GetComponent<T>();
|
||||
if (component == null)
|
||||
{
|
||||
component = gameObject.AddComponent<T>();
|
||||
}
|
||||
#endif
|
||||
|
||||
return component;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Cysharp.Threading.Tasks.Triggers;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
@ -38,7 +39,19 @@ public class SandboxMain : MonoBehaviour
|
|||
CancellationTokenSource cts;
|
||||
|
||||
UniTaskCompletionSource ucs;
|
||||
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 UniTask RunStandardDelayAsync()
|
||||
|
@ -57,7 +70,7 @@ public class SandboxMain : MonoBehaviour
|
|||
|
||||
var scheduled = job.Schedule();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
UnityEngine.Debug.Log("OK");
|
||||
|
@ -76,7 +89,7 @@ public class SandboxMain : MonoBehaviour
|
|||
ShowPlayerLoop.DumpPlayerLoop("Current", playerLoop);
|
||||
|
||||
|
||||
RunStandardDelayAsync().Forget();
|
||||
//RunStandardDelayAsync().Forget();
|
||||
|
||||
//for (int i = 0; i < 14; i++)
|
||||
//{
|
||||
|
@ -89,7 +102,10 @@ public class SandboxMain : MonoBehaviour
|
|||
|
||||
// -----
|
||||
|
||||
RunJobAsync().Forget();
|
||||
// RunJobAsync().Forget();
|
||||
|
||||
//ClickOnce().Forget();
|
||||
//ClickForever().Forget();
|
||||
|
||||
//var cor = UniTask.ToCoroutine(async () =>
|
||||
// {
|
||||
|
@ -102,26 +118,101 @@ public class SandboxMain : MonoBehaviour
|
|||
//StartCoroutine(cor);
|
||||
|
||||
|
||||
//this.TryGetComponent(
|
||||
|
||||
|
||||
CancellationTokenSource cts = new CancellationTokenSource();
|
||||
|
||||
var trigger = this.GetAsyncUpdateTrigger();
|
||||
Go(trigger, cts.Token).Forget();
|
||||
//Go(trigger).Forget();
|
||||
//Go(trigger).Forget();
|
||||
|
||||
|
||||
Application.logMessageReceived += Application_logMessageReceived;
|
||||
|
||||
|
||||
ucs = new UniTaskCompletionSource();
|
||||
//ucs = new UniTaskCompletionSource();
|
||||
|
||||
okButton.onClick.AddListener(async () =>
|
||||
//okButton.onClick.AddListener(async () =>
|
||||
//{
|
||||
// await InnerAsync(false);
|
||||
//});
|
||||
|
||||
okButton.onClick.AddListener(() =>
|
||||
{
|
||||
await InnerAsync(false);
|
||||
FooAsync().Forget();
|
||||
});
|
||||
|
||||
cancelButton.onClick.AddListener(async () =>
|
||||
cancelButton.onClick.AddListener(() =>
|
||||
{
|
||||
text.text = "";
|
||||
|
||||
// ucs.TrySetResult();
|
||||
|
||||
await ucs.Task;
|
||||
cts.Cancel();
|
||||
});
|
||||
}
|
||||
|
||||
async UniTaskVoid Go(AsyncUpdateTrigger trigger, CancellationToken ct)
|
||||
{
|
||||
await UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate);
|
||||
UnityEngine.Debug.Log("AWAIT BEFO:" + Time.frameCount);
|
||||
var handler = trigger.GetUpdateAsyncHandler(ct);
|
||||
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
await handler.UpdateAsync();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnityEngine.Debug.Log("AWAIT END:" + Time.frameCount);
|
||||
}
|
||||
}
|
||||
|
||||
async UniTaskVoid ClickOnce()
|
||||
{
|
||||
try
|
||||
{
|
||||
await okButton.OnClickAsync();
|
||||
UnityEngine.Debug.Log("CLICKED ONCE");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UnityEngine.Debug.Log(ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnityEngine.Debug.Log("END ONCE");
|
||||
}
|
||||
}
|
||||
|
||||
async UniTaskVoid ClickForever()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var handler = okButton.GetAsyncClickEventHandler())
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
await handler.OnClickAsync();
|
||||
UnityEngine.Debug.Log("Clicked");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UnityEngine.Debug.Log(ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnityEngine.Debug.Log("END");
|
||||
}
|
||||
}
|
||||
|
||||
async UniTask SimpleAwait()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
|
@ -174,7 +265,10 @@ public class SandboxMain : MonoBehaviour
|
|||
|
||||
private void Application_logMessageReceived(string condition, string stackTrace, LogType type)
|
||||
{
|
||||
text.text += "\n" + condition;
|
||||
if (text != null)
|
||||
{
|
||||
text.text += "\n" + condition;
|
||||
}
|
||||
}
|
||||
|
||||
async UniTask OuterAsync(bool b)
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue