coroutine

How does StartCoroutine / yield return pattern really work in Unity?

…衆ロ難τιáo~ 提交于 2019-11-26 06:53:15
问题 I understand the principle of coroutines. I know how to get the standard StartCoroutine / yield return pattern to work in C# in Unity, e.g. invoke a method returning IEnumerator via StartCoroutine and in that method do something, do yield return new WaitForSeconds(1); to wait a second, then do something else. My question is: what\'s really going on behind the scenes? What does StartCoroutine really do? What IEnumerator is WaitForSeconds returning? How does StartCoroutine return control to the

Unity - need to return value only after coroutine finishes

折月煮酒 提交于 2019-11-26 03:45:07
问题 I\'m working on a game in unity and encountered an issue which I cannot solve. I\'m connecting to a web server via standard WWW object and using a coroutine in order to execute a POST request. The code in itself works, but I need to update a variable value and return that variable once the coroutine finishes, which I\'m not able to do. public int POST(string username, string passw) { WWWForm form = new WWWForm(); form.AddField(\"usr\", username); form.AddField(\"pass\", passw); WWW www = new

What does the “yield” keyword do?

佐手、 提交于 2019-11-25 23:55:21
问题 What is the use of the yield keyword in Python? What does it do? For example, I\'m trying to understand this code 1 : def _get_child_candidates(self, distance, min_dist, max_dist): if self._leftchild and distance - max_dist < self._median: yield self._leftchild if self._rightchild and distance + max_dist >= self._median: yield self._rightchild And this is the caller: result, candidates = [], [self] while candidates: node = candidates.pop() distance = node._get_dist(obj) if distance <= max