Created
July 11, 2012 23:26
-
-
Save jakevsrobots/3094417 to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class ClosureTest : MonoBehaviour { | |
void Start () { | |
List<int> sourceData = new List<int>(); | |
for(int i=0; i < 10; i++) { | |
sourceData.Add(i); | |
} | |
Action<int> dataProcessor = delegate(int datum) { | |
Debug.Log(datum); | |
}; | |
StartCoroutine(RunClosureTest(sourceData, dataProcessor)); | |
} | |
private IEnumerator RunClosureTest(List<int> data, Action<int> dataProcessorAction) { | |
List<Action> todo = new List<Action>(); | |
for(int i=0; i < data.Count; i++) { | |
AddDelegate(todo, i, dataProcessorAction); | |
yield return null; | |
} | |
foreach(Action action in todo) { | |
action(); | |
} | |
} | |
private void AddDelegate(List<Action> originalList, int value, Action<int> dataProcessorAction) { | |
originalList.Add(delegate() { | |
dataProcessorAction(value); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment