{"id":578,"date":"2016-09-19T09:50:29","date_gmt":"2016-09-19T01:50:29","guid":{"rendered":"http:\/\/39.100.100.179\/?p=578"},"modified":"2016-10-11T09:27:52","modified_gmt":"2016-10-11T01:27:52","slug":"action%e7%94%a8%e6%b3%95%e4%bb%8eupdate%e9%87%8c%e8%8e%b7%e5%8f%96%e6%95%b0%e6%8d%ae%e6%9b%b4%e6%96%b0","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=578","title":{"rendered":"Action\u7528\u6cd5\u4eceUpdate\u91cc\u83b7\u53d6\u6570\u636e\u66f4\u65b0"},"content":{"rendered":"<pre class=\"lang:c# decode:true  \">using UnityEngine;\r\nusing System.Collections;\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\npublic class Test : MonoBehaviour\r\n{\r\n    public List&lt;Action&lt;int, bool&gt;&gt; m_CallBackList;     \/\/ \u521d\u59cb\u5316\r\n\r\n    void Start()\r\n    {\r\n        m_CallBackList = new List&lt;Action&lt;int, bool&gt;&gt;();\r\n        \/\/ \u8fd9\u91cc\u662f\u83b7\u53d6\u6240\u9700\u8981\u7684\u503c\uff0c\u4e00\u822c\u5728\u5176\u5b83\u811a\u672c\u91cc\u53bb\u7528\u3002 \u53ea\u6709\u5728\u4f20\u503c\u65f6\u624d\u4f1a\u8c03\u7528\r\n        ChangeValue((int _int, bool _bool) =&gt;\r\n        {\r\n            print(_int + \" \" + _bool.ToString());\r\n        });\r\n    }\r\n\r\n    int i = 0;\r\n    \/\/ Update is called once per frame\r\n    void Update()\r\n    {\r\n\r\n        i++;\r\n        if (i % 50 == 0)\r\n        {\r\n            foreach (Action&lt;int, bool&gt; item in m_CallBackList)\r\n            {\r\n                item(i, true); \/\/ \u8fd9\u91cc\u662f\u4f20\u503c \u5f53\u4e00\u5b9a\u6761\u4ef6\u4e0b \u5c06\u503c\u4f20\u8fc7\u53bb\r\n            }\r\n        }\r\n        if (i % 80 == 0)\r\n        {\r\n            foreach (Action&lt;int, bool&gt; item in m_CallBackList)\r\n            {\r\n                item(i, false); \/\/ \u8fd9\u91cc\u662f\u4f20\u503c \u5f53\u4e00\u5b9a\u6761\u4ef6\u4e0b \u5c06\u503c\u4f20\u8fc7\u53bb\r\n            }\r\n        }\r\n    }\r\n\r\n    \/\/ \u8d4b\u503c\r\n    public void ChangeValue(Action&lt;int, bool&gt; callback)\r\n    {\r\n        if (m_CallBackList.Contains(callback) == false)\r\n        {\r\n            m_CallBackList.Add(callback);\r\n        }\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using UnityEngine; using System.Collecti &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=578\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23],"tags":[183,182],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/578"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=578"}],"version-history":[{"count":6,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/578\/revisions"}],"predecessor-version":[{"id":716,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/578\/revisions\/716"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=578"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}