2012-08-17 71 views
-3

我想創建一個協程列表,以便將來啓動。如何將這些功能存儲在列表中?如何在列表中存儲協程?

假設我們有這樣一個功能:

IEnumerator Example() { 
    while (true) { 
     yield return new WaitForFixedUpdate(); 
    } 
} 

我們不能將它存儲裏面的東西一樣List<Func<IEnumerator >> list但我們得到的編譯器錯誤,如:

Error 1 The best overloaded method match for 'System.Collections.Generic.List<System.Func<System.Collections.IEnumerator>>.Add(System.Func<System.Collections.IEnumerator>)' has some invalid arguments 

當我們調用

  list.Add(Example); 

或者如果我們使用List<Example> list,我們不會收到編譯錯誤,但是在

  if (disposeActions.Any()) { 
       yield return StartCoroutine(list[0]); //here we get null exception 
       disposeActions.RemoveAt(0); 
      } 

所以我想知道如何創建一個列表來存儲IEnumerator函數並且能夠將它的項目發送到coutines?

+1

喜myWallJSON,感謝提高你的問題。我已投票重新提出問題的新版本,但您也可以在http://answers.unity3d.com – Jimmy 2012-08-17 17:44:51

+0

+1上找到答案並重新打開。我認爲這很有趣 – Kay 2012-08-18 06:21:41

回答

2

你提的問題是很難理解的,但也許你正在尋找的東西是這樣的:

var listOfFunctions = new List<Func<T, TResult>>(); 
+0

編譯器異常 - 請參閱後更新。 – myWallJSON 2012-08-17 17:31:57