{"id":1973,"date":"2024-06-15T13:06:49","date_gmt":"2024-06-15T13:06:49","guid":{"rendered":"https:\/\/histy.jp\/?p=1973"},"modified":"2024-08-08T01:52:26","modified_gmt":"2024-08-08T01:52:26","slug":"post-1973","status":"publish","type":"post","link":"https:\/\/histy.jp\/?p=1973","title":{"rendered":"Unity\u3067\u30b8\u30a7\u30cd\u30ea\u30af\u30b9\u3092\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u76ee\u7684<\/h2>\n\n\n\n<p>\u6226\u95d8\u6642\u306b\u547c\u3073\u51fa\u3059\u30c0\u30e1\u30fc\u30b8\u51e6\u7406\u306b\u95a2\u308f\u308b\u95a2\u6570\u304cEnemy\u30af\u30e9\u30b9\u3068Player\u30af\u30e9\u30b9\u3067\u5225\u308c\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<p>\u305d\u308c\u3092\u3001\u30c0\u30e1\u30fc\u30b8\u51e6\u7406\u306f\u5171\u901a\u306e\u51e6\u7406\u3092\u66f8\u3044\u3066\u3044\u308b\u306e\u3067\u30b8\u30a7\u30cd\u30ea\u30af\u30b9\u3092\u4f7f\u3063\u30661\u3064\u306b\u307e\u3068\u3081\u305f\u3044\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u73fe\u72b6\u8a73\u7d30<\/h3>\n\n\n\n<p>EnemyController\u30af\u30e9\u30b9\u3068PlayerController\u30af\u30e9\u30b9\u306b\u305d\u308c\u305e\u308c\u30c0\u30e1\u30fc\u30b8\u51e6\u7406\u3092\u66f8\u3044\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6539\u5584\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u6226\u95d8\u3067\u767a\u751f\u3059\u308b\u51e6\u7406\u3092\u62c5\u5f53\u3059\u308bBattleSystem\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u3001\u305d\u3053\u306b\u307e\u3068\u3081\u308b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30b8\u30a7\u30cd\u30ea\u30af\u30b9\u306b\u3064\u3044\u3066<\/h3>\n\n\n\n<p>\u203bC#\u3060\u3068\u30b8\u30a7\u30cd\u30ea\u30af\u30b9\u3068\u306f\u8a00\u308f\u305a\u306b\u3001\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u3068\u547c\u3076\u3089\u3057\u3044\u3002<\/p>\n\n\n\n<p>\u53c2\u8003\u8cc7\u6599<\/p>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/ja-jp\/dotnet\/csharp\/programming-guide\/generics\/generic-methods\">\u30b8\u30a7\u30cd\u30ea\u30c3\u30af \u30e1\u30bd\u30c3\u30c9 (C# \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0 \u30ac\u30a4\u30c9)<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9f\u88c5<\/h3>\n\n\n\n<p>\uff11\uff0e3\u3064\u306e\u30af\u30e9\u30b9\u30681\u3064\u306e\u30a4\u30f3\u30bf\u30d5\u30a7\u30a4\u30b9\u3092\u5b9f\u88c5\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u30fb\u6226\u95d8\u51e6\u7406\u306b\u95a2\u9023\u3059\u308b\u51e6\u7406\u3092\u62c5\u3046BattleSystem\u30af\u30e9\u30b9<\/p>\n\n\n\n<p>\u30fb\u6575\u30aa\u30d6\u30b8\u30a7\u30af\u30c8EnemyController\u30af\u30e9\u30b9<\/p>\n\n\n\n<p>\u30fb\u30d7\u30ec\u30a4\u30e4\u30fc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8PlayerController\u30af\u30e9\u30b9<\/p>\n\n\n\n<p>\u30fbBattleSystem\u3067\u5f15\u6570\u306b\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u578b\u3092\u6307\u5b9a\u3057\u305f\u969b\u306b\u5f15\u6570\u306e\u30e1\u30f3\u30d0\u30fc\u3092\u4f7f\u3046\u305f\u3081\u306b\u5fc5\u8981\u306aBattleInterfece<\/p>\n\n\n\n<p>\uff12\uff0e\u5404\u30af\u30e9\u30b9\u3068\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u306e\u5185\u5bb9<\/p>\n\n\n\n<p>PlayerController\u30af\u30e9\u30b9\u3068\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\n\npublic interface BattleInterface\n{\n    int HP { get; set;}\n}\npublic class PlayerController : MonoBehaviour, BattleInterface\n{\n    int hp;\n    public int HP { get =&gt; hp; set =&gt; hp = value; }\n}<\/code><\/pre>\n\n\n\n<p>\uff08\u3053\u3053\u3067\u306f\u7c21\u6613\u7684\u306bHP\u3092PlayerController\u30af\u30e9\u30b9\u306e\u30e1\u30f3\u30d0\u30fc\u306b\u3057\u3066\u3044\u308b\u304c\u672c\u5f53\u306fMVC\u30e2\u30c7\u30eb\u306b\u5f93\u3063\u3066\u3001Model\u306b\u5e30\u5c5e\u3055\u305b\u308b\u3002\uff09<\/p>\n\n\n\n<p>EnemyController<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class EnemyController : MonoBehaviour, BattleInterface\n{\n    int hp;\n    public int HP { get =&gt; hp; set =&gt; hp = value; }\n}<\/code><\/pre>\n\n\n\n<p>BattleSystem<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic static class BattleSystem\n{\n    public static void Damage&lt;Attacker, Defencer>(Attacker attacker, Defencer defencer)\n    where Attacker : BattleInterface\n    where Defencer : BattleInterface\n    {\n        int deffencerHP = defencer.HP;\n        deffencerHP -= 10;\u3000\/\/ \u30c0\u30e1\u30fc\u30b8\n        if (deffencerHP &lt; 0) deffencerHP = 0;\n\n        defencer.HP = deffencerHP;\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u305d\u306e\u4ed6\u306b\u6c17\u306b\u306a\u3063\u305f\u8a18\u4e8b<\/p>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/ja-jp\/dotnet\/csharp\/language-reference\/keywords\/interface\">interface (C# \u30ea\u30d5\u30a1\u30ec\u30f3\u30b9)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u7684 \u6226\u95d8\u6642\u306b\u547c\u3073\u51fa\u3059\u30c0\u30e1\u30fc\u30b8\u51e6\u7406\u306b\u95a2\u308f\u308b\u95a2\u6570\u304cEnemy\u30af\u30e9\u30b9\u3068Player\u30af\u30e9\u30b9\u3067\u5225\u308c\u3066\u3044\u308b\u3002 \u305d\u308c\u3092\u3001\u30c0\u30e1\u30fc\u30b8\u51e6\u7406\u306f\u5171\u901a\u306e\u51e6\u7406\u3092\u66f8\u3044\u3066\u3044\u308b\u306e\u3067\u30b8\u30a7\u30cd\u30ea\u30af\u30b9\u3092\u4f7f\u3063\u30661\u3064\u306b\u307e\u3068\u3081\u305f\u3044\u3002 \u73fe\u72b6\u8a73\u7d30 EnemyContro [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts\/1973"}],"collection":[{"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1973"}],"version-history":[{"count":6,"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts\/1973\/revisions"}],"predecessor-version":[{"id":2301,"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts\/1973\/revisions\/2301"}],"wp:attachment":[{"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}