{"id":1889,"date":"2020-05-14T11:59:11","date_gmt":"2020-05-14T03:59:11","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=1889"},"modified":"2020-05-18T17:50:55","modified_gmt":"2020-05-18T09:50:55","slug":"unity-c%e7%bb%a7%e6%89%bf","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=1889","title":{"rendered":"[Unity\/C#]MonoBehaviour\u591a\u7ee7\u627f\u4e0b\u7684\u91cd\u8f7d\u51fd\u6570\u8c03\u7528\u4fdd\u969c"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>public class MonoBehaviourBase : MonoBehaviour\n{\n    private void OnDestroy()\n    {\n        \/\/ do base destroy...\n    }\n}\n\npublic class BattleField: MonoBehaviourBase \n{\n    public void OnDestroy()\n    {\n        \/\/ do battle destroy\n    }\n}\n\n\u8fd9\u79cd\u5199\u6cd5\uff0c\u4e0d\u4f1a\u6709\u4efb\u4f55\u8b66\u544a\uff01\uff01\uff01\n\u4f46\u662f\u5728\u6267\u884c\u7ed3\u679c\u4e0a\uff0c\u57fa\u4e8eUnity-Mono\u4f53\u7cfb\n\u7cfb\u7edf\u5c06\u53ea\u4f1a\u6267\u884cBattleField\u7684OnDestroy\uff0c\n\u8fd9\u6837MonoBehaviourBase\u7684OnDestroy\u4e0d\u88ab\u8c03\u7528\uff01\n\u4f1a\u53d1\u751f\u4e0d\u53ef\u9884\u671f\u7684\u884c\u4e3a\u3002\n\n\u6539\u5199\u65b9\u6cd5\u4e3a\uff1a\n\npublic class MonoBehaviourBase : MonoBehaviour\n{\n    private void OnDestroy()\n    {\n        \/\/ do base destroy...\n        this.OnDestroyBase();\n    }\n    public virtual void OnDestroyCallback() {}\n}\n\npublic class BattleField: MonoBehaviourBase \n{\n    public override void OnDestroyCallback()\n    {\n        \/\/ do battle destroy\n    }\n}\n\n\u82e5\u5b50\u7c7b\u91cd\u5199\u4e86 OnDestroy, \u7f16\u8bd1\u5668\u5c06\u4f1a\u8b66\u544a\uff01\n\u9664\u975e\u6709\u4eba\u6076\u610f\u91cd\u5199\uff1apublic new void OnDestory();\n\u8fbe\u5230\u4e86\u4ee3\u7801\u5b89\u5168\u7684\u76ee\u7684<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1889"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1889"}],"version-history":[{"count":4,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1889\/revisions"}],"predecessor-version":[{"id":1893,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1889\/revisions\/1893"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}