Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pjv:laboratoare:2023:03 [2023/10/23 09:45]
alexandru.gradinaru
pjv:laboratoare:2023:03 [2024/10/07 10:48] (current)
alexandru.gradinaru
Line 1: Line 1:
-===== Transformari de baza =====+===== 3. Transformari de baza =====
  
 ==== Cerinte ===== ==== Cerinte =====
Line 208: Line 208:
   * If you want to use asynchronous execution to utilize multiple CPU cores, use threads.   * If you want to use asynchronous execution to utilize multiple CPU cores, use threads.
 </​note>​ </​note>​
 +
 +> **Coroutines**
 +
 +<code c#>
 +/* Create a Coroutine */
 +private IEnumerator CountSeconds(int count = 10)
 +{
 +  for (int i = 0; i <= count; i++) {
 +    Debug.Log(i + " second(s) have passed"​);​
 +    yield return new WaitForSeconds(1.0f);​
 +  }
 +}
 +
 +/* Call a Coroutine */
 +StartCoroutine(CountSeconds());​
 +StartCoroutine(CountSeconds(10));​
 +
 +/* Call a Coroutine that may need to be stopped */
 +StartCoroutine("​CountSeconds"​);​
 +StartCoroutine("​CountSeconds",​ 10);
 +
 +/* Stop a Coroutine */
 +StopCoroutine("​CountSeconds"​);​
 +StopAllCoroutines();​
 +
 +/* Store and call a Coroutine from a variable */
 +private IEnumerator countSecondsCoroutine;​
 +
 +countSecondsCoroutine = CountSeconds();​
 +StartCoroutine(countSecondsCoroutine);​
 +
 +/* Stop a stored Coroutine */
 +StopCoroutine(countSecondsCoroutine);​
 +
 +/* Coroutine Return Types */
 +yield return null; // Waits until the next Update() call
 +yield return new WaitForFixedUpdate();​ // Waits until the next FixedUpdate() call
 +yield return new WaitForEndOfFrame();​ // Waits until everything this frame has executed
 +yield return new WaitForSeconds(float seconds); // Waits for game time in seconds
 +yield return new WaitUntil(() => MY_CONDITION);​ // Waits until a custom condition is met
 +yield return new WWW("​MY/​WEB/​REQUEST"​);​ // Waits for a web request
 +yield return StartCoroutine("​MY_COROUTINE"​);​ // Waits until another Coroutine is completed
 +
 +</​code>​
  
  
pjv/laboratoare/2023/03.1698043532.txt.gz ยท Last modified: 2023/10/23 09:45 by alexandru.gradinaru
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0