WaitForTaskCompletionYieldInstruction.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using UnityEngine;
  12. /// <summary>
  13. /// A yield instruction that blocks a coroutine until an AsyncTask has completed. </summary>
  14. /// <typeparam name="T"> The type of the AsyncTask result.</typeparam>
  15. public class WaitForTaskCompletionYieldInstruction<T> : CustomYieldInstruction
  16. {
  17. /// <summary> The AsyncTask the yield instruction waits on. </summary>
  18. private AsyncTask<T> m_Task;
  19. /// <summary> Constructor for WaitForTaskCompletionYieldInstruction. </summary>
  20. /// <param name="task"> The task to wait for completion.</param>
  21. public WaitForTaskCompletionYieldInstruction(AsyncTask<T> task)
  22. {
  23. m_Task = task;
  24. }
  25. /// <summary>
  26. /// Gets a value indicating whether the coroutine instruction should keep waiting. </summary>
  27. /// <value> <c>true</c> if the task is incomplete, otherwise <c>false</c>. </value>
  28. public override bool keepWaiting
  29. {
  30. get
  31. {
  32. return !m_Task.IsComplete;
  33. }
  34. }
  35. }
  36. }