{"id":216185,"date":"2014-03-18T11:39:03","date_gmt":"2014-03-18T07:39:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=216185"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=216185","title":{"rendered":"<span class=\"post_title\">\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u0432 Unity<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/d61\/e90\/5eb\/d61e905eb505a1669f207aef4e2cf2cb.jpg\" align=\"left\"\/><br \/>  \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b (Coroutines, \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b) \u0432 Unity \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0412 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043d\u0435\u0442 \u0438 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u043f\u043e\u043b\u043e\u043d \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u044b. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043c\u043d\u0435 \u0442\u0430\u043a \u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0433\u0434\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u0431\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0433\u0440\u0443\u043f\u043f\u044b \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0432 \u0441 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0441\u043b\u0435 \u0438\u0445 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f. <br \/>  \u0425\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0430\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0442\u0430\u043a\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u0434\u0431\u043e\u0440 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 C# \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0435 <b>IEnumerator<\/b> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <b>yield<\/b>. \u0412 Unity \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u043e \u043f\u0435\u0440\u0432\u043e\u0433\u043e <b>yield<\/b> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <b>StartCoroutine<\/b>. \u0414\u0430\u043b\u044c\u0448\u0435 Unity \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 Update \u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c LateUpdate, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044f \u043f\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u043c\u0443 \u0432 yield \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0431\u043b\u043e\u043a\u0443 \u043a\u043e\u0434\u0430. <\/p>\n<p>  \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0432 <b>yield<\/b> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:<\/p>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e FixedUpdate:  <\/p>\n<pre><code class=\"cs\">yield return new WaitForFixedUpdate(); <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e LateUpdate \u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u0441\u0446\u0435\u043d\u044b:  <\/p>\n<pre><code class=\"cs\">yield return WaitForEndOfFrame(); <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f:  <\/p>\n<pre><code class=\"cs\">yield return new WaitForSeconds(0.1f); \/\/ \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0447\u0435\u0440\u0435\u0437 100ms <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430:  <\/p>\n<pre><code class=\"cs\">yield return StartCoroutine(AnotherCoroutine()); <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430:  <\/p>\n<pre><code class=\"cs\">yield return new WWW(someLink); <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u043f\u0440\u043e\u0447\u0438\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0446\u0438\u043a\u043b\u0430 Update:  <\/p>\n<pre><code class=\"cs\">yield return null; <\/code><\/pre>\n<p>  \u0412\u044b\u0439\u0442\u0438 \u0438\u0437 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cs\">yield return break; <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <b>WaitForSeconds<\/b> \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u043b\u0433\u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 (\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u043a\u0443\u0447\u0435), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0431\u044b\u0441\u0442\u0440\u044b\u0445 \u0446\u0438\u043a\u043b\u0430\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043b\u043e\u0445\u043e\u0439 \u0438\u0434\u0435\u0435\u0439. <\/p>\n<p>  \u042f \u0443\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b, \u0447\u0442\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0442\u043e\u0447\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0442\u043e\u043a\u0435.<\/p>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430:<\/p>\n<pre><code class=\"cs\">void Start() { \tStartCoroutine(TestCoroutine()); }  IEnumerator TestCoroutine() { \twhile(true) \t{ \t\tyield return null; \t\tDebug.Log(Time.deltaTime); \t} } <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0441 \u0446\u0438\u043a\u043b\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u0440\u0435\u043c\u044f, \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0435\u0435 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0430. <br \/>  \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <i>yield return null<\/i>, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u0438\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043b\u043e\u0433. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 <i>StartCoroutine(TestCoroutine())<\/i>, \u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0431\u043b\u043e\u043a\u0443 \u043a\u043e\u0434\u0430 \u043f\u043e\u0441\u043b\u0435 <i>yield return null<\/i> \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0451\u043d \u043f\u043e\u0441\u043b\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <b>Update<\/b>, \u0442\u0430\u043a \u0447\u0442\u043e \u0438 \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e <i>yield return null<\/i> <b>Time.deltaTime<\/b> \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0441 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u0432\u0441\u0451 \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0440\u0432\u0430\u0442\u044c, \u0432\u044b\u0437\u0432\u0430\u0432 <b>StopAllCoroutines()<\/b>, <b>StopCoroutine(\u00abTestCoroutine\u00bb)<\/b>, \u0438\u043b\u0438 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0438\u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 GameObject.<\/p>\n<p>  \u0425\u043e\u0440\u043e\u0448\u043e. \u0417\u043d\u0430\u0447\u0438\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0432 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u044b, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0444\u0440\u0435\u0439\u043c, \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u044b\u0445 \u0434\u0440\u0443\u0433 \u0437\u0430 \u0434\u0440\u0443\u0433\u043e\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0432, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0438\u0438 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0439, \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044d\u0442\u0430\u043f\u0430\u0445. \u0418\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0431\u0435\u0437 <i>yield return<\/i> \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435. \u041d\u043e \u043a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0432, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u0438\u0445 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e? <\/p>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043a\u043e\u0440\u0443\u0442\u0438\u043d, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435:<\/p>\n<p>  \u041a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u0434\u0432\u0438\u0433\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cs\">public bool IsMoving = false;  IEnumerator MoveCoroutine(Vector3 moveTo) { \tIsMoving = true; \t \t\/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a \u043d\u043e\u0432\u043e\u0439 \tvar iniPosition = transform.position; \twhile (transform.position != moveTo) \t{ \t\t\/\/ \u0442\u0443\u0442 \u043c\u0435\u043d\u044f\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0438 \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0435\u0433\u043e \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \t\t\/\/ \u0438 \u0436\u0434\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0430 \t\tyield return null; \t} \t \tIsMoving = false; } <\/code><\/pre>\n<p>  \u041a\u043b\u0430\u0441\u0441, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0441 \u0433\u0440\u0443\u043f\u043f\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0432\u0438\u0433\u0430\u0442\u044c: <\/p>\n<pre><code class=\"cs\">IEnumetaror PerformMovingCoroutine() { \t\/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u0435\u043b\u0430  \tforeach(MovableObjectScript s in objectsToMove) \t{ \t\t\/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \t\tStartCoroutine(s.MoveCoroutine(moveTo)); \t}  \tbool isMoving = true; \twhile (isMoving)  \t{ \t\tisMoving = false; \t\tArray.ForEach(objectsToMove, s =&gt; { if (s.IsMoving) isMoving = true; } \t\tif (isMoving) yield return null; \t}  \t\/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0449\u0435 \u0434\u0435\u043b\u0430 } <\/code><\/pre>\n<p>  \u0411\u043b\u043e\u043a \u00ab\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0449\u0435 \u0434\u0435\u043b\u0430\u00bb \u043d\u0430\u0447\u043d\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 <b>MoveCoroutine<\/b> \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 <b>objectsToMove<\/b>.<\/p>\n<p>  \u0427\u0442\u043e \u0436, \u0443\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0439. <br \/>  \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0443 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0432, \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0438 \u0432 \u043b\u044e\u0431\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430 \u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u0430 \u0440\u0430\u0431\u043e\u0442\u0443?<br \/>  \u0421\u0434\u0435\u043b\u0430\u0435\u043c! <\/p>\n<p>  \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u0441\u0451 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">public static class CoroutineExtension { \t\/\/ \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c &lt;\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0433\u0440\u0443\u043f\u043f\u044b, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0432&gt; \tstatic private readonly Dictionary&lt;string, int&gt; Runners = new Dictionary&lt;string, int&gt;();  \t\/\/ MonoBehaviour \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \tpublic static void ParralelCoroutinesGroup(this IEnumerator coroutine, MonoBehaviour parent, string groupName) \t{ \t\tif (!Runners.ContainsKey(groupName)) \t\t\tRunners.Add(groupName, 0);  \t\tRunners[groupName]++; \t\tparent.StartCoroutine(DoParallel(coroutine, parent, groupName)); \t} \t  \tstatic IEnumerator DoParallel(IEnumerator coroutine, MonoBehaviour parent, string groupName) \t{ \t\tyield return parent.StartCoroutine(coroutine); \t\tRunners[groupName]--; \t} \t \t\/\/ \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c, \u0447\u0442\u043e \u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u0433\u0440\u0443\u043f\u043f\u0435 \u043d\u0435\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \tpublic static bool GroupProcessing(string groupName) \t{ \t\treturn (Runners.ContainsKey(groupName) && Runners[groupName] &gt; 0); \t} } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445 \u043c\u0435\u0442\u043e\u0434 <b>ParralelCoroutinesGroup<\/b> \u0438 \u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u043a\u0430 \u043c\u0435\u0442\u043e\u0434 <b>CoroutineExtension.GroupProcessing<\/b> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true:<\/p>\n<pre><code class=\"cs\">public class CoroutinesTest : MonoBehaviour {  \t\/\/ Use this for initialization \tvoid Start() \t{ \t\tStartCoroutine(GlobalCoroutine()); \t}  \tIEnumerator GlobalCoroutine() \t{ \t\tfor (int i = 0; i &lt; 5; i++) \t\t\tRegularCoroutine(i).ParralelCoroutinesGroup(this, &quot;test&quot;);  \t\twhile (CoroutineExtension.GroupProcessing(&quot;test&quot;)) \t\t\tyield return null;  \t\tDebug.Log(&quot;Group 1 finished&quot;);  \t\tfor (int i = 10; i &lt; 15; i++) \t\t\tRegularCoroutine(i).ParralelCoroutinesGroup(this, &quot;anotherTest&quot;);  \t\twhile (CoroutineExtension.GroupProcessing(&quot;anotherTest&quot;)) \t\t\tyield return null;  \t\tDebug.Log(&quot;Group 2 finished&quot;); \t}  \tIEnumerator RegularCoroutine(int id) \t{ \t\tint iterationsCount = Random.Range(1, 5);  \t\tfor (int i = 1; i &lt;= iterationsCount; i++) \t\t{ \t\t\tyield return new WaitForSeconds(1); \t\t}  \t\tDebug.Log(string.Format(&quot;{0}: Coroutine {1} finished&quot;, Time.realtimeSinceStartup, id)); \t} }  <\/code><\/pre>\n<p>  \u0413\u043e\u0442\u043e\u0432\u043e!<\/p>\n<p>  <img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/34d\/aaa\/36c\/34daaa36c5f44af59f6c48e19e86f17e.png\" align=\"left\"\/> \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/216185\/\"> http:\/\/habrahabr.ru\/post\/216185\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/d61\/e90\/5eb\/d61e905eb505a1669f207aef4e2cf2cb.jpg\" align=\"left\"\/><br \/>  \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b (Coroutines, \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b) \u0432 Unity \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0412 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043d\u0435\u0442 \u0438 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u043f\u043e\u043b\u043e\u043d \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u044b. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043c\u043d\u0435 \u0442\u0430\u043a \u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0433\u0434\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u0431\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0433\u0440\u0443\u043f\u043f\u044b \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u043e\u0432 \u0441 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0441\u043b\u0435 \u0438\u0445 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f. <br \/>  \u0425\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0430\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0442\u0430\u043a\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u0434\u0431\u043e\u0440 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u0445.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-216185","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/216185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=216185"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/216185\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=216185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=216185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=216185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}