mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-19 21:50:08 +00:00
export
This commit is contained in:
@@ -12,7 +12,7 @@ public static class PackageExporter
|
|||||||
public static void Export()
|
public static void Export()
|
||||||
{
|
{
|
||||||
// configure
|
// configure
|
||||||
var root = "UniTask";
|
var root = "Plugins/UniTask";
|
||||||
var exportPath = "./UniTask.unitypackage";
|
var exportPath = "./UniTask.unitypackage";
|
||||||
|
|
||||||
var path = Path.Combine(Application.dataPath, root);
|
var path = Path.Combine(Application.dataPath, root);
|
||||||
|
|||||||
@@ -136,19 +136,31 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
|||||||
// don't use boxed stateMachine.
|
// don't use boxed stateMachine.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG || !UNITY_2018_3_OR_NEWER
|
||||||
|
|
||||||
|
object id;
|
||||||
|
|
||||||
// 9. For Debugger Attach
|
// 9. For Debugger Attach
|
||||||
[DebuggerHidden]
|
|
||||||
public object ObjectIdForDebugger
|
public object ObjectIdForDebugger
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
id = new object();
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
/*
|
||||||
if (promise == null)
|
if (promise == null)
|
||||||
{
|
{
|
||||||
promise = AutoResetUniTaskCompletionSource.Create();
|
promise = AutoResetUniTaskCompletionSource.Create();
|
||||||
}
|
}
|
||||||
return promise;
|
return promise;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Auto)]
|
[StructLayout(LayoutKind.Auto)]
|
||||||
@@ -281,18 +293,30 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
|||||||
// don't use boxed stateMachine.
|
// don't use boxed stateMachine.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG || !UNITY_2018_3_OR_NEWER
|
||||||
|
|
||||||
|
object id;
|
||||||
|
|
||||||
// 9. For Debugger Attach
|
// 9. For Debugger Attach
|
||||||
[DebuggerHidden]
|
|
||||||
public object ObjectIdForDebugger
|
public object ObjectIdForDebugger
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
id = new object();
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
/*
|
||||||
if (promise == null)
|
if (promise == null)
|
||||||
{
|
{
|
||||||
promise = AutoResetUniTaskCompletionSource<T>.Create();
|
promise = AutoResetUniTaskCompletionSource<T>.Create();
|
||||||
}
|
}
|
||||||
return promise;
|
return promise;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,6 @@ namespace Cysharp.Threading.Tasks.CompilerServices
|
|||||||
object id;
|
object id;
|
||||||
|
|
||||||
// 9. For Debugger Attach
|
// 9. For Debugger Attach
|
||||||
[DebuggerHidden]
|
|
||||||
public object ObjectIdForDebugger
|
public object ObjectIdForDebugger
|
||||||
{
|
{
|
||||||
get
|
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 Cysharp.Threading.Tasks.Internal;
|
||||||
using System;
|
using System;
|
||||||
|
|||||||
@@ -356,11 +356,11 @@ namespace Cysharp.Threading.Tasks.Triggers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (handlers != null)
|
if (handlers == null)
|
||||||
{
|
{
|
||||||
handlers = new List<AsyncTriggerHandler<T>>();
|
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)
|
static T GetOrAddComponent<T>(GameObject gameObject)
|
||||||
where T : Component
|
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>();
|
var component = gameObject.GetComponent<T>();
|
||||||
if (component == null)
|
if (component == null)
|
||||||
{
|
{
|
||||||
component = gameObject.AddComponent<T>();
|
component = gameObject.AddComponent<T>();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Cysharp.Threading.Tasks.Triggers;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -38,7 +39,19 @@ public class SandboxMain : MonoBehaviour
|
|||||||
CancellationTokenSource cts;
|
CancellationTokenSource cts;
|
||||||
|
|
||||||
UniTaskCompletionSource ucs;
|
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()
|
async UniTask RunStandardDelayAsync()
|
||||||
@@ -57,7 +70,7 @@ public class SandboxMain : MonoBehaviour
|
|||||||
|
|
||||||
var scheduled = job.Schedule();
|
var scheduled = job.Schedule();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UnityEngine.Debug.Log("OK");
|
UnityEngine.Debug.Log("OK");
|
||||||
@@ -76,7 +89,7 @@ public class SandboxMain : MonoBehaviour
|
|||||||
ShowPlayerLoop.DumpPlayerLoop("Current", playerLoop);
|
ShowPlayerLoop.DumpPlayerLoop("Current", playerLoop);
|
||||||
|
|
||||||
|
|
||||||
RunStandardDelayAsync().Forget();
|
//RunStandardDelayAsync().Forget();
|
||||||
|
|
||||||
//for (int i = 0; i < 14; i++)
|
//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 () =>
|
//var cor = UniTask.ToCoroutine(async () =>
|
||||||
// {
|
// {
|
||||||
@@ -102,26 +118,101 @@ public class SandboxMain : MonoBehaviour
|
|||||||
//StartCoroutine(cor);
|
//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;
|
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 = "";
|
text.text = "";
|
||||||
|
|
||||||
// ucs.TrySetResult();
|
// 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()
|
async UniTask SimpleAwait()
|
||||||
{
|
{
|
||||||
await UniTask.Yield();
|
await UniTask.Yield();
|
||||||
@@ -174,7 +265,10 @@ public class SandboxMain : MonoBehaviour
|
|||||||
|
|
||||||
private void Application_logMessageReceived(string condition, string stackTrace, LogType type)
|
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)
|
async UniTask OuterAsync(bool b)
|
||||||
|
|||||||
BIN
src/UniTask/UniTask.unitypackage
Normal file
BIN
src/UniTask/UniTask.unitypackage
Normal file
Binary file not shown.
Reference in New Issue
Block a user