mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-16 20:20:45 +00:00
Add UniTask.WaitForFixedUpdate
This commit is contained in:
@@ -44,6 +44,22 @@ namespace Cysharp.Threading.Tasks
|
||||
return UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Same as UniTask.Yield(PlayerLoopTiming.FixedUpdate).
|
||||
/// </summary>
|
||||
public static YieldAwaitable WaitForFixedUpdate()
|
||||
{
|
||||
return UniTask.Yield(PlayerLoopTiming.FixedUpdate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Same as UniTask.Yield(PlayerLoopTiming.FixedUpdate, cancellationToken).
|
||||
/// </summary>
|
||||
public static UniTask WaitForFixedUpdate(CancellationToken cancellationToken)
|
||||
{
|
||||
return UniTask.Yield(PlayerLoopTiming.FixedUpdate, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (delayFrameCount < 0)
|
||||
|
||||
@@ -267,11 +267,11 @@ public class SandboxMain : MonoBehaviour
|
||||
//cts.Cancel();
|
||||
//await r;
|
||||
Debug.Log("SendWebRequestDone:" + PlayerLoopInfo.CurrentLoopType);
|
||||
|
||||
|
||||
// var foo = await UnityWebRequest.Get("https://bing.com/").SendWebRequest();
|
||||
// foo.downloadHandler.text;
|
||||
//
|
||||
|
||||
// var foo = await UnityWebRequest.Get("https://bing.com/").SendWebRequest();
|
||||
// foo.downloadHandler.text;
|
||||
//
|
||||
_ = await UnityWebRequest.Get("https://bing.com/").SendWebRequest().WithCancellation(CancellationToken.None);
|
||||
Debug.Log("SendWebRequestWithCancellationDone:" + PlayerLoopInfo.CurrentLoopType);
|
||||
}
|
||||
@@ -358,11 +358,39 @@ public class SandboxMain : MonoBehaviour
|
||||
StartCoroutine(CoroutineRun());
|
||||
}
|
||||
|
||||
async UniTaskVoid AsyncFixedUpdate()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
await UniTask.WaitForFixedUpdate();
|
||||
Debug.Log("Async:" + Time.frameCount + ", " + PlayerLoopInfo.CurrentLoopType);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator CoroutineFixedUpdate()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitForFixedUpdate();
|
||||
Debug.Log("Coroutine:" + Time.frameCount + ", " + PlayerLoopInfo.CurrentLoopType);
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Debug.Log("FixedUpdate:" + Time.frameCount + ", " + PlayerLoopInfo.CurrentLoopType);
|
||||
}
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
PlayerLoopInfo.Inject();
|
||||
|
||||
_ = AsyncFixedUpdate();
|
||||
StartCoroutine(CoroutineFixedUpdate());
|
||||
|
||||
|
||||
|
||||
okButton.onClick.AddListener(UniTask.UnityAction(async () =>
|
||||
{
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user