【发布时间】:2017-12-08 09:28:37
【问题描述】:
我们在使用 IEnumerator 时遇到了一些问题,并且不知道如何从中检索数组。我们发现您必须使用回调来执行此操作,但我们并不真正知道如何使用它。这是 IEnumerator 的代码和需要从中接收字符串数组的 void。
public void StartRoutineGetProjects(string username, string password, string url){
StartCoroutine(GetProjects(username, password, url));
// here we dont know how to receive the array, need some help here
}
public IEnumerator GetProjects (string username, string password, string url, Action<string[]> callback)
{
string privateURL = "http://" + url + "/Unity/myprojects.php";
WWWForm form = new WWWForm ();
form.AddField ("username", username);
form.AddField ("password", password);
// Send WWWForm
WWW projects_get = new WWW (privateURL, form);
if (projects_get.error != null && projects_get.error != "") {
Debug.Log ("Internal Error");
} else {
// splitting the result at "|"
string[] tempProjects = projects_get.text.Split ("|".ToCharArray ());
yield return tempProjects;
callback(tempProjects) // <-- here we want to return the array
}
}
我们会很高兴得到每一个帮助。
【问题讨论】:
标签: c# arrays callback delegates ienumerator