{"id":870,"date":"2021-11-06T11:14:00","date_gmt":"2021-11-06T03:14:00","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=870"},"modified":"2021-10-25T15:25:37","modified_gmt":"2021-10-25T07:25:37","slug":"creator%e8%b7%a8%e5%9c%ba%e6%99%af%e6%95%b0%e6%8d%ae%e4%bc%a0%e9%80%92%e7%9a%84%e4%b8%89%e7%a7%8d%e6%96%b9%e5%bc%8f%e3%80%82","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=870","title":{"rendered":"Creator\u8de8\u573a\u666f\u6570\u636e\u4f20\u9012\u7684\u4e09\u79cd\u65b9\u5f0f\u3002"},"content":{"rendered":"\n<p>\u6700\u8fd1\u9047\u5230\u8de8\u573a\u666f\u7684\u6570\u636e\u4f20\u9012\u7684\u9700\u6c42\uff0c\u4e0a\u5348\u6574\u7406\u4e86\u4e00\u4e0b\u51e0\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u81ea\u5df1\u64b0\u5199\u4e00\u7bc7\u6587\u7ae0\u6765\u603b\u7ed3\uff0c\u907f\u514d\u9057\u5fd8\u4e5f\u6709\u8ff9\u53ef\u5faa\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u628a\u6e90\u7801\u653e\u51fa\u6765\uff0c\u5730\u5740\u662f\uff1a<a href=\"https:\/\/github.com\/894658027\/HTML5-Games\/tree\/master\/cocosCreator\/scene-data-transfer\">https:\/\/github.com\/894658027\/HTML5-Games\/tree\/master\/cocosCreator\/scene-data-transfer<\/a><\/p>\n\n\n\n<p>\u5148\u770b\u4e0b\u9879\u76ee\u7684\u914d\u7f6e\u7ed3\u6784\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-1 is-cropped\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" width=\"1024\" height=\"699\" src=\"http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2021\/10\/1-1024x699.png\" alt=\"\" data-id=\"886\" data-full-url=\"http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2021\/10\/1.png\" data-link=\"http:\/\/blog.xrhoujie.com\/?attachment_id=886\" class=\"wp-image-886\" srcset=\"http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2021\/10\/1-1024x699.png 1024w, http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2021\/10\/1-300x205.png 300w, http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2021\/10\/1-768x524.png 768w, http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2021\/10\/1.png 1129w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p>\u8fd9\u91cc\u67093\u4e2a\u573a\u666f\u6587\u4ef6\uff0c\u6bcf\u4e2a\u573a\u666f\u6587\u4ef6\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684ts\u811a\u672c\u6587\u4ef6\uff0c\u811a\u672c\u6587\u4ef6\u91cc\u9762\u6709\u4ee3\u7801\uff0cGlobal\u6587\u4ef6\u662f\u7528\u6765\u5b58\u653e\u63a5\u53e3\u6587\u4ef6\u7684&#8221;\u5168\u5c40\u53d8\u91cf&#8221;\uff0csession\u6587\u4ef6\u4e5f\u662f\u63a5\u53e3\u6587\u4ef6\u662f\u7528\u6765\u5f15\u5165\u811a\u672c\u7684\u4ee3\u7801\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u8bf4\u4e00\u4e0b\u7b2c\u4e00\u79cd\uff0c\u901a\u8fc7class\u7684\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<p>session.ts\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Session {\n   id = \"hello\"\n  name = \"\u4f60\u597d\"\n  label = \"helloword\"\n}\nexport default new Session<\/code><\/pre>\n\n\n\n<p>hello1.ts\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import session from \".\/session\"\n\u5f15\u5165\u540e\u53ef\u4ee5\u5728\u94a9\u5b50\u51fd\u6570\u91cc\u9762\u8c03\u7528Session\u5185\u90e8\u7684\u5c5e\u6027\uff0c<\/code><\/pre>\n\n\n\n<p>\u7b2c\u4e8c\u79cd\u65b9\u6cd5&#8212;\u8bbe\u7f6e\u5e38\u9a7b\u8282\u70b9->\u8981\u4fdd\u8bc1\u5e38\u9a7b\u8282\u70b9\u662f\u6839\u8282\u70b9\uff0c\u5426\u5219\u53d6\u7684\u4e3anull,\u914d\u5408\u5207\u6362\u573a\u666f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \/\/\u5728\u8282\u70b9\u4e0a\u7ed1\u5b9a\u63a5\u53e3\u683c\u5f0f\n        lableNode&#91;'port']={\n            sceneId : \"hello1\",\n            name : lableNode.name,\n            label : this.label.string,\n            \n        }\n        \/\/\u7b2c\u4e8c\u79cd---\u8bbe\u7f6e\u5e38\u9a7b\u8282\u70b9->\u8981\u4fdd\u8bc1\u5e38\u9a7b\u8282\u70b9\u662f\u6839\u8282\u70b9\uff0c\u5426\u5219\u53d6\u7684\u4e3anull,\u914d\u5408\u5207\u6362\u573a\u666f\n        cc.game.addPersistRootNode(lableNode);\n\n        \/\/cc.game.removePersistRootNode(myNode); \u53d6\u6d88\u5e38\u9a7b\u8282\u70b9\n        this.scheduleOnce(()=>{\n            \/\/\u5207\u6362\u5230hello2\u573a\u666f\n            cc.director.loadScene(\"hello2\");\n        },1)\n<\/code><\/pre>\n\n\n\n<p>\u5207\u6362hello2\u573a\u666f\u540e\u5c31\u80fd\u591f\u83b7\u53d6\u5230\u8fd9\u4e2a\u5e38\u9a7b\u8282\u70b9\u4e86\uff0c\u4ee5\u53ca\u4e0a\u9762\u7684\u6570\u636e\u5185\u5bb9<\/p>\n\n\n\n<p>\u53d6\u503c\u7684\u65f6\u5019\u76f4\u63a5\u7528cc.find(\u2019xxx\u2018)\u8fdb\u884c\u83b7\u53d6\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e09\u79cd\u65b9\u6cd5&#8212;\u8bbe\u7f6e\u5168\u5c40\u53d8\u91cf<\/p>\n\n\n\n<p>Global.ts\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>window&#91;'Global'] = {\n    id: null,\n    name: null,\n    age:null,\n  };<\/code><\/pre>\n\n\n\n<p>hello3.ts\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nconst { ccclass, property } = cc._decorator;\n\n@ccclass\nexport default class NewClass extends cc.Component {\n\n    \/\/\u7b2c\u4e09\u79cd\u5f15\u5165\u5168\u5c40\u53d8\u91cf\uff0c\n    \/\/  \u8bbf\u95ee\u5168\u5c40\u53d8\u91cf\u65f6\uff0c\u5982\u679c\u53d8\u91cf\u672a\u5b9a\u4e49\u5c06\u4f1a\u629b\u51fa\u5f02\u5e38\u3002\n    \/\/ \u6dfb\u52a0\u5168\u5c40\u53d8\u91cf\u65f6\uff0c\u8bf7\u5c0f\u5fc3\u4e0d\u8981\u548c\u7cfb\u7edf\u5df2\u6709\u7684\u5168\u5c40\u53d8\u91cf\u91cd\u540d\u3002\n    \/\/ \u4f60\u9700\u8981\u5c0f\u5fc3\u786e\u4fdd\u5168\u5c40\u53d8\u91cf\u4f7f\u7528\u4e4b\u524d\u90fd\u5df2\u521d\u59cb\u5316\u548c\u8d4b\u503c\u3002\n    Global: any;\n    start() {\n        var text = 'Back';\n        this.Global = window&#91;'Global']\n        this.Global.label = text;\n        console.log(this.Global)\n\n    }\n\n    \/\/ update (dt) {}\n}\n<\/code><\/pre>\n\n\n\n<p>\u55ef\uff0c\u57fa\u672c\u4e0a\u5c31\u662f\u8fd9\u4e2a\u6837\u5b50 \uff0c3\u79cd\u8de8\u573a\u666f\u6570\u636e\u7684\u4f20\u9012\u65b9\u5f0f\uff0c\u4e4b\u524d\u7ffb\u6587\u6863\u597d\u50cf\u8fd8\u6709\u4e24\u79cd\u65b9\u6cd5\uff0c\u4e00\u4e2a\u662f\u7c7b\u4f3c\u7684\u4f7f\u7528require\u65b9\u6cd5\uff0c\u8fd8\u6709\u4e00\u4e2a\u662fcc.props\u8fd9\u4e2a\u6ca1\u7528\u8fc7\u8fd9\u91cc\u5c31\u4e0d\u6f14\u793a\u4e86\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u6709\u66f4\u597d\u7684\u65b9\u5f0f\u53ef\u4ee5\u8ddf\u6211\u7559\u8a00\uff0c\u671f\u5f85\u4e92\u76f8\u5b66\u4e60\u4e0e\u8fdb\u6b65\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u9047\u5230\u8de8\u573a\u666f\u7684\u6570\u636e\u4f20\u9012\u7684\u9700\u6c42\uff0c\u4e0a\u5348\u6574\u7406\u4e86\u4e00\u4e0b\u51e0\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u81ea\u5df1\u64b0\u5199\u4e00\u7bc7\u6587\u7ae0\u6765\u603b\u7ed3\uff0c\u907f\u514d\u9057\u5fd8\u4e5f\u6709\u8ff9\u53ef\u5faa\u3002 \u9996 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":307,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[30],"tags":[32],"_links":{"self":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/870"}],"collection":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=870"}],"version-history":[{"count":8,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/870\/revisions"}],"predecessor-version":[{"id":887,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/870\/revisions\/887"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/media\/307"}],"wp:attachment":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=870"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}