{"id":2209,"date":"2020-08-21T23:49:36","date_gmt":"2020-08-21T15:49:36","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=2209"},"modified":"2020-08-21T23:50:04","modified_gmt":"2020-08-21T15:50:04","slug":"cevent-add-remove%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=2209","title":{"rendered":"[C#]event\/add\/remove\u8bed\u6cd5\u7cd6\u4f7f\u7528\u65b9\u6cd5"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>public class EventTest : MonoBehaviour\n{\n    public delegate void LogCallback();\n    void Start()\n    {\n        LogCallback callback = ()=>\n        {\n            Debug.Log(\"Call\");\n        };\n\n        MyLog += callback;\n        MyLog -= callback;\n        MyLog -= callback;\n        MyLog += callback;\n\n        if (LogStack != null)\n        {\n            LogStack.Invoke();\n        }\n    }\n\n    private LogCallback LogStack;\n    public event LogCallback MyLog\n    {\n        add\n        {\n            LogStack += value;\n        }\n\n        remove\n        {\n            LogStack -= value;\n        }\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","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\/2209"}],"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=2209"}],"version-history":[{"count":2,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2209\/revisions"}],"predecessor-version":[{"id":2211,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2209\/revisions\/2211"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}