{"id":202,"date":"2014-07-10T21:39:12","date_gmt":"2014-07-10T12:39:12","guid":{"rendered":"http:\/\/naochang.me\/?p=202"},"modified":"2015-10-14T20:33:52","modified_gmt":"2015-10-14T11:33:52","slug":"%e3%82%b3%e3%83%ab%e3%83%bc%e3%83%81%e3%83%b3%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"https:\/\/stacstar.jp\/blog\/?p=202","title":{"rendered":"\u30b3\u30eb\u30fc\u30c1\u30f3\u306b\u3064\u3044\u3066"},"content":{"rendered":"<p>\u3042\u307e\u308a\u7406\u89e3\u305b\u305a\u306b\u30b3\u30eb\u30fc\u30c1\u30f3\u3092\u4f7f\u7528\u3057\u3066\u3044\u305f\u306e\u3067\u3001\u3082\u3046\u5c11\u3057\u3061\u3083\u3093\u3068\u7406\u89e3\u3057\u3088\u3046\u3068\u898b\u76f4\u3057\u3066\u307f\u305f\u3002<br \/>\n\u305d\u3082\u305d\u3082\u30b3\u30eb\u30fc\u30c1\u30f3\u3068\u306f\u3002\u3002\u3002<br \/>\n\u4ee5\u4e0bWikipedia\u3088\u308a\u3002<\/p>\n<blockquote><p>\n\u30b3\u30eb\u30fc\u30c1\u30f3\uff08\u82f1: co-routine\uff09\u3068\u306f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u69cb\u9020\u306e\u4e00\u7a2e\u3002\u30b5\u30d6\u30eb\u30fc\u30c1\u30f3\u304c\u30a8\u30f3\u30c8\u30ea\u30fc\u304b\u3089\u30ea\u30bf\u30fc\u30f3\u307e\u3067\u3092\u4e00\u3064\u306e\u51e6\u7406\u5358\u4f4d\u3068\u3059\u308b\u306e\u306b\u5bfe\u3057\u3001\u30b3\u30eb\u30fc\u30c1\u30f3\u306f\u3044\u3063\u305f\u3093\u51e6\u7406\u3092\u4e2d\u65ad\u3057\u305f\u5f8c\u3001\u7d9a\u304d\u304b\u3089\u51e6\u7406\u3092\u518d\u958b\u3067\u304d\u308b\u3002\u63a5\u982d\u8f9e co \u306f\u5354\u8abf\u3092\u610f\u5473\u3059\u308b\u304c\u3001\u8907\u6570\u306e\u30b3\u30eb\u30fc\u30c1\u30f3\u304c\u4e2d\u65ad\u30fb\u7d99\u7d9a\u306b\u3088\u308a\u5354\u8abf\u52d5\u4f5c\u3092\u884c\u3046\u3053\u3068\u306b\u3088\u308b\u3002<br \/>\n\u30b5\u30d6\u30eb\u30fc\u30c1\u30f3\u3068\u7570\u306a\u308a\u3001\u72b6\u614b\u7ba1\u7406\u3092\u610f\u8b58\u305b\u305a\u306b\u884c\u3048\u308b\u305f\u3081\u3001\u5354\u8abf\u7684\u51e6\u7406\u3001\u30a4\u30c6\u30ec\u30fc\u30bf\u3001\u7121\u9650\u30ea\u30b9\u30c8\u3001\u30d1\u30a4\u30d7\u306a\u3069\u3001\u7d99\u7d9a\u72b6\u6cc1\u3092\u6301\u3064\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u5bb9\u6613\u306b\u8a18\u8ff0\u3067\u304d\u308b\u3002<br \/>\n\u30b3\u30eb\u30fc\u30c1\u30f3\u306f\u30b5\u30d6\u30eb\u30fc\u30c1\u30f3\u3092\u4e00\u822c\u5316\u3057\u305f\u3082\u306e\u3068\u8003\u3048\u3089\u308c\u308b\u3002\u30b3\u30eb\u30fc\u30c1\u30f3\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u8a00\u8a9e\u306b\u306f Modula-2\u3001Simula\u3001Icon\u3001Lua\u3001C#\u3001Limbo \u306a\u3069\u304c\u3042\u308b\u3002\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u3067\u539f\u7406\u7684\u306b\u306f\u540c\u3058\u3053\u3068\u304c\u3067\u304d\u308b\u305f\u3081\u3001\u73fe\u5728\u306f\u305d\u3061\u3089\u304c\u4f7f\u308f\u308c\u308b\u30b1\u30fc\u30b9\u304c\u591a\u3044\u3002\n<\/p><\/blockquote>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u51e6\u7406\u3092\u4e2d\u65ad\u3057\u518d\u3073\u547c\u3073\u51fa\u3059\u3068\u7d9a\u304d\u304b\u3089\u518d\u958b\u3067\u304d\u308b\u3068\u3044\u3046\u3053\u3068\u306e\u3088\u3046\u3067\u3059\u3002<br \/>\n<!--more--><br \/>\nC#\u3067\u306fIEnumerator\u3068\u3044\u3046\u578b\u304c\u3042\u3063\u3066\u3053\u308c\u3067\u30b3\u30eb\u30fc\u30c1\u30f3\u3092\u5b9f\u73fe\u3067\u304d\u308b\u3002Enumerator(\u6570\u3048\u4e0a\u3052)\u3068\u3044\u3046\u3088\u3046\u306b\u3001Iterator\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u5b9f\u88c5\u304c\u3055\u308c\u3066\u3044\u3066\u3001<a href=\"http:\/\/msdn.microsoft.com\/ja-jp\/library\/System.Collections.IEnumerator_methods(v=vs.110).aspx\" target=\"_blank\">\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u3092\u898b\u3066\u307f\u308b\u3068<\/a>MoveNext()\u3068Reset()\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308b\u3002MoveNext()\u306e\u623b\u308a\u5024\u306fbool\u3067\u3001\u6b21\u306e\u6570\u3048\u4e0a\u3052\u304c\u53ef\u80fd\u304b\u3069\u3046\u304b\u304c\u8fd4\u3063\u3066\u304f\u308b\u3002<\/p>\n<p>\u51e6\u7406\u3092\u4e2d\u65ad\u3059\u308b\u306b\u306f yield \u3068\u3044\u3046\u30ad\u30fc\u30ef\u30fc\u30c9\u3067\u3001<br \/>\nyield return 0;<br \/>\n\u3068\u66f8\u304f\u3068\u51e6\u7406\u3092\u4e2d\u65ad\u3067\u304d\u308b\u3002<br \/>\nreturn \u306e\u5f8c\u308d\u306fIEnumerator\u578b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u73fe\u5728\u306e\u5024\u3068\u3057\u305f\u3044\u3082\u306e\u3092\u8fd4\u3059\u3068\u4fdd\u6301\u3055\u308c\u308b\u3002<br \/>\nyield break;<br \/>\n\u3068\u66f8\u304f\u3068\u305d\u308c\u4ee5\u4e0a\u306e\u6570\u3048\u4e0a\u3052\u3092\u4e2d\u6b62\u3067\u304d\u308b\u3002<\/p>\n<p>\u3053\u308c\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u305f\u3073\u306b\u30b3\u30eb\u30fc\u30c1\u30f3\u306e\u51e6\u7406\u3092\u547c\u3073\u51fa\u3059\u30b5\u30f3\u30d7\u30eb\u306f\u3053\u3061\u3089\u3002<\/p>\n<pre class=\"brush: unitycsharp; title: ; notranslate\" title=\"\">\r\nIEnumerator coroutine;\r\n\r\nvoid Awake() {\r\n\tthis.coroutine = Routine();\r\n}\r\n\r\nvoid OnGUI() {\r\n\tif (GUI.Button(new Rect(Screen.width \/ 2 - 80, Screen.height \/ 2 - 15, 160, 30), &quot;test&quot;)) {\r\n\t\tbool hasNext = this.coroutine.MoveNext();\r\n\r\n\t\tif (!hasNext) {\r\n\t\t\t\/\/ this.coroutine.Reset(); \/\/ NotSupportedException\u304c\u51fa\u308b\r\n\t\t\tthis.coroutine = Routine();\r\n\t\t\tprint(&quot;Reset&quot;);\r\n\t\t}\r\n\t\telse {\r\n\t\t\tprint(&quot;current : &quot; + this.coroutine.Current);\r\n\t\t}\r\n\t}\r\n}\r\n\r\nIEnumerator Routine() {\r\n\tprint(&quot;Coroutine-1&quot;);\r\n\tyield return 1;\r\n\tprint(&quot;Coroutine-2&quot;);\r\n\tyield return 2;\r\n\tprint(&quot;Coroutine-3&quot;);\r\n\tyield return 3;\r\n}\r\n\r\n\/*\r\nCoroutine-1\r\ncurrent : 1\r\nCoroutine-2\r\ncurrent : 2\r\nCoroutine-3\r\ncurrent : 3\r\nReset\r\n\u4ee5\u4e0b\u7e70\u308a\u8fd4\u3057\r\n*\/\r\n<\/pre>\n<p>\u6570\u3048\u4e0a\u3052\u306f\u3082\u3061\u308d\u3093\u306a\u3093\u3060\u3051\u3069\u3001\u3053\u308c\u3092\u4f7f\u3046\u3068\u72b6\u614b\u7ba1\u7406\u306a\u3093\u304b\u3092\u3057\u306a\u304f\u3068\u3082\u30e6\u30fc\u30b6\u30fc\u306e\u30a4\u30f3\u30bf\u30e9\u30af\u30b7\u30e7\u30f3\u3068\u3068\u3082\u306b\u9077\u79fb\u3059\u308b\u3088\u3046\u306a\u3082\u306e\u3082\u4f5c\u308c\u305d\u3046\u3002\u3061\u306a\u307f\u306bIEnumerator.Reset()\u306f\u5b9f\u88c5\u3055\u308c\u3066\u3044\u306a\u3044\u3068NotSupportedException\u3068\u306a\u308a\u547c\u3073\u51fa\u305b\u306a\u3044\u3002<\/p>\n<p><strong>\u4fbf\u5229\u306a\u30b3\u30eb\u30fc\u30c1\u30f3\u3060\u3051\u3069\u3001Unity\u3067\u306f\u91cd\u305f\u3044\u51e6\u7406\u3092\u30d5\u30ec\u30fc\u30e0\u3054\u3068\u306b\u5206\u3051\u3066\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b<a href=\"http:\/\/docs.unity3d.com\/ScriptReference\/MonoBehaviour.StartCoroutine.html\" target=\"_blank\">StartCoroutine(IEnumerator routine)<\/a>\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u3002<\/strong><br \/>\nStartCoroutine\u3067\u6307\u5b9a\u3057\u305f\u51e6\u7406\u306fyield return\u3055\u308c\u308b\u5ea6\u3001\u6bce\u30d5\u30ec\u30fc\u30e0\u518d\u5ea6\u547c\u3073\u51fa\u3057\u304c\u3055\u308c\u3066\u51e6\u7406\u304c\u7d42\u308f\u308b\u307e\u3067\u7d9a\u304f\u3002<br \/>\nStartCoroutine()\u306e\u623b\u308a\u5024\u306f<a href=\"http:\/\/docs.unity3d.com\/ScriptReference\/Coroutine.html\" target=\"_blank\">Coroutine<\/a>\u578b\u3067\u3001\u3053\u3044\u3064\u306e\u89aa\u30af\u30e9\u30b9\u306f<a href=\"http:\/\/docs.unity3d.com\/ScriptReference\/YieldInstruction.html\" title=\"YieldInstruction\" target=\"_blank\">YieldInstruction<\/a>\u3068\u3044\u3046\u3001yield\u306b\u4f7f\u308f\u308c\u308b\u623b\u308a\u5024\u3092\u8fd4\u3057\u3066\u304f\u308c\u308b\u3002StartCoroutine()\u3092\u547c\u3076\u969b\u306b yield return StartCoroutine() \u3068\u3057\u3066\u3084\u308b\u3068\u30b3\u30eb\u30fc\u30c1\u30f3\u3067\u6307\u5b9a\u3057\u305f\u51e6\u7406\u304c\u7d42\u308f\u3063\u305f\u5f8c\u306b\u51e6\u7406\u304c\u518d\u958b\u3055\u308c\u308b\u3002<br \/>\n\u901a\u5e38IEnumerator\u306f\u6570\u3048\u4e0a\u3052\u306e\u6a5f\u80fd\u3067\u3001yield return **\u3067\u8fd4\u3057\u305f\u5024\u306f\u5148\u306e\u30b5\u30f3\u30d7\u30eb\u306e\u3088\u3046\u306b\u73fe\u5728\u306e\u5024\u3068\u3057\u3066\u4fdd\u5b58\u3055\u308c\u308b\u3002\u305d\u308c\u3092Unity\u3067\u306fYieldInstruction\u578b(WaitForSeconds, WaitForFixedUpdate, Coroutine\u306a\u3069)\u3092yield return\u3055\u305b\u308b\u3068\u3001\u6e21\u3055\u308c\u305f\u30b3\u30eb\u30fc\u30c1\u30f3\u306e\u51e6\u7406\u3092\u7d42\u3048\u305f\u3042\u3068\u547c\u3073\u51fa\u3057\u5143\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u51e6\u7406\u3092\u518d\u958b\u3055\u305b\u308b\u3088\u3046\u306b\u3057\u3066\u3042\u308b\u3002(\u3068\u3044\u3046\u89e3\u91c8\u3067\u3044\u3044\u306e\u3067\u3057\u3087\u3046\u304b??)<\/p>\n<pre class=\"brush: unitycsharp; title: ; notranslate\" title=\"\">\r\n\/\/\/ &lt;summary&gt;\r\n\/\/\/ Awake.\r\n\/\/\/ &lt;\/summary&gt;\r\nIEnumerator Start() {\r\n\tprint(&quot;Start start&quot;);\r\n\tStartCoroutine(this.Method(&quot;A&quot;)); \/\/ \u51e6\u7406\u3092\u5f85\u305f\u306a\u3044\r\n\tprint(&quot;yield&quot;);\r\n\tyield return StartCoroutine(this.Method(&quot;B&quot;)); \/\/ \u51e6\u7406\u3092\u5f85\u3064\r\n\tprint(&quot;Start end&quot;);\r\n}\r\n\r\n\/\/\/ &lt;summary&gt;\r\n\/\/\/ \u30b5\u30f3\u30d7\u30eb\u30e1\u30bd\u30c3\u30c9\u3002\r\n\/\/\/ &lt;\/summary&gt;\r\nIEnumerator Method(string param) {\r\n\tprint(&quot;Method start &quot; + param);\r\n\tyield return new WaitForSeconds(1f);\r\n\tprint(&quot;Method end &quot; + param);\r\n}\r\n\r\n\/*\r\n\u7d50\u679c\r\nStart start\r\nMethod start A\r\nyield\r\nMethod start B\r\nMethod end A\r\nMethod end B\r\nStart end\r\n*\/\r\n<\/pre>\n<p>\u30b3\u30eb\u30fc\u30c1\u30f3\u306f\u3042\u304f\u307e\u3067\u30e1\u30a4\u30f3\u30b9\u30ec\u30c3\u30c9\u3067\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u672c\u5f53\u306e\u610f\u5473\u3067\u9055\u3046\u30b9\u30ec\u30c3\u30c9\u3067\u52d5\u304b\u3059\u306b\u306fThread\u30af\u30e9\u30b9\u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u308b\u3088\u3046\u3060\u3051\u3069\u3001Thread\u3092\u4f7f\u3046\u51e6\u7406\u306b\u306fUnity\u306eAPI\u306f\u4f7f\u3048\u306a\u3044\u3089\u3057\u3044\u3002<\/p>\n<p>\u53c2\u8003\uff09<br \/>\n<a href=\"http:\/\/www.wisdomsoft.jp\/656.html\" title=\"Wisdomsoft | \u51e6\u7406\u306e\u5206\u5272\uff08\u30b3\u30eb\u30fc\u30c1\u30f3\uff09\" target=\"_blank\">Wisdomsoft | \u51e6\u7406\u306e\u5206\u5272\uff08\u30b3\u30eb\u30fc\u30c1\u30f3\uff09<\/a><br \/>\n<a href=\"http:\/\/d.hatena.ne.jp\/fujimisakari\/20140217\/1392585217\" title=\"\u5b89\u5b9a\u306e\u6f22\u306b\u306a\u308b\u305f\u3081\u306b | \u30b3\u30eb\u30fc\u30c1\u30f3\u306b\u3064\u3044\u3066\" target=\"_blank\">\u5b89\u5b9a\u306e\u6f22\u306b\u306a\u308b\u305f\u3081\u306b | \u30b3\u30eb\u30fc\u30c1\u30f3\u306b\u3064\u3044\u3066<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3042\u307e\u308a\u7406\u89e3\u305b\u305a\u306b\u30b3\u30eb\u30fc\u30c1\u30f3\u3092\u4f7f\u7528\u3057\u3066\u3044\u305f\u306e\u3067\u3001\u3082\u3046\u5c11\u3057\u3061\u3083\u3093\u3068\u7406\u89e3\u3057\u3088\u3046\u3068\u898b\u76f4\u3057\u3066\u307f\u305f\u3002 \u305d\u3082\u305d\u3082\u30b3\u30eb\u30fc\u30c1\u30f3\u3068\u306f\u3002\u3002\u3002 \u4ee5\u4e0bWikipedia\u3088\u308a\u3002 \u30b3\u30eb\u30fc\u30c1\u30f3\uff08\u82f1: co-routine\uff09\u3068\u306f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u69cb\u9020\u306e\u4e00\u7a2e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,2],"tags":[],"class_list":["post-202","post","type-post","status-publish","format-standard","hentry","category-c","category-unity"],"_links":{"self":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=202"}],"version-history":[{"count":26,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/202\/revisions"}],"predecessor-version":[{"id":487,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/202\/revisions\/487"}],"wp:attachment":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}