using System; using System.Runtime.CompilerServices; using UnityEngine.Networking; namespace BulletHellTemplate { /// /// Provides extension methods for UnityWebRequestAsyncOperation to enable awaiting. /// public static class UnityWebRequestAsyncOperationExtensions { /// /// Returns an awaiter for UnityWebRequestAsyncOperation. /// /// The UnityWebRequestAsyncOperation instance. /// An awaiter for UnityWebRequestAsyncOperation. public static UnityWebRequestAsyncOperationAwaiter GetAwaiter(this UnityWebRequestAsyncOperation asyncOp) { return new UnityWebRequestAsyncOperationAwaiter(asyncOp); } } /// /// Awaiter implementation for UnityWebRequestAsyncOperation. /// public class UnityWebRequestAsyncOperationAwaiter : INotifyCompletion { private UnityWebRequestAsyncOperation asyncOp; /// /// Initializes a new instance of the UnityWebRequestAsyncOperationAwaiter class. /// /// The UnityWebRequestAsyncOperation instance to await. public UnityWebRequestAsyncOperationAwaiter(UnityWebRequestAsyncOperation asyncOp) { this.asyncOp = asyncOp; } /// /// Indicates whether the operation is completed. /// public bool IsCompleted => asyncOp.isDone; /// /// Schedules the continuation action to be invoked when the operation completes. /// /// The action to invoke upon completion. public void OnCompleted(Action continuation) { asyncOp.completed += _ => continuation(); } /// /// Returns the result of the operation. /// /// The UnityWebRequestAsyncOperation instance. public UnityWebRequestAsyncOperation GetResult() { return asyncOp; } } }