{"id":213,"date":"2021-08-20T01:14:56","date_gmt":"2021-08-19T17:14:56","guid":{"rendered":"https:\/\/www.blinkedu.cn\/?p=213"},"modified":"2021-08-22T17:35:04","modified_gmt":"2021-08-22T09:35:04","slug":"213","status":"publish","type":"post","link":"https:\/\/www.blinkedu.cn\/index.php\/2021\/08\/20\/213\/","title":{"rendered":"Unity\u7ea2\u70b9\u7cfb\u7edf\uff08Lua\u8bed\u8a00\u5b9e\u73b0\uff09"},"content":{"rendered":"<h2>\u4ecb\u7ecd<\/h2>\n<p>\u7ea2\u70b9\u7cfb\u7edf\u662f\u76ee\u524d\u7edd\u5927\u90e8\u5206\u6e38\u620f\u90fd\u4f1a\u62e5\u6709\u7684\u529f\u80fd\uff0c\u4f5c\u7528\u662f\u5728\u5f53\u73a9\u5bb6\u8fbe\u6210\u67d0\u79cd\u72b6\u6001\u65f6\uff08\u4f8b\u5982\uff1a\u4efb\u52a1\u5b8c\u6210\uff0c\u6709\u65b0\u7684\u90ae\u4ef6\u7b49\uff09\uff0c\u4f1a\u5728\u76f8\u5173\u6309\u94ae\u4e0a\u663e\u793a\u4e00\u4e2a\u5c0f\u7ea2\u70b9\u6765\u63d0\u793a\u73a9\u5bb6\u8fdb\u884c\u76f8\u5173\u64cd\u4f5c\u3002<\/p>\n<p>\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/wp_editor_md_03e3f3ee3d4346ec39e6012ef903ae86.jpg\"><img decoding=\"async\" layer-src=\"https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/wp_editor_md_03e3f3ee3d4346ec39e6012ef903ae86.jpg\" src=\"https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/wp_editor_md_03e3f3ee3d4346ec39e6012ef903ae86.jpg\" alt=\"\u300aUnity\u7ea2\u70b9\u7cfb\u7edf\uff08Lua\u8bed\u8a00\u5b9e\u73b0\uff09\u300b\" \/><\/a><\/p>\n<p>\u7ea2\u70b9\u7cfb\u7edf\u662f\u4e00\u4e2a\u770b\u8d77\u6765\u5f88\u7b80\u5355\uff0c\u4f46\u662f\u5374\u5f88\u86cb\u75bc\u7684\u529f\u80fd\u3002\u9ebb\u70e6\u7684\u539f\u56e0\u5e76\u4e0d\u662f\u5b9e\u73b0\u8d77\u6765\u5f88\u590d\u6742\uff0c\u800c\u662f\u5b83\u662f\u4e00\u4e2a\u5c42\u5c42\u5957\u5a03\u7684\u7ed3\u6784\uff0c\u5e76\u4e14\u6d89\u53ca\u5230\u6e38\u620f\u4e2d\u7684\u7edd\u5927\u90e8\u5206\u6a21\u5757\uff0c\u5982\u679c\u7ea2\u70b9\u7cfb\u7edf\u8bbe\u8ba1\u7684\u4e0d\u5408\u7406\u4f1a\u5bfc\u81f4\u52a0\u7ea2\u70b9\u529f\u80fd\u65f6\u4f1a\u7279\u522b\u7684\u9ebb\u70e6\uff0c\u7ef4\u62a4\u4e5f\u7279\u522b\u56f0\u96be\uff0c\u4e5f\u5f88\u5bb9\u6613\u51faBug\u3002\uff08\u4e00\u822c\u9879\u76ee\u7ec4\u7684\u540c\u4e8b\u90fd\u7279\u522b\u8ba8\u538c\u52a0\u7ea2\u70b9\uff0c2333&#8230;\uff09<\/p>\n<h2>\u7ea2\u70b9\u7cfb\u7edf\u7ed3\u6784\u5206\u6790<\/h2>\n<p>\u7ea2\u70b9\u7cfb\u7edf\u5176\u5b9e\u662f\u4e00\u4e2a\u6807\u51c6\u7684\u6811\u5f62\u7ed3\u6784\uff0c\u5176\u7ea2\u70b9\u70b9\u4eae\u7684\u65b9\u5f0f\u662f\u4ece\u5176\u53f6\u5b50\u8282\u70b9\u5f00\u59cb\u5f80\u4e0a\u70b9\u4eae\uff0c\u76f4\u5230\u4e3b\u754c\u9762\u7684\u7ea2\u70b9\u88ab\u70b9\u4eae<\/p>\n<p>\u5982\u4e0b\u56fe\uff0c\u5f53K\u9700\u8981\u70b9\u4eae\u7ea2\u70b9\u65f6\uff0c\u4f1a\u4e00\u76f4\u5f80\u4e0a\u70b9\u4eae\uff0c\u6700\u540eA\u8282\u70b9\u88ab\u70b9\u4eae\uff08 K &#8211; H &#8211; D &#8211; A \uff09<\/p>\n<figure id=\"attachment_mmd_214\" class=\"wp-block-image \"><img width=\"835\" height=\"710\" src=\"https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/RedDotSystem.png\" class=\"attachment-full size-full\" alt=\"\u300aUnity\u7ea2\u70b9\u7cfb\u7edf\uff08Lua\u8bed\u8a00\u5b9e\u73b0\uff09\u300b\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/RedDotSystem.png 835w, https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/RedDotSystem-300x255.png 300w, https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/RedDotSystem-768x653.png 768w, https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/RedDotSystem-750x638.png 750w\" sizes=\"(max-width: 835px) 100vw, 835px\" \/><\/figure>\n<h2>\u7ea2\u70b9\u7cfb\u7edf\u8bbe\u8ba1<\/h2>\n<h3>\u7ea2\u70b9\u7c7b\u7ed3\u6784\uff08RedDotNode\uff09<\/h3>\n<p>\u6211\u4eec\u5728\u767b\u5f55\u6e38\u620f\u540e\u4f1a\u770b\u5230\u754c\u9762\u4e0a\u4f1a\u663e\u793a\u7ea2\u70b9\uff0c\u8fd9\u662f\u6211\u4eec\u5e76\u6ca1\u6709\u6253\u5f00\u8fc7\u5176\u4ed6\u754c\u9762\uff0c\u5e76\u4e14\u6211\u4eec\u5173\u95ed\u4e86\u754c\u9762\u540e\uff0c\u4e3b\u754c\u9762\u7684\u7ea2\u70b9\u4f9d\u65e7\u4f1a\u8fdb\u884c\u5237\u65b0\u3002\u7ea2\u70b9\u5237\u65b0\u4e0e\u754c\u9762\u6253\u5f00\u5e76\u6ca1\u6709\u76f4\u63a5\u7684\u5173\u8054\uff0c\u4e5f\u5c31\u662f\u8bf4\u7ea2\u70b9\u7684\u663e\u793a\u662f\u7531\u7ea2\u70b9\u6570\u636e\u8fdb\u884c\u9a71\u52a8\u7684\u3002\u4e3a\u4e86\u4fdd\u5b58\u7ea2\u70b9\u6570\u636e\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u7ed3\u6784\u8fdb\u884c\u7ea2\u70b9\u4fe1\u606f\u5b58\u50a8\uff0c\u6bcf\u4e00\u4e2a\u7ea2\u70b9\u90fd\u662f\u4e00\u4e2a\u5bf9\u8c61\u3002<\/p>\n<p>\u5728\u7ea2\u70b9\u4e2d\u6211\u4eec\u9700\u8981\u5b58\u50a8\u54ea\u4e9b\u6570\u636e\uff1f<\/p>\n<ul>\n<li>name\uff1a\u8282\u70b9\u70b9\u540d\u5b57\uff0c\u5728\u6211\u4eec\u67e5\u627e\u7ed3\u70b9\u65f6\u4f1a\u901a\u8fc7\u7ed3\u70b9\u540d\u79f0\u8fdb\u884c\u5224\u65ad\u662f\u5426\u662f\u6211\u4eec\u8981\u627e\u7684\u7ed3\u70b9<\/li>\n<li>parent\uff1a\u7236\u8282\u70b9\uff0c\u5728\u53f6\u5b50\u8282\u70b9\u72b6\u6001\u5237\u65b0\u65f6\uff0c\u4f1a\u901a\u8fc7\u7236\u7ed3\u70b9\u4e00\u76f4\u5f80\u4e0a\u5237\u65b0\uff08\u6574\u4e2a\u7ea2\u70b9\u6811\u7684\u6839\u8282\u70b9\u662f\u6ca1\u6709\u7236\u8282\u70b9\u7684\uff09<\/li>\n<li>childList\uff1a\u5b50\u8282\u70b9\u5217\u8868\uff0c\u8282\u70b9\u53ef\u80fd\u5b58\u5728\u591a\u4e2a\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u7528\u4e00\u4e2a\u5217\u8868\u5b58\u50a8\u8be5\u8282\u70b9\u7684\u6240\u6709\u5b50\u8282\u70b9\uff08\u53f6\u5b50\u8282\u70b9\u7684childList\u662f\u4e3a\u7a7a\u7684\uff09<\/li>\n<li>gameObject\uff1a\u7ea2\u70b9\u6e38\u620f\u7269\u4f53\uff0c\u754c\u9762\u4e2d\u663e\u793a\u7684\u7ea2\u70b9\uff0c\u5f53\u8282\u70b9\u6709\u88ab\u6ce8\u518c\u65f6\uff0c\u4f1a\u8bbe\u7f6e\u8be5gameObeject\uff0c\u5e76\u5237\u65b0\u663e\u793a\u3002\u6ce8\u9500\u65f6\u7f6e\u7a7a<\/li>\n<li>count\uff1a\u7ea2\u70b9\u7684\u6570\u91cf\uff0c\u8fd9\u91cc\u5b58\u50a8\u7684\u65f6\u6570\u91cf\u800c\u4e0d\u662f\u663e\u793a\u72b6\u6001\u662f\u56e0\u4e3a\u6709\u7684\u7ea2\u70b9\u4f1a\u8fdb\u884c\u6570\u91cf\u7684\u663e\u793a\uff0c\u5982\u679c\u5b50\u8282\u70b9\u6709\u4e24\u4e2a\u662f\u70b9\u4eae\u72b6\u6001\uff0c\u5219\u8be5\u8282\u70b9\u5728\u754c\u9762\u4f1a\u663e\u793a\u6570\u91cf2<\/li>\n<\/ul>\n<h3>\u6784\u5efa\u7ea2\u70b9\u6811<\/h3>\n<h4>\u6784\u5efa\u6811\u7684\u65b9\u5f0f\uff1a\u901a\u8fc7\u89e3\u6790key\u6765\u6784\u5efa\uff0ckey\u7684\u683c\u5f0f\uff1a\u8282\u70b9\u4e4b\u95f4\u7528.\u5206\u9694<\/h4>\n<p>\u4ee5\u56fe\u4e8c\u4e3a\u4f8b\uff1a<\/p>\n<ul>\n<li>A\u7684Key\uff1aa<\/li>\n<li>D\u7684Key\uff1aa.d<\/li>\n<li>H\u7684Key\uff1aa.d.h<\/li>\n<li>K\u7684Key\uff1aa.d.h.k<\/li>\n<\/ul>\n<p>\u8fd9\u6837\u53ea\u8981\u5c06key\u4ee5.\u8fdb\u884c\u5206\u5272\uff0c\u4f1a\u5f97\u5230\u4e00\u4e2a\u8282\u70b9\u540d\u79f0\u5217\u8868\uff0c\u901a\u8fc7\u8fd9\u4e2a\u5217\u8868\u5c31\u53ef\u80fd\u5f88\u65b9\u4fbf\u7684\u6784\u5efa\u5bf9\u5e94\u7684\u6811\u7ed3\u6784\uff0c\u5e76\u4e14\u80fd\u51c6\u786e\u7684\u67e5\u627e\u7684\u5bf9\u5e94\u7684\u8282\u70b9<\/p>\n<h4>\u4ec0\u4e48\u65f6\u5019\u6784\u5efa<\/h4>\n<p>\u770b\u8fc7\u5f88\u591a\u7684\u7ea2\u70b9\u7cfb\u7edf\u662f\u5728\u6e38\u620f\u521d\u59cb\u5316\u7684\u65f6\u5019\u5c31\u4f1a\u5c06\u6574\u4e2a\u7ea2\u70b9\u6811\u6784\u5efa\u51fa\u6765\uff0c\u8fd9\u79cd\u65b9\u5f0f\u5bf9\u4e8e\u56fa\u5b9a\u7ed3\u6784\uff08key\uff09\u7684\u7ea2\u70b9\u662f\u53ef\u4ee5\u63d0\u524d\u6784\u5efa\u51fa\u6765\u7684\uff08\u4f8b\u5982\uff1a\u4e3b\u754c\u9762\u90ae\u4ef6\u6309\u94ae\uff0c\u5b83\u7684\u4f4d\u7f6e\u662f\u56fa\u5b9a\u4e0d\u53d8\u7684\u4e14\u662f\u5e38\u9a7b\u6309\u94ae\uff09\uff0c\u4f46\u662f\u6709\u7684\u7ea2\u70b9\u662f\u6ca1\u529e\u6cd5\u786e\u5b9akey\u503c\u7684\uff0c\u4f8b\u5982\u6d3b\u52a8\u5217\u8868\uff0c\u8fd9\u4e2a\u5217\u8868\u662f\u4f1a\u52a8\u6001\u53d8\u5316\u7684\uff0c\u6d3b\u52a8\u7684\u4f4d\u7f6e\u4e5f\u53ef\u80fd\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u8fd9\u6837\u5c31\u4e0d\u592a\u597d\u63d0\u524d\u6784\u5efa\u7ea2\u70b9\u6811\u3002\u6240\u4ee5\u8fd9\u91cc\u6211\u4eec\u91c7\u7528\u7684\u65b9\u5f0f\u662f\u5728\u8c03\u7528\u83b7\u53d6\u8282\u70b9\u7684\u65b9\u6cd5\uff08_GetNode\uff09\u7684\u65f6\u5019\uff0c\u5982\u679c\u8be5\u8282\u70b9\u4e0d\u5b58\u5728\u5c31\u4f1a\u7acb\u5373\u5728\u7ea2\u70b9\u6811\u4e2d\u6784\u5efa\u5bf9\u5e94\u7684\u7ed3\u6784\u3002<\/p>\n<p>\u5047\u5982\u4e0a\u9762\u7684K\u8282\u70b9\u4e0b\u9762\u662f\u4e00\u4e2a\u6d3b\u52a8\u5217\u8868\uff0c\u4e14\u6d3b\u52a8\u662f\u52a8\u6001\u66f4\u65b0\u7684\uff0c\u90a3\u4e48\u6211\u4eec\u6ce8\u518c\u7ea2\u70b9\u65f6\u7684\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u65b9\u5f0f\u52a8\u6001\u62fc\u63a5key<\/p>\n<ul>\n<li>\u7b7e\u5230\u6d3b\u52a8id\u4e3a1001\uff0ckey\uff1aa.d.h.k.1001<\/li>\n<li>\u5145\u503c\u6d3b\u52a8id\u4e3a1002\uff0ckey\uff1aa.d.h.k.1002<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u6ce8\u518c\u7ea2\u70b9\u65f6\u7684\u6d41\u7a0b\u7b80\u56fe\uff0c\u56fe\u4e2d\u7eff\u8272\u7684\u6b65\u9aa4\u662f\u5728\u8bbe\u7f6e\u7ea2\u70b9\u72b6\u6001\uff08SetValid\uff09\u4e5f\u4f1a\u6267\u884c\u7684<\/p>\n<figure id=\"attachment_mmd_215\" class=\"wp-block-image \"><img width=\"625\" height=\"694\" src=\"https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/\u672a\u547d\u540d\u6587\u4ef6-1.png\" class=\"attachment-full size-full\" alt=\"\u300aUnity\u7ea2\u70b9\u7cfb\u7edf\uff08Lua\u8bed\u8a00\u5b9e\u73b0\uff09\u300b\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/\u672a\u547d\u540d\u6587\u4ef6-1.png 625w, https:\/\/www.blinkedu.cn\/wp-content\/uploads\/2021\/08\/\u672a\u547d\u540d\u6587\u4ef6-1-270x300.png 270w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/figure>\n<p><strong>\u8fd9\u79cd\u65b9\u5f0f\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a\u4e00\u5b9a\u8981\u786e\u4fddKey\u7684\u7ed3\u6784\u6b63\u786e\uff0c\u4e0d\u80fd\u51fa\u73b0\u9519\u8bef\uff08\u5982\uff1a\u7236\u8282\u70b9\u540d\u5b57\u9519\u8bef\uff09\uff0c\u8fd9\u6837\u4f1a\u4ece\u51fa\u9519\u7684\u8282\u70b9\u5f00\u59cb\u6784\u5efa\u4e00\u4e2a\u5b50\u6811\uff0c\u4f1a\u8131\u79bb\u6b63\u786e\u7ed3\u6784<\/strong><\/p>\n<h2>\u4ee3\u7801\u5b9e\u73b0<\/h2>\n<p>\u8fd9\u91cc\u4f7f\u7528\u7684Lua\u8bed\u8a00\u5b9e\u73b0\u7684\uff08\u56e0\u4e3a\u76ee\u524d\u6b63\u5728\u5f00\u53d1\u7684\u9879\u76ee\u5c31\u662f\u7528\u7684Lua\u8bed\u8a00\uff09<\/p>\n<h3>\u7ea2\u70b9\u8282\u70b9\u811a\u672c<\/h3>\n<pre><code class=\"language-Lua line-numbers\">local RedDotNode = class() -- class\u662f\u9879\u76ee\u4e2d\u5c01\u88c5\u7684\u4e00\u4e2a\u6a21\u62df\u9762\u5411\u5bf9\u8c61\u4e2d\u7684\u7c7b\u7684\u529f\u80fd\n\nfunction RedDotNode:__new(name, parent)\n    self.name = name        -- \u540d\u79f0\n    self.parent = parent    -- \u7236\u8282\u70b9\n    self.childList = nil    -- \u5b50\u8282\u70b9\u5217\u8868\n    self.gameObject = nil   -- \u7ea2\u70b9\u6e38\u620f\u7269\u4f53\n    self.txtComp = nil      -- \u663e\u793a\u6570\u91cf\u7684\u7ec4\u4ef6\n    self.count = 0          -- \u7ea2\u70b9\u6570\u91cf\nend\n\n-- \u6ce8\u518c\u7ea2\u70b9\u65f6\u8c03\u7528\nfunction RedDotNode:RegisterHandle(parentGo)\n    -- \u67e5\u627e\u7269\u4f53\u4e0b\u9762\u662f\u5426\u6709\u7ea2\u70b9\u7269\u4f53\n    local go = __FindChild(parentGo, &quot;RedDot&quot;)\n    -- \u5982\u679c\u6709\u76f4\u63a5\u8bbe\u7f6e\u4e3a\u8be5\u8282\u70b9\u7684\u7ea2\u70b9\u6e38\u620f\u7269\u4f53\n    -- \u5426\u5219\u5c31\u8fdb\u884c\u52a8\u6001\u52a0\u8f7d\u5e76\u5b9e\u4f8b\u5316\n    if go then\n        self.gameObject = go\n    else\n        -- \u8fd9\u91cc\u662f\u6839\u636ekey\u7684\u540e\u7f00\u52a0\u8f7d\u4e0d\u540c\u7684\u7ea2\u70b9\u9884\u5236\n        -- \u5e76\u8bbe\u7f6e\u5176\u4f4d\u7f6e\n        local prefabName = string.endWith(self.name, &quot;_NUM&quot;) and &quot;NumRedDot&quot; or &quot;RedDot&quot;\n        go = __UIResouseIns:LoadUIPrefab('UI\/Panel\/' .. prefabName, 0, parentGo.transform) -- \u8fd9\u4e2a\u662f\u6211\u4eec\u9879\u76ee\u5c01\u88c5\u7684\u52a0\u8f7d\u5e76\u5b9e\u4f8b\u5316\u7684\u63a5\u53e3\n        go.name = &quot;RedDot&quot;\n        local rtPoint = go:GetComponent(CSType.RectTransform)\n        if not rtPoint then\n            rtPoint = go:AddComponent(CSType.RectTransform)\n        end\n        if not rtPoint then\n            UnityEngine.GameObject.Destroy(go)\n            return\n        end\n        rtPoint.anchorMax = Vector2.New(1, 1)\n        rtPoint.anchorMin = Vector2.New(1, 1)\n        rtPoint.anchoredPosition = Vector2.New(-16, -16)\n        self.gameObject = go\n    end\n    -- \u67e5\u627e\u7ea2\u70b9\u4e0b\u7684\u663e\u793a\u6570\u91cf\u7684Text\u7ec4\u4ef6\n    self.txtComp =  __FindChild(self.gameObject, &quot;TxtCount&quot;, CSType.Text)\n    self:Refresh()\nend\n\n-- \u6ce8\u9500\u7ea2\u70b9\u65f6\u8fdb\u884c\u8c03\u7528\nfunction RedDotNode:UnRegisterHandle()\n    self.gameObject = nil\n    self.txtComp = nil\nend\n\n-- \u7ea2\u70b9\u662f\u5426\u70b9\u4eae\uff08\u5f53\u6570\u91cf&gt;0\u662f\u8be5\u7ea2\u70b9\u5c31\u4e3a\u70b9\u4eae\u72b6\u6001\uff09\nfunction RedDotNode:IsValid()\n    return self.count &gt; 0\nend\n\n-- \u6dfb\u52a0\u5b50\u8282\u70b9\nfunction RedDotNode:AddChild(name)\n    if not self.childList then\n        self.childList = {}\n    end\n    local node = RedDotNode.new(name, self)\n    table.append(self.childList, node)\n    return node\nend\n\n-- \u901a\u8fc7\u540d\u5b57\u83b7\u53d6\u5b50\u8282\u70b9\nfunction RedDotNode:GetChild(name)\n    for _, node in ipairs(self.childList or {}) do\n        if node.name == name then\n            return node\n        end\n    end\nend\n\n-- \u8bbe\u7f6e\u7ea2\u70b9\u663e\u793a\u72b6\u6001\nfunction RedDotNode:SetValid(isValid)\n    -- \u5982\u679c\u8bbe\u7f6e\u7684\u7ea2\u70b9\u663e\u793a\u72b6\u6001\u548c\u5f53\u524d\u72b6\u6001\u4e00\u76f4\uff0c\u5e76\u4e14\u5f53\u524d\u7ed3\u70b9\u662f\u53f6\u5b50\u7ed3\u70b9\u5c31\u4e0d\u8fdb\u884c\u5904\u7406\n    if self:IsValid() == isValid and (not self.childList or #self.childList &lt;= 0) then\n        return\n    end\n    if isValid then\n        -- \u72b6\u6001\u4e3a true, \u7ea2\u70b9\u6570\u91cf\u52a01\n        self.count = self.count + 1\n    else\n        -- \u72b6\u6001\u4e3a false\uff0c\u7ea2\u70b9\u6570\u91cf\u51cf1\n        self.count = self.count - 1\n    end\n    -- \u5237\u65b0\u7ea2\u70b9\u663e\u793a\n    self:Refresh()\n    -- \u5982\u679c\u5f53\u524d\u8282\u70b9\u5b58\u5728\u7236\u8282\u70b9\uff0c\u5219\u7ee7\u7eed\u8bbe\u7f6e\u7236\u8282\u70b9\u72b6\u6001\n    if self.parent then\n        self.parent:SetValid(isValid)\n    end\nend\n\n-- \u5237\u65b0\u7ea2\u70b9\u663e\u793a\nfunction RedDotNode:Refresh()\n    -- \u5982\u679c\u7ea2\u70b9\u6e38\u620f\u7269\u4f53\u4e3anull\uff0c\u4e0d\u505a\u5904\u7406\n    if tolua.isnull(self.gameObject) then\n        return\n    end\n    -- \u5982\u679c\u5b58\u5728\u663e\u793a\u7ea2\u70b9\u6570\u91cf\u7684Text\uff0c\u5c31\u8bbe\u7f6e\u6570\u91cf\u663e\u793a\n    if self.txtComp then\n        self.txtComp.text = self.count &gt;= 100 and &quot;99&quot; or self.count\n    end\n    -- \u8bbe\u7f6e\u7ea2\u70b9\u7269\u4f53\u7684\u663e\u793a\u72b6\u6001\n    __SetActive(self.gameObject, self:IsValid())\nend\n\nreturn RedDotNode\n<\/code><\/pre>\n<h3>\u7ea2\u70b9\u7ba1\u7406\u5668<\/h3>\n<pre><code class=\"language-lua line-numbers\">RedDotMgr = {}\nrequire(&quot;scripts\/common\/reddot\/RedDotDefine&quot;)\nlocal RedDotNode = require(&quot;scripts\/common\/reddot\/RedDotNode&quot;)\nRedDotMgr.key_map = {}\nRedDotMgr.root = nil\n\n-- \u6ce8\u518c\u7ea2\u70b9\n-- parentGo: \u9700\u8981\u663e\u793a\u7ea2\u70b9\u7684\u7269\u4f53\nfunction RedDotMgr:Register(key, parentGo)\n    local node = self:_GetNode(key)\n    if node then\n        node:RegisterHandle(parentGo)\n        --node:Refresh()\n    end\nend\n\n-- \u6ce8\u9500\u7ea2\u70b9\nfunction RedDotMgr:UnRegister(key)\n    if not self:IsNodeExist(key) then\n        return\n    end\n    local node = self:_GetNode(key)\n    if node then\n        node:UnRegisterHandle()\n    end\nend\n\n-- \u8bbe\u7f6e\u7ea2\u70b9\u663e\u793a\u72b6\u6001\uff08\u53ea\u80fd\u8bbe\u7f6e\u53f6\u5b50\u7ed3\u70b9\uff09\nfunction RedDotMgr:SetValid(key, isValid)\n    local node = self:_GetNode(key)\n    if node.childList and #node.childList &gt; 0 then\n        LogError(&quot;SetValid Error: \u53ea\u80fd\u8bbe\u7f6e\u53f6\u5b50\u8282\u70b9\u7684\u72b6\u6001\uff01key=&quot; .. key)\n        return\n    end\n    node:SetValid(isValid)\nend\n\n-- \u5224\u65adkey\u5bf9\u5e94\u7684\u7ea2\u70b9\u662f\u5426\u663e\u793a\nfunction RedDotMgr:IsValid(key)\n    if self:IsNodeExist(key) then\n        local node = self:_GetNode(key)\n        return node:IsValid()\n    end\n    return false\nend\n\n-- \u7ec4\u88c5Key\nfunction RedDotMgr:PackKey(prefixKey, ...)\n    local args = { ... }\n    local key = string.format(&quot;%s.%s&quot;, prefixKey, table.concat(args, '.'))\n    return key\nend\n\n-- \u83b7\u53d6\u8282\u70b9\nfunction RedDotMgr:_GetNode(key)\n    if not self.root then\n        self.root = RedDotNode.new(&quot;Root&quot;)\n    end\n    local keyList = self:_ParseKey(key)\n    local node = self.root\n    for _, name in ipairs(keyList) do\n        local tempNode = node:GetChild(name)\n        if not tempNode then\n            tempNode = node:AddChild(name)\n        end\n        node = tempNode\n    end\n    return node\nend\n\n-- \u8282\u70b9\u662f\u5426\u5b58\u5728\nfunction RedDotMgr:IsNodeExist(key)\n    return self.key_map[key] ~= nil\nend\n\nfunction RedDotMgr:_ParseKey(key)\n    if string.isNilOrEmpty(key) then\n        LogError(&quot;ParseKey Error: Key\u4e0d\u80fd\u4e3a\u7a7a!&quot;)\n        return\n    end\n    local keyList = self.key_map[key]\n    if not keyList then\n        keyList = string.split(key, '.')\n        self.key_map[key] = keyList\n    end\n    return keyList\nend\n<\/code><\/pre>\n<h3>\u7ea2\u70b9Key\u5b9a\u4e49<\/h3>\n<pre><code class=\"language-lua line-numbers\">--- \u5982\u679c\u9700\u8981\u663e\u793a\u6570\u5b57\u7ea2\u70b9\uff0c\u5219\u5728\u8282\u70b9key\u540e\u9762\u52a0\u4e0a_NUM\nRedDot = {\n    --- \u4efb\u52a1\n    MainTask = &quot;Task_NUM&quot;,          -- \u4e3b\u754c\u9762\u4efb\u52a1\u6309\u94ae\n    Task1 = &quot;Task_NUM.Task1&quot;,       -- \u4efb\u52a11\n    Task2 = &quot;Task_NUM.Task2&quot;,       -- \u4efb\u52a12\n    --- \u6d3b\u52a8\n    MainActivity = &quot;MainActivity&quot;,      -- \u4e3b\u754c\u9762\u6d3b\u52a8\u6309\u94ae  \n    SignIn = &quot;MainActivity.SignIn&quot;,     -- \u7b7e\u5230\u6d3b\u52a8\n}\n<\/code><\/pre>\n<p><strong>\u8fd9\u4e2a\u7ea2\u70b9\u7cfb\u7edf\u662f\u76ee\u524d\u5df2\u7ecf\u5728\u6211\u4eec\u9879\u76ee\u4e2d\u4f7f\u7528\u7684\u7ea2\u70b9\u7cfb\u7edf\uff0c\u4e2d\u95f4\u7528\u5230\u4e86\u5f88\u591a\u6846\u67b6\u4e2d\u5c01\u88c5\u597d\u7684\u529f\u80fd\uff0c\u6240\u4ee5\u76f4\u63a5\u642c\u8fd0\u8fd0\u884c\u4e0d\u4e86\u662f\u6b63\u5e38\u7684\u3002\u5176\u4e2d\u8fd8\u662f\u6709\u5f88\u591a\u53ef\u4ee5\u4f18\u5316\u7684\u5730\u65b9\uff0c\u8fd9\u91cc\u53ea\u662f\u63d0\u4f9b\u4e00\u4e2a\u601d\u8def\u3002\u5982\u679c\u6709\u65f6\u95f4\u7684\u8bdd\u4f1a\u5c3d\u91cf\u6574\u7406\u6210C#\u7248\u672c\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ecb\u7ecd \u7ea2\u70b9\u7cfb\u7edf\u662f\u76ee\u524d\u7edd\u5927\u90e8\u5206\u6e38\u620f\u90fd\u4f1a\u62e5\u6709\u7684\u529f\u80fd\uff0c\u4f5c\u7528\u662f\u5728\u5f53\u73a9\u5bb6\u8fbe\u6210\u67d0\u79cd\u72b6\u6001\u65f6\uff08\u4f8b\u5982\uff1a\u4efb\u52a1\u5b8c\u6210\uff0c\u6709\u65b0\u7684\u90ae\u4ef6\u7b49\uff09\uff0c\u4f1a\u5728\u76f8\u5173\u6309\u94ae\u4e0a\u663e\u793a\u4e00\u4e2a\u5c0f\u7ea2\u70b9\u6765\u63d0\u793a\u73a9\u5bb6\u8fdb\u884c\u76f8\u5173\u64cd\u4f5c\u3002 \u5982\u4e0b\u56fe\uff1a \u7ea2\u70b9\u7cfb\u7edf\u662f\u4e00\u4e2a\u770b\u8d77\u6765\u5f88\u7b80\u5355\uff0c\u4f46\u662f\u5374\u5f88\u86cb\u75bc\u7684\u529f\u80fd\u3002\u9ebb\u70e6\u7684\u539f\u56e0\u5e76\u4e0d\u662f\u5b9e\u73b0\u8d77\u6765\u5f88\u590d\u6742\uff0c\u800c\u662f\u5b83\u662f\u4e00\u4e2a\u5c42\u5c42\u5957\u5a03\u7684\u7ed3\u6784\uff0c\u5e76\u4e14\u6d89\u53ca\u5230\u6e38\u620f\u4e2d\u7684\u7edd\u5927\u90e8\u5206\u6a21\u5757\uff0c\u5982\u679c\u7ea2\u70b9\u7cfb\u7edf\u8bbe\u8ba1\u7684\u4e0d\u5408\u7406\u4f1a\u2026\u2026<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,1],"tags":[],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category-unity","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/posts\/213"}],"collection":[{"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/comments?post=213"}],"version-history":[{"count":0,"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}