Monday, December 8, 2014

CSG Post 7: The Wonderful World of Enumerators

Ive known that Enumerators have existed for some time now. But Ive never quite realized how powerful they were before I Started working on SOY. Enumerators allow you to perform operations on a timed delay that can be closely controlled. My first run in with Enumerators was at the 2014 Global Game where I used them with: "yield return new WaitForSeconds();" pretty much exclusively. This Enumerator function is plenty useful however soon after coming onto SOY I learned the power of combining loops with Enumerators. With loops you can have Enumerators delay indefinitely until a certain criteria is met. Another trick I learned is that you can substitute the Update method with an Enumerator and have the enumerator run at lower speeds resulting in a better performance Update Methods.

IEnumerator DelayTilCriteria()
{
   while(critera < 80)
  {
    critera++;
    if(breakOut == true)
     {
       break;
     }
    yield return new WaitForSeconds(1.0f);
  }
}

This snippet shows how you can Delay, Increment and Exit an Enumerator Coroutine.

No comments:

Post a Comment