Created
June 6, 2011 13:21
-
-
Save AngryAnt/1010234 to your computer and use it in GitHub Desktop.
An example of how to do delayed initialization - spreading heavy initialization workloads across multiple frames.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static int newID = 0; | |
private int id; | |
private bool initialized = false; | |
IEnumerator Start () | |
{ | |
id = newID++; | |
for (int i = 0; i < id; i++) | |
{ | |
yield return null; | |
} | |
// Do initialization | |
initialized = true; | |
} | |
void Update () | |
{ | |
if (!initialized) | |
{ | |
return; | |
} | |
// Do work | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment