cocos-enhance-kit/assets/js/e0acac31.924c1780.js
2024-12-20 14:47:15 +08:00

1 line
18 KiB
JavaScript

"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[6710],{3905:function(e,t,n){n.d(t,{Zo:function(){return o},kt:function(){return d}});var a=n(67294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function c(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t){if(null==e)return{};var n,a,r=function(e,t){if(null==e)return{};var n,a,r={},l=Object.keys(e);for(a=0;a<l.length;a++)n=l[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a<l.length;a++)n=l[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var i=a.createContext({}),u=function(e){var t=a.useContext(i),n=t;return e&&(n="function"==typeof e?e(t):c(c({},t),e)),n},o=function(e){var t=u(e.components);return a.createElement(i.Provider,{value:t},e.children)},p={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},k=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,i=e.parentName,o=s(e,["components","mdxType","originalType","parentName"]),k=u(n),d=r,m=k["".concat(i,".").concat(d)]||k[d]||p[d]||l;return n?a.createElement(m,c(c({ref:t},o),{},{components:n})):a.createElement(m,c({ref:t},o))}));function d(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,c=new Array(l);c[0]=k;var s={};for(var i in t)hasOwnProperty.call(t,i)&&(s[i]=t[i]);s.originalType=e,s.mdxType="string"==typeof e?e:r,c[1]=s;for(var u=2;u<l;u++)c[u]=n[u];return a.createElement.apply(null,c)}return a.createElement.apply(null,n)}k.displayName="MDXCreateElement"},98263:function(e,t,n){n.r(t),n.d(t,{assets:function(){return o},contentTitle:function(){return i},default:function(){return d},frontMatter:function(){return s},metadata:function(){return u},toc:function(){return p}});var a=n(87462),r=n(63366),l=(n(67294),n(3905)),c=["components"],s={sidebar_position:4,description:"\u8be6\u7ec6\u4e86\u89e3\u5982\u4f55\u901a\u8fc7\u70d8\u7119\u63d0\u5347\u8fd0\u884c\u65f6\u6587\u672c\u6e32\u67d3\u6027\u80fd\u3002"},i="\u6587\u672c\u6e32\u67d3\u70d8\u7119",u={unversionedId:"user-guide/text-render/text-baking",id:"version-3.0.0/user-guide/text-render/text-baking",title:"\u6587\u672c\u6e32\u67d3\u70d8\u7119",description:"\u8be6\u7ec6\u4e86\u89e3\u5982\u4f55\u901a\u8fc7\u70d8\u7119\u63d0\u5347\u8fd0\u884c\u65f6\u6587\u672c\u6e32\u67d3\u6027\u80fd\u3002",source:"@site/versioned_docs/version-3.0.0/user-guide/text-render/text-baking.md",sourceDirName:"user-guide/text-render",slug:"/user-guide/text-render/text-baking",permalink:"/cocos-enhance-kit/docs/user-guide/text-render/text-baking",draft:!1,tags:[],version:"3.0.0",sidebarPosition:4,frontMatter:{sidebar_position:4,description:"\u8be6\u7ec6\u4e86\u89e3\u5982\u4f55\u901a\u8fc7\u70d8\u7119\u63d0\u5347\u8fd0\u884c\u65f6\u6587\u672c\u6e32\u67d3\u6027\u80fd\u3002"},sidebar:"tutorialSidebar",previous:{title:"RichText \u81ea\u5b9a\u4e49\u6750\u8d28",permalink:"/cocos-enhance-kit/docs/user-guide/text-render/text-richtext"},next:{title:"\u52a8\u6001\u5408\u56fe",permalink:"/cocos-enhance-kit/docs/user-guide/dynamic-batcher/dynamic-batcher-intro"}},o={},p=[{value:"\u9884\u52a0\u8f7d Label Canvas",id:"\u9884\u52a0\u8f7d-label-canvas",level:2},{value:"\u70d8\u7119\u6587\u672c\u6d4b\u91cf\u503c",id:"\u70d8\u7119\u6587\u672c\u6d4b\u91cf\u503c",level:2},{value:"\u9884\u52a0\u8f7d <code>Char</code> \u56fe\u96c6",id:"\u9884\u52a0\u8f7d-char-\u56fe\u96c6",level:2},{value:"\u5b9e\u9645\u5e94\u7528",id:"\u5b9e\u9645\u5e94\u7528",level:2}],k={toc:p};function d(e){var t=e.components,s=(0,r.Z)(e,c);return(0,l.kt)("wrapper",(0,a.Z)({},k,s,{components:t,mdxType:"MDXLayout"}),(0,l.kt)("h1",{id:"\u6587\u672c\u6e32\u67d3\u70d8\u7119"},"\u6587\u672c\u6e32\u67d3\u70d8\u7119"),(0,l.kt)("p",null,"\u793e\u533a\u7248\u4e3a\u5f15\u64ce\u589e\u52a0\u4e86\u6587\u672c\u6e32\u67d3\u70d8\u7119\u7684\u80fd\u529b\u3002"),(0,l.kt)("p",null,"\u4ee5\u67d0\u4e2a\u9879\u76ee\u7684\u754c\u9762\u6253\u5f00\u64cd\u4f5c\u4e3a\u4f8b\uff0c\u901a\u8fc7\u5206\u6790 CPU Profile \u53ef\u4ee5\u770b\u5230\uff0c\u5f53\u754c\u9762\u8282\u70b9\u6fc0\u6d3b\u65f6\uff0c\u7edd\u5927\u90e8\u5206\u7684\u8017\u65f6\u90fd\u6765\u81ea\u4e8e\u6587\u672c\u6e32\u67d3\u51fd\u6570\uff08_applyFontTexture\uff09\u3002"),(0,l.kt)("p",null,(0,l.kt)("img",{alt:"before baking",src:n(73658).Z,width:"1544",height:"1042"})),(0,l.kt)("p",null,"\u4f46\u8fd9\u4e2a\u754c\u9762\u7684\u6587\u672c\u91cf\u5e76\u4e0d\u591a\uff0c\u5728\u4f4e\u7aef\u673a\u4e0a\u7684\u8017\u65f6\u5374\u6709 1.06s\u3002"),(0,l.kt)("p",null,"\u901a\u8fc7\u6587\u672c\u6e32\u67d3\u70d8\u7119\u4f18\u5316\u540e\uff0c\u8017\u65f6\u964d\u81f3 60ms\uff01"),(0,l.kt)("p",null,(0,l.kt)("img",{alt:"after baking",src:n(77333).Z,width:"812",height:"626"})),(0,l.kt)("p",null,"\u6587\u672c\u6e32\u67d3\u70d8\u7119\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\uff1a"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("strong",{parentName:"li"},"\u9884\u52a0\u8f7d Label Canvas")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("strong",{parentName:"li"},"\u70d8\u7119\u6587\u672c\u6d4b\u91cf\u503c")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("strong",{parentName:"li"},"\u9884\u52a0\u8f7d ",(0,l.kt)("inlineCode",{parentName:"strong"},"Char")," \u56fe\u96c6"))),(0,l.kt)("p",null,"\u6211\u4eec\u5c06\u9010\u4e2a\u8bf4\u660e\u3002"),(0,l.kt)("h2",{id:"\u9884\u52a0\u8f7d-label-canvas"},"\u9884\u52a0\u8f7d Label Canvas"),(0,l.kt)("p",null,"\u5f15\u64ce\u901a\u8fc7\u79bb\u5c4f Canvas \u6e32\u67d3\u6587\u672c\uff0c\u5185\u90e8\u7ef4\u62a4\u7740\u4e00\u4e2a Canvas \u6c60\u4ee5\u4f5c\u590d\u7528\u3002"),(0,l.kt)("p",null,"\u6bcf\u4e2a\u975e Char \u6a21\u5f0f\u7684 Label \u90fd\u4f1a\u5360\u7528\u4e00\u4e2a Canvas \u5bf9\u8c61\uff0c\u76f4\u5230 Label \u9500\u6bc1\u624d\u4f1a\u5c06 Canvas \u5bf9\u8c61\u653e\u56de\u6c60\u4e2d\u3002"),(0,l.kt)("p",null,"\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cCanvas \u6c60\u4e0d\u9884\u5148\u521b\u5efa\u5bf9\u8c61\uff0c\u800c\u662f\u5728\u4f7f\u7528\u65f6\u8fdb\u884c\u521b\u5efa\uff0c\u5728\u90e8\u5206\u4f4e\u7aef\u8bbe\u5907\u4e0a\uff0c\u8fd9\u4f1a\u589e\u52a0\u6587\u672c\u6e32\u67d3\u65f6\u7684\u5361\u987f\u3002"),(0,l.kt)("p",null,"\u5e76\u4e14\u8be5 Canvas \u6c60\u9ed8\u8ba4\u6700\u5927\u7f13\u5b58\u6570\u91cf\u4e3a 32\uff0c\u8d85\u8fc7\u8be5\u6570\u91cf\u7684\u5bf9\u8c61\u4e0d\u4f1a\u653e\u5165\u6c60\u4e2d\u800c\u662f\u76f4\u63a5\u9500\u6bc1\uff0c\u8fd9\u4e5f\u5bfc\u81f4\u5927\u91cf\u4f7f\u7528 Label \u7684\u9879\u76ee\u53ef\u80fd\u4f1a\u56e0\u4e3a\u6301\u7eed\u521b\u5efa Canvas \u800c\u9020\u6210\u5361\u987f\u3002"),(0,l.kt)("p",null,"\u73b0\u5728\uff0c\u793e\u533a\u7248\u5f00\u653e\u4e86\u8fd9\u90e8\u5206\u7684\u63a5\u53e3\uff0c\u53ef\u901a\u8fc7 ",(0,l.kt)("inlineCode",{parentName:"p"},"cc.Label._canvasPool")," \u8bbf\u95ee\u8be5\u5bf9\u8c61\u6c60\u3002"),(0,l.kt)("p",null,"\u53ef\u4ee5\u8c03\u6574\u6700\u5927\u7f13\u5b58\u6570\u91cf\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-ts"},"cc.Label._canvasPool.max = 64;\n")),(0,l.kt)("p",null,"\u53ef\u4ee5\u9884\u5148\u7f13\u5b58 Canvas \u5bf9\u8c61\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-ts"},"cc.Label._canvasPool.cache(Number.MAX_SAFE_INTEGER);\n")),(0,l.kt)("p",null,"\u9884\u5148\u7f13\u5b58\u63a5\u53e3\u9700\u4f20\u5165\u8981\u7f13\u5b58\u7684\u5bf9\u8c61\u6570\u91cf\uff0c\u65e0\u8bba\u5982\u4f55\uff0c\u5b9e\u9645\u7f13\u5b58\u7684\u5bf9\u8c61\u6570\u91cf\u90fd\u4e0d\u4f1a\u8d85\u8fc7\u8bbe\u7f6e\u7684\u6700\u5927\u6570\u91cf\u3002"),(0,l.kt)("h2",{id:"\u70d8\u7119\u6587\u672c\u6d4b\u91cf\u503c"},"\u70d8\u7119\u6587\u672c\u6d4b\u91cf\u503c"),(0,l.kt)("p",null,"\u5f15\u64ce\u5185\u90e8\u5728\u6e32\u67d3\u6587\u672c\u524d\u9700\u8981\u5148\u6d4b\u91cf\u5b57\u7b26\u7684\u5bbd\u9ad8\uff0c\u8fd9\u662f\u901a\u8fc7 Canvas \u4e0a\u7684 ",(0,l.kt)("inlineCode",{parentName:"p"},"measureText")," \u63a5\u53e3\u5b9e\u73b0\u7684\u3002"),(0,l.kt)("p",null,"\u5982\u679c\u4f60\u5bf9\u6027\u80fd\u8fdb\u884c\u4e86\u5206\u6790\uff0c\u90a3\u4e48\u53ef\u4ee5\u770b\u51fa\uff0c\u8be5\u63a5\u53e3\u5360\u636e\u5355\u6b21\u6587\u672c\u6e32\u67d3\u603b\u8017\u65f6\u7684 80% \u4ee5\u4e0a\u3002"),(0,l.kt)("p",null,"\u5f15\u64ce\u4f1a\u5bf9\u6b64\u63a5\u53e3\u7684\u7ed3\u679c\u8fdb\u884c\u7f13\u5b58\uff0c\u76f8\u540c\u6837\u5f0f\u7684\u6587\u672c\u4f1a\u4ece\u7f13\u5b58\u4e2d\u8bfb\u53d6\uff0c\u907f\u514d\u4e86\u90e8\u5206\u6027\u80fd\u6d88\u8017\u3002"),(0,l.kt)("p",null,"\u4f46\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8be5\u7f13\u5b58\u4ec5\u4f1a\u4fdd\u7559\u6700\u540e 100 \u6b21\u7684\u6d4b\u91cf\u503c\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u6240\u6709 Label \u4f7f\u7528 Char \u6a21\u5f0f\u6e32\u67d3\uff0c\u5728\u6e32\u67d3 100 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u540e\uff0c\u7f13\u5b58\u5c31\u4f1a\u88ab\u9010\u4e2a\u79fb\u9664\uff0c\u6d4b\u91cf\u503c\u53c8\u4f1a\u6709\u5927\u91cf\u6027\u80fd\u6d88\u8017\u3002"),(0,l.kt)("p",null,"\u6240\u4ee5\uff0c\u793e\u533a\u7248\u5bf9\u8fd9\u90e8\u5206\u63a5\u53e3\u8fdb\u884c\u4e86\u4f18\u5316\uff0c\u5f00\u653e\u4e86 ",(0,l.kt)("inlineCode",{parentName:"p"},"cc.textUtils")," \u7684\u90e8\u5206\u63a5\u53e3\u6765\u63a7\u5236\u6d4b\u91cf\u503c\u7f13\u5b58\u3002"),(0,l.kt)("p",null,"\u9996\u5148\uff0c\u4f60\u53ef\u4ee5\u8c03\u6574\u7f13\u5b58\u5bb9\u91cf\uff0c\u5bb9\u91cf\u8d8a\u5927\uff0c\u5c31\u80fd\u907f\u514d\u66f4\u591a\u6d4b\u91cf\u503c\u7684\u6027\u80fd\u6d88\u8017\uff0c\u4f46\u5185\u5b58\u5360\u7528\u4f1a\u4e0a\u5347\uff0c\u8bf7\u89c6\u60c5\u51b5\u800c\u5b9a\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-ts"},"cc.textUtils.measureCache.limit = Number.MAX_SAFE_INTEGER;\n")),(0,l.kt)("p",null,"\u5176\u6b21\uff0c\u6211\u4eec\u5f00\u653e\u4e86\u64cd\u4f5c\u7f13\u5b58\u7684\u63a5\u53e3\uff0c\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u70d8\u7119\u6d4b\u91cf\u503c\uff0c\u5c06\u6d4b\u91cf\u503c\u6570\u636e\u4fdd\u5b58\u5230\u9879\u76ee\u4e2d\uff0c\u5b8c\u5168\u907f\u514d\u6d4b\u91cf\u503c\u7684\u6027\u80fd\u6d88\u8017\uff01"),(0,l.kt)("p",null,"\u83b7\u53d6\u4e0e\u5e94\u7528\u7f13\u5b58\u5bf9\u8c61\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-ts"},"// \u83b7\u53d6\nconst data = cc.textUtils.getMeasureCache();\n\n// \u5e94\u7528\ncc.textUtils.applyMeasureCache(data);\n")),(0,l.kt)("p",null,"\u6211\u4eec\u63a8\u8350\u7684\u7528\u6cd5\u662f\uff1a"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"\u5728\u5f00\u53d1\u6d4b\u8bd5\u7684\u7248\u672c\u4e2d\u6536\u96c6\u7f13\u5b58\u6570\u636e\u5e76\u5e8f\u5217\u5316\u5230\u9879\u76ee\u7684 JSON \u6587\u4ef6\u4e2d\uff08\u56e0\u4e3a\u6536\u96c6\u4f1a\u6709\u6027\u80fd\u6d88\u8017\uff0c\u6240\u4ee5\u7ebf\u4e0a\u7248\u672c\u4e0d\u8fdb\u884c\u6536\u96c6\uff09"),(0,l.kt)("li",{parentName:"ul"},"\u5728\u6e38\u620f\u542f\u52a8\u524d\u5e94\u7528\u7f13\u5b58\u6570\u636e")),(0,l.kt)("p",null,(0,l.kt)("strong",{parentName:"p"},"\u6ce8\u610f")),(0,l.kt)("p",null,"\u7ecf\u8fc7\u6211\u4eec\u7684\u6d4b\u8bd5\uff0c\u540c\u4e2a\u5b57\u7b26\u5728\u5fae\u4fe1\u5c0f\u6e38\u620f\u5e73\u53f0\u4e0e Web \u7aef\u5f97\u51fa\u7684\u6d4b\u91cf\u503c\u662f\u4e00\u81f4\u7684\u3002"),(0,l.kt)("p",null,"\u4f46\u53ef\u80fd\u4f1a\u51fa\u73b0\u5176\u5b83\u4e0d\u540c\u5e73\u53f0\u6216\u8005\u8bbe\u5907\u5bf9\u540c\u4e2a\u5b57\u7b26\u7684\u6d4b\u91cf\u503c\u662f\u4e0d\u4e00\u81f4\u7684\uff0c\u5efa\u8bae\u9488\u5bf9\u8fd9\u79cd\u60c5\u51b5\u70d8\u7119\u591a\u4e2a JSON \u6587\u4ef6\u5e76\u5206\u522b\u5e94\u7528\u5373\u53ef\u3002"),(0,l.kt)("h2",{id:"\u9884\u52a0\u8f7d-char-\u56fe\u96c6"},"\u9884\u52a0\u8f7d ",(0,l.kt)("inlineCode",{parentName:"h2"},"Char")," \u56fe\u96c6"),(0,l.kt)("p",null,"\u5efa\u8bae\u5148\u9605\u8bfb ",(0,l.kt)("a",{parentName:"p",href:"#%E7%83%98%E7%84%99%E6%96%87%E6%9C%AC%E6%B5%8B%E9%87%8F%E5%80%BC"},"\u70d8\u7119\u6587\u672c\u6d4b\u91cf\u503c"),"\uff0c\u518d\u9605\u8bfb\u672c\u8282\u5185\u5bb9\u3002"),(0,l.kt)("p",null,"\u5982\u679c\u4f60\u5bf9\u6027\u80fd\u8fdb\u884c\u4e86\u5206\u6790\uff0c\u90a3\u4e48\u53ef\u4ee5\u770b\u51fa\uff0c\u5373\u4f7f\u6211\u4eec\u70d8\u7119\u4e86\u6587\u672c\u6d4b\u91cf\u503c\uff0c\u4f9d\u65e7\u4f1a\u6709\u5c06\u6587\u672c\u7ed8\u5236\u5230\u7eb9\u7406\u4e0a\u7684\u6027\u80fd\u6d88\u8017\uff0c\u90a3\u4e48\u8fd9\u5269\u4e0b 20% \u7684\u6027\u80fd\u6d88\u8017\u5982\u679c\u65e0\u6cd5\u907f\u514d\uff0c\u80fd\u63a7\u5236\u5b83\u6d88\u8017\u7684\u65f6\u673a\u4e5f\u662f\u5f88\u6709\u610f\u4e49\u7684\u3002"),(0,l.kt)("p",null,"\u6240\u4ee5\uff0c\u793e\u533a\u7248\u63d0\u4f9b\u4e86 Char \u56fe\u96c6\u7684\u9884\u52a0\u8f7d\u63a5\u53e3\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u7279\u5b9a\u65f6\u673a\uff08\u6bd4\u5982\u6e38\u620f\u542f\u52a8\u65f6\uff09\u5c31\u52a0\u8f7d\u597d\u4f1a\u7528\u5230\u7684\u6240\u6709\u5b57\u7b26\uff0c\u907f\u514d\u6e38\u620f\u4e2d\u7684\u5361\u987f\u3002"),(0,l.kt)("p",null,"\u5f15\u64ce\u7684 Char \u56fe\u96c6\u53ea\u4f1a\u5728\u7528\u5230\u65f6\u624d\u4f1a\u521b\u5efa\uff0c\u6240\u4ee5\u6211\u4eec\u5728\u8c03\u7528\u4efb\u4f55\u63a5\u53e3\u524d\u9700\u8981\u521d\u59cb\u5316\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-ts"},"cc.Label.LetterAtlases.init();\n")),(0,l.kt)("p",null,"\u7531\u4e8e\u5f15\u64ce\u5e76\u4e0d\u4f1a\u6301\u6709\u6bcf\u4e2a\u5b57\u7b26\u4fe1\u606f\u7684\u7f13\u5b58\uff0c\u6240\u4ee5\u9700\u8981\u901a\u8fc7\u793e\u533a\u7248\u65b0\u589e\u7684\u5f00\u542f\u7f13\u5b58\u63a5\u53e3\u6765\u4fdd\u7559\u5b57\u7b26\u4fe1\u606f\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-ts"},"cc.Label._shareAtlas.enableLetterCache = true;\n")),(0,l.kt)("p",null,"\u548c\u70d8\u7119\u6587\u672c\u6d4b\u91cf\u503c\u4e00\u6837\uff0c\u6211\u4eec\u53ea\u63a8\u8350\u5728\u5f00\u53d1\u6d4b\u8bd5\u7248\u672c\u6536\u96c6\u7f13\u5b58\uff0c\u56e0\u4e3a\u4fdd\u7559\u7f13\u5b58\u548c\u6536\u96c6\u64cd\u4f5c\u90fd\u4f1a\u6709\u6027\u80fd\u6d88\u8017\u3002"),(0,l.kt)("p",null,"\u4ee5\u4e0b\u4e24\u4e2a\u63a5\u53e3\u53ef\u4ee5\u83b7\u53d6\u4e0e\u5e94\u7528\u5b57\u7b26\u7f13\u5b58\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-ts"},"// \u83b7\u53d6\nconst data = cc.Label._shareAtlas.getLetterCache();\n\n// \u5e94\u7528\ncc.Label._shareAtlas.applyLetterCache(data);\n")),(0,l.kt)("p",null,"\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4eec\u53ea\u662f\u5c06\u6e32\u67d3\u8fc7\u7684\u5b57\u7b26\u4fe1\u606f\u7f13\u5b58\u4e0b\u6765\uff0c\u800c\u4e0d\u662f\u7eb9\u7406\u672c\u8eab\uff0c\u7136\u540e\u5728\u7279\u5b9a\u65f6\u673a\u8c03\u7528\u63a5\u53e3\u6765\u6279\u91cf\u6e32\u67d3\u5b57\u7b26\u5230\u7eb9\u7406\u4e0a\u3002"),(0,l.kt)("p",null,"\u5e76\u4e14\uff0c\u8fd9\u91cc\u7684\u7f13\u5b58\u4fe1\u606f\u5df2\u7ecf\u5305\u62ec\u4e86\u6bcf\u4e2a\u5b57\u7b26\u7684\u6d4b\u91cf\u503c\uff0c\u6240\u4ee5\u5982\u679c\u4f60\u7684\u9879\u76ee\u53ea\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"CHAR")," \u6a21\u5f0f\u7684 Label \u7ec4\u4ef6\uff0c\u90a3\u4e48\u4f60\u4e0d\u7528\u518d\u5355\u72ec\u70d8\u7119\u6587\u672c\u6d4b\u91cf\u503c\u3002"),(0,l.kt)("h2",{id:"\u5b9e\u9645\u5e94\u7528"},"\u5b9e\u9645\u5e94\u7528"),(0,l.kt)("p",null,"\u4f60\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u4ee3\u7801\uff0c\u5728\u6e38\u620f\u5f00\u53d1\u6d4b\u8bd5\u7248\u672c\u4e2d\u5c06\u7f13\u5b58\u6570\u636e\u4e0a\u4f20\u81f3\u4e00\u4e2a\u540e\u7aef\u670d\u52a1\u5668\u3002"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-ts"},'// \u4e0a\u62a5 Label \u70d8\u7119\u4fe1\u606f\nif (!CC_EDITOR && game.TEST) {\n cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, () => {\n // \u542f\u7528\u7f13\u5b58\n cc.Label._shareAtlas.enableLetterCache = true;\n \n setInterval(() => {\n const unCaches = {};\n for (const key in cc.textUtils.measureCache.datas) {\n if (!(key in _measureCache)) {\n unCaches[key] = cc.textUtils.measureCache.datas[key].value;\n _measureCache[key] = unCaches[key];\n console.warn("\u672a\u6536\u96c6\u7684\u6d4b\u91cf\u503c\uff1a", key, unCaches[key]);\n }\n }\n\n if (Object.keys(unCaches).length > 0) {\n sendToServer(JSON.stringify(unCaches));\n }\n\n const unLetters = {};\n for (const key in cc.Label._shareAtlas.letterCache) {\n if (!(key in _letterCache)) {\n unLetters[key] = cc.Label._shareAtlas.letterCache[key];\n _letterCache[key] = unLetters[key];\n console.warn("\u672a\u6536\u96c6\u7684 Char \u5b57\u7b26\uff1a", key, unLetters[key]);\n }\n }\n\n if (Object.keys(unLetters).length > 0) {\n sendToServer(JSON.stringify(unLetters));\n }\n }, 10000);\n });\n}\n')),(0,l.kt)("p",null,"\u7136\u540e\u5728\u6bcf\u4e2a\u7248\u672c\u4e0a\u7ebf\u524d\uff0c\u4ece\u540e\u7aef\u4e0b\u8f7d\u7f13\u5b58\u6570\u636e\u5230\u9879\u76ee\u4e2d\uff0c\u5e76\u7528\u4ee3\u7801\u8bfb\u53d6\u5e76\u5728\u6e38\u620f\u5f00\u59cb\u524d\u5e94\u7528\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-ts"},"cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, () => {\n // \u63d0\u524d\u7f13\u5b58 Label Canvas\n cc.Label._canvasPool.cache(Number.MAX_SAFE_INTEGER);\n\n // \u63d0\u9ad8\u6587\u672c\u6d4b\u91cf\u503c\u7f13\u5b58\u5bb9\u91cf\n cc.textUtils.measureCache.limit = Number.MAX_SAFE_INTEGER;\n cc.textUtils.applyMeasureCache(_measureCache);\n\n // \u70d8\u7119 CHAR \u5b57\u7b26\n cc.Label.LetterAtlases.init();\n cc.Label._shareAtlas.applyLetterCache(_letterCache);\n});\n")))}d.isMDXComponent=!0},77333:function(e,t,n){t.Z=n.p+"assets/images/after-baking-c51a2a28fa45d7143bcc44e6e6c2f5ea.png"},73658:function(e,t,n){t.Z=n.p+"assets/images/before-baking-c6759f737a1faec7971ec238b287eb60.png"}}]);