diff --git a/assets/Game/prefabs/SlotScene.prefab b/assets/Game/SlotScene.prefab similarity index 100% rename from assets/Game/prefabs/SlotScene.prefab rename to assets/Game/SlotScene.prefab diff --git a/assets/Game/prefabs/SlotScene.prefab.meta b/assets/Game/SlotScene.prefab.meta similarity index 100% rename from assets/Game/prefabs/SlotScene.prefab.meta rename to assets/Game/SlotScene.prefab.meta diff --git a/assets/Game/scripts/game/SysGift.ts b/assets/Game/scripts/game/SysGift.ts index 1582e72..95c15dc 100644 --- a/assets/Game/scripts/game/SysGift.ts +++ b/assets/Game/scripts/game/SysGift.ts @@ -28,13 +28,6 @@ export class SysGift extends Component { onLoad(): void { this.hideAll(); - let sp_win = this.info.getChildByName("sysgift_win") - - - sp_win.getComponent(LocalizedSprite).fetchRender(); - let scale = 116 / sp_win.getComponent(Sprite).spriteFrame.width; - sp_win.setScale(scale, scale, scale); - } hideAll() { @@ -53,9 +46,10 @@ export class SysGift extends Component { let txt_spin_num = this.info.getChildByName("count") txt_spin_num.getComponent(Label).string = (frb.Ongoing.Frn.toLocaleString()) - + let sp_win = this.info.getChildByName("sysgift_win") let txt_win = this.info.getChildByName("win") - + let scale = 116 / sp_win.getComponent(Sprite).spriteFrame.width; + sp_win.setScale(scale, scale, scale); let num = Math.round(frb.Ongoing.Fra * 100 + 1e-6) / 100; txt_win.getComponent(Label).string = num.toLocaleString('en-US', { diff --git a/assets/Loading/game.scene b/assets/Loading/game.scene index 8600bcf..6865029 100644 --- a/assets/Loading/game.scene +++ b/assets/Loading/game.scene @@ -23,7 +23,7 @@ "_active": true, "_components": [], "_prefab": { - "__id__": 86 + "__id__": 88 }, "_lpos": { "__type__": "cc.Vec3", @@ -54,7 +54,7 @@ }, "autoReleaseAssets": false, "_globals": { - "__id__": 87 + "__id__": 89 }, "_id": "6c29a3fe-b10e-44a5-98e3-55595b231767" }, @@ -77,25 +77,25 @@ "__id__": 8 }, { - "__id__": 64 + "__id__": 66 }, { - "__id__": 67 + "__id__": 69 } ], "_active": true, "_components": [ - { - "__id__": 82 - }, - { - "__id__": 83 - }, { "__id__": 84 }, { "__id__": 85 + }, + { + "__id__": 86 + }, + { + "__id__": 87 } ], "_prefab": null, @@ -341,22 +341,22 @@ "__id__": 9 }, { - "__id__": 57 + "__id__": 59 } ], "_active": true, "_components": [ - { - "__id__": 60 - }, - { - "__id__": 61 - }, { "__id__": 62 }, { "__id__": 63 + }, + { + "__id__": 64 + }, + { + "__id__": 65 } ], "_prefab": null, @@ -405,37 +405,40 @@ "__id__": 13 }, { - "__id__": 17 + "__id__": 16 }, { - "__id__": 21 + "__id__": 19 }, { - "__id__": 28 + "__id__": 23 }, { - "__id__": 35 + "__id__": 30 }, { - "__id__": 38 + "__id__": 37 }, { - "__id__": 41 + "__id__": 40 }, { - "__id__": 44 + "__id__": 43 }, { - "__id__": 47 + "__id__": 46 + }, + { + "__id__": 49 } ], "_active": true, "_components": [ { - "__id__": 55 + "__id__": 57 }, { - "__id__": 56 + "__id__": 58 } ], "_prefab": null, @@ -579,7 +582,7 @@ }, { "__type__": "cc.Node", - "_name": "logo", + "_name": "logo_en", "_objFlags": 0, "__editorExtras__": {}, "_parent": { @@ -593,9 +596,6 @@ }, { "__id__": 15 - }, - { - "__id__": 16 } ], "_prefab": null, @@ -690,17 +690,113 @@ "_id": "a2KA7dT9RMJZBIPSbZhR0S" }, { - "__type__": "e6c8d4szahIuLbtf6yx+hH6", + "__type__": "cc.Node", + "_name": "logo_zh", + "_objFlags": 0, + "__editorExtras__": {}, + "_parent": { + "__id__": 9 + }, + "_children": [], + "_active": false, + "_components": [ + { + "__id__": 17 + }, + { + "__id__": 18 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 663.101, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_mobility": 0, + "_layer": 33554432, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "8e+2zLMv1HqqxiUKOLQrTw" + }, + { + "__type__": "cc.UITransform", "_name": "", "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 13 + "__id__": 16 }, "_enabled": true, "__prefab": null, - "spriteName": "logo", - "_id": "67Q7ahbKJAM7Vc6X8nDEbW" + "_contentSize": { + "__type__": "cc.Size", + "width": 937, + "height": 329 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "4d5uC1VoVHYJ7MHb/YBMj9" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 16 + }, + "_enabled": true, + "__prefab": null, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_spriteFrame": { + "__uuid__": "51ffde0b-ff7a-4e4e-b639-b58e4b55b73f@f9941", + "__expectedType__": "cc.SpriteFrame" + }, + "_type": 0, + "_fillType": 0, + "_sizeMode": 1, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_useGrayscale": false, + "_atlas": null, + "_id": "f7WVXSzkJGBqk9RieKTXqj" }, { "__type__": "cc.Node", @@ -713,14 +809,14 @@ "_children": [], "_active": true, "_components": [ - { - "__id__": 18 - }, - { - "__id__": 19 - }, { "__id__": 20 + }, + { + "__id__": 21 + }, + { + "__id__": 22 } ], "_prefab": null, @@ -759,7 +855,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 17 + "__id__": 19 }, "_enabled": true, "__prefab": null, @@ -781,7 +877,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 17 + "__id__": 19 }, "_enabled": true, "__prefab": null, @@ -820,7 +916,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 17 + "__id__": 19 }, "_enabled": true, "__prefab": null, @@ -837,19 +933,19 @@ }, "_children": [ { - "__id__": 22 + "__id__": 24 } ], "_active": true, "_components": [ - { - "__id__": 25 - }, - { - "__id__": 26 - }, { "__id__": 27 + }, + { + "__id__": 28 + }, + { + "__id__": 29 } ], "_prefab": null, @@ -888,16 +984,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 21 + "__id__": 23 }, "_children": [], "_active": true, "_components": [ { - "__id__": 23 + "__id__": 25 }, { - "__id__": 24 + "__id__": 26 } ], "_prefab": null, @@ -936,7 +1032,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 22 + "__id__": 24 }, "_enabled": true, "__prefab": null, @@ -958,7 +1054,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 22 + "__id__": 24 }, "_enabled": true, "__prefab": null, @@ -997,7 +1093,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 21 + "__id__": 23 }, "_enabled": true, "__prefab": null, @@ -1019,7 +1115,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 21 + "__id__": 23 }, "_enabled": true, "__prefab": null, @@ -1058,12 +1154,12 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 21 + "__id__": 23 }, "_enabled": true, "__prefab": null, "_barSprite": { - "__id__": 24 + "__id__": 26 }, "_mode": 0, "_totalLength": 494, @@ -1081,19 +1177,19 @@ }, "_children": [ { - "__id__": 29 + "__id__": 31 } ], "_active": true, "_components": [ - { - "__id__": 32 - }, - { - "__id__": 33 - }, { "__id__": 34 + }, + { + "__id__": 35 + }, + { + "__id__": 36 } ], "_prefab": null, @@ -1132,16 +1228,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 28 + "__id__": 30 }, "_children": [], "_active": true, "_components": [ { - "__id__": 30 + "__id__": 32 }, { - "__id__": 31 + "__id__": 33 } ], "_prefab": null, @@ -1180,7 +1276,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 29 + "__id__": 31 }, "_enabled": true, "__prefab": null, @@ -1202,7 +1298,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 29 + "__id__": 31 }, "_enabled": true, "__prefab": null, @@ -1241,7 +1337,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 28 + "__id__": 30 }, "_enabled": true, "__prefab": null, @@ -1263,7 +1359,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 28 + "__id__": 30 }, "_enabled": true, "__prefab": null, @@ -1279,7 +1375,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 28 + "__id__": 30 }, "_enabled": true, "__prefab": null, @@ -1325,10 +1421,10 @@ "_active": true, "_components": [ { - "__id__": 36 + "__id__": 38 }, { - "__id__": 37 + "__id__": 39 } ], "_prefab": null, @@ -1367,7 +1463,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 35 + "__id__": 37 }, "_enabled": true, "__prefab": null, @@ -1389,7 +1485,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 35 + "__id__": 37 }, "_enabled": true, "__prefab": null, @@ -1434,10 +1530,10 @@ "_active": true, "_components": [ { - "__id__": 39 + "__id__": 41 }, { - "__id__": 40 + "__id__": 42 } ], "_prefab": null, @@ -1476,7 +1572,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 38 + "__id__": 40 }, "_enabled": true, "__prefab": null, @@ -1498,7 +1594,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 38 + "__id__": 40 }, "_enabled": true, "__prefab": null, @@ -1566,10 +1662,10 @@ "_active": true, "_components": [ { - "__id__": 42 + "__id__": 44 }, { - "__id__": 43 + "__id__": 45 } ], "_prefab": null, @@ -1608,7 +1704,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 41 + "__id__": 43 }, "_enabled": true, "__prefab": null, @@ -1630,7 +1726,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 41 + "__id__": 43 }, "_enabled": true, "__prefab": null, @@ -1698,10 +1794,10 @@ "_active": true, "_components": [ { - "__id__": 45 + "__id__": 47 }, { - "__id__": 46 + "__id__": 48 } ], "_prefab": null, @@ -1740,7 +1836,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 44 + "__id__": 46 }, "_enabled": true, "__prefab": null, @@ -1762,7 +1858,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 44 + "__id__": 46 }, "_enabled": true, "__prefab": null, @@ -1828,19 +1924,19 @@ }, "_children": [ { - "__id__": 48 + "__id__": 50 } ], "_active": false, "_components": [ - { - "__id__": 51 - }, - { - "__id__": 52 - }, { "__id__": 53 + }, + { + "__id__": 54 + }, + { + "__id__": 55 } ], "_prefab": null, @@ -1879,16 +1975,16 @@ "_objFlags": 512, "__editorExtras__": {}, "_parent": { - "__id__": 47 + "__id__": 49 }, "_children": [], "_active": true, "_components": [ { - "__id__": 49 + "__id__": 51 }, { - "__id__": 50 + "__id__": 52 } ], "_prefab": null, @@ -1927,7 +2023,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 48 + "__id__": 50 }, "_enabled": true, "__prefab": null, @@ -1949,7 +2045,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 48 + "__id__": 50 }, "_enabled": true, "__prefab": null, @@ -2011,7 +2107,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 47 + "__id__": 49 }, "_enabled": true, "__prefab": null, @@ -2033,7 +2129,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 47 + "__id__": 49 }, "_enabled": true, "__prefab": null, @@ -2072,13 +2168,13 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 47 + "__id__": 49 }, "_enabled": true, "__prefab": null, "clickEvents": [ { - "__id__": 54 + "__id__": 56 } ], "_interactable": true, @@ -2130,7 +2226,7 @@ "_duration": 0.1, "_zoomScale": 1.2, "_target": { - "__id__": 47 + "__id__": 49 }, "_id": "54j4lwPyZHbqqANZE+r9Tj" }, @@ -2208,10 +2304,10 @@ "_active": true, "_components": [ { - "__id__": 58 + "__id__": 60 }, { - "__id__": 59 + "__id__": 61 } ], "_prefab": null, @@ -2250,7 +2346,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 57 + "__id__": 59 }, "_enabled": true, "__prefab": null, @@ -2272,7 +2368,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 57 + "__id__": 59 }, "_enabled": true, "__prefab": null, @@ -2416,10 +2512,10 @@ "_active": true, "_components": [ { - "__id__": 65 + "__id__": 67 }, { - "__id__": 66 + "__id__": 68 } ], "_prefab": null, @@ -2458,7 +2554,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 64 + "__id__": 66 }, "_enabled": true, "__prefab": null, @@ -2480,7 +2576,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 64 + "__id__": 66 }, "_enabled": true, "__prefab": null, @@ -2523,22 +2619,22 @@ }, "_children": [ { - "__id__": 68 + "__id__": 70 }, { - "__id__": 72 + "__id__": 74 }, { - "__id__": 77 + "__id__": 79 } ], "_active": false, "_components": [ { - "__id__": 80 + "__id__": 82 }, { - "__id__": 81 + "__id__": 83 } ], "_prefab": null, @@ -2577,19 +2673,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 67 + "__id__": 69 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 69 - }, - { - "__id__": 70 - }, { "__id__": 71 + }, + { + "__id__": 72 + }, + { + "__id__": 73 } ], "_prefab": null, @@ -2628,7 +2724,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 68 + "__id__": 70 }, "_enabled": true, "__prefab": null, @@ -2650,7 +2746,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 68 + "__id__": 70 }, "_enabled": true, "__prefab": null, @@ -2662,7 +2758,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 68 + "__id__": 70 }, "_enabled": true, "__prefab": null, @@ -2701,22 +2797,22 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 67 + "__id__": 69 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 73 - }, - { - "__id__": 74 - }, { "__id__": 75 }, { "__id__": 76 + }, + { + "__id__": 77 + }, + { + "__id__": 78 } ], "_prefab": null, @@ -2755,7 +2851,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 72 + "__id__": 74 }, "_enabled": true, "__prefab": null, @@ -2777,7 +2873,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 72 + "__id__": 74 }, "_enabled": true, "__prefab": null, @@ -2839,7 +2935,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 72 + "__id__": 74 }, "_enabled": true, "__prefab": null, @@ -2852,7 +2948,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 72 + "__id__": 74 }, "_enabled": true, "__prefab": null, @@ -2882,16 +2978,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 67 + "__id__": 69 }, "_children": [], "_active": true, "_components": [ { - "__id__": 78 + "__id__": 80 }, { - "__id__": 79 + "__id__": 81 } ], "_prefab": null, @@ -2930,7 +3026,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 77 + "__id__": 79 }, "_enabled": true, "__prefab": null, @@ -2952,7 +3048,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 77 + "__id__": 79 }, "_enabled": true, "__prefab": null, @@ -2991,7 +3087,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 67 + "__id__": 69 }, "_enabled": true, "__prefab": null, @@ -3013,7 +3109,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 67 + "__id__": 69 }, "_enabled": true, "__prefab": null, @@ -3085,32 +3181,32 @@ }, "_enabled": true, "__prefab": null, - "BG": { - "__id__": 5 + "progressNode": { + "__id__": 23 + }, + "progressBar": { + "__id__": 29 + }, + "progressLabel": { + "__id__": 42 + }, + "loadingLabel": { + "__id__": 45 + }, + "maskSpineNode": { + "__id__": 30 + }, + "lightSpineNode": { + "__id__": 37 + }, + "startBtnNode": { + "__id__": 49 }, "LoadingUINode": { "__id__": 9 }, - "progressBar": { - "__id__": 27 - }, - "progressLabel": { - "__id__": 40 - }, - "loadingTipLabel": { - "__id__": 43 - }, - "retryTipLabel": { - "__id__": 46 - }, - "startBtn": { - "__id__": 53 - }, - "startBtnLabel": { - "__id__": 50 - }, - "GameNode": { - "__id__": 57 + "rb7Logo": { + "__id__": 66 }, "languageJson": { "__uuid__": "65d2a408-9396-47e4-99de-73423a590b7f", @@ -3132,10 +3228,10 @@ "__id__": 5 }, "Logo": { - "__id__": 64 + "__id__": 66 }, "rotateNode": { - "__id__": 67 + "__id__": 69 }, "_id": "d8F/UwpTxNpZhwSJjDvnkk" }, @@ -3150,29 +3246,29 @@ { "__type__": "cc.SceneGlobals", "ambient": { - "__id__": 88 - }, - "shadows": { - "__id__": 89 - }, - "_skybox": { "__id__": 90 }, - "fog": { + "shadows": { "__id__": 91 }, - "octree": { + "_skybox": { "__id__": 92 }, - "skin": { + "fog": { "__id__": 93 }, - "lightProbeInfo": { + "octree": { "__id__": 94 }, - "postSettings": { + "skin": { "__id__": 95 }, + "lightProbeInfo": { + "__id__": 96 + }, + "postSettings": { + "__id__": 97 + }, "bakedWithStationaryMainLight": false, "bakedWithHighpLightmap": false }, diff --git a/assets/Loading/scripts/i18n/LocalizedSprite.ts b/assets/Loading/scripts/i18n/LocalizedSprite.ts index 9850706..df0e200 100644 --- a/assets/Loading/scripts/i18n/LocalizedSprite.ts +++ b/assets/Loading/scripts/i18n/LocalizedSprite.ts @@ -1,7 +1,7 @@ -import { _decorator, Component, SpriteFrame, Sprite, resources } from 'cc'; +import { _decorator, Component, Sprite } from 'cc'; import { I18nManager } from '../manager/I18nManager'; -const { ccclass, property, executeInEditMode } = _decorator; +const { ccclass, property } = _decorator; @ccclass('LocalizedSprite') export class LocalizedSprite extends Component { @@ -15,90 +15,21 @@ export class LocalizedSprite extends Component { this.updateSprite(); } - fetchRender() { - if (!this.sprite) { - this.sprite = this.getComponent(Sprite); - } - - if (this.sprite) { - this.updateSprite(); - } else { - console.warn(`LocalizedSprite: No Sprite component found on node ${this.node.name}`); - this.loadDefaultSprite(); - } - } - public updateSprite() { if (!this.sprite || !this.spriteName) return; + if (!I18nManager.instance.ready) return; + let cacheKey = `${I18nManager.instance.currentLanguage}_${this.spriteName}`; + let cachedFrame = I18nManager.instance.spriteFrameCache.get(cacheKey); - const currentLanguage = I18nManager.instance.currentLanguage; - const cacheKey = `${currentLanguage}_${this.spriteName}`; - - // 从I18nManager获取缓存的SpriteFrame - const cachedFrame = I18nManager.instance.spriteFrameCache.get(cacheKey); if (cachedFrame) { - this.setNewSpriteFrame(cachedFrame); - return; - } - - // 如果缓存中没有,从resources加载 - const spritePath = `i18nSprite/${currentLanguage}/${this.spriteName}/spriteFrame`; - resources.load(spritePath, SpriteFrame, (err, spriteFrame) => { - if (err) { - console.warn(`Failed to load sprite: ${spritePath}`, err); - this.loadDefaultSprite(); - return; - } - - if (spriteFrame) { - // 添加到I18nManager的缓存中 - I18nManager.instance.spriteFrameCache.set(cacheKey, spriteFrame); - this.setNewSpriteFrame(spriteFrame); - } - }); - } - - private loadDefaultSprite() { - const defaultPath = `i18nSprite/en/${this.spriteName}/spriteFrame`; - const cacheKey = `en_${this.spriteName}`; - - // 从I18nManager获取默认语言的缓存 - const cachedFrame = I18nManager.instance.spriteFrameCache.get(cacheKey); - if (cachedFrame) { - this.setNewSpriteFrame(cachedFrame); - return; - } - - resources.load(defaultPath, SpriteFrame, (err, spriteFrame) => { - if (err) { - console.error('Failed to load default sprite:', err); - return; - } - - if (spriteFrame) { - // 添加到I18nManager的缓存中 - I18nManager.instance.spriteFrameCache.set(cacheKey, spriteFrame); - this.setNewSpriteFrame(spriteFrame); - } - }); - } - - private setNewSpriteFrame(newFrame: SpriteFrame) { - if (this.sprite) { - this.sprite.spriteFrame = newFrame; + this.sprite.spriteFrame = cachedFrame; } } - public setSpriteName(name: string) { - this.spriteName = name; - this.updateSprite(); - } - - onDestroy() { - // 只清理当前组件的引用 - if (this.sprite) { - this.sprite.spriteFrame = null; - } - this.sprite = null; + updateSpriteForPreload(language: string) { + this.sprite = this.getComponent(Sprite); + let cacheKey = `${language}_${this.spriteName}`; + let cachedFrame = I18nManager.instance.spriteFrameCache.get(cacheKey); + this.sprite.spriteFrame = cachedFrame; } } \ No newline at end of file diff --git a/assets/Loading/scripts/loading.ts b/assets/Loading/scripts/loading.ts index 611692e..c357419 100644 --- a/assets/Loading/scripts/loading.ts +++ b/assets/Loading/scripts/loading.ts @@ -1,296 +1,236 @@ -import { _decorator, Component, Node, ProgressBar, Label, Button, view, VideoPlayer, UITransform, AssetManager, tween, ResolutionPolicy, game, director, Director, sys, macro, JsonAsset } from 'cc'; +import { _decorator, Component, Node, ProgressBar, Label, UITransform, tween, JsonAsset } from 'cc'; import { callGameApi, getIsRB7, getLanguage, initReqAddr } from './comm'; -import { GameDataManager } from './manager/GameDataManager'; -import { ResManager } from './manager/ResManager'; -import { AudioManager } from './manager/AudioManager'; -import { NodePoolManager } from './manager/NodePoolManager'; +import { DEBUG } from 'cc/env'; +import { initErrorManager } from './manager/ErrorManager'; import { I18nManager } from './manager/I18nManager'; import { LocalizedSprite } from './i18n/LocalizedSprite'; -import { initErrorManager } from './manager/ErrorManager'; -let { ccclass, property } = _decorator; - -@ccclass('LoadingUI') -export class LoadingUI extends Component { - //test - @property(Node) - BG: Node = null; - - @property(Node) - LoadingUINode: Node = null; - - @property(ProgressBar) - progressBar: ProgressBar = null; - - @property(Label) - progressLabel: Label = null; - - @property(Label) - loadingTipLabel: Label = null; - - @property(Label) - retryTipLabel: Label = null; - - @property(Button) - startBtn: Button = null; - - @property(Label) - startBtnLabel: Label = null; - - @property(Node) - GameNode: Node = null; - - @property(JsonAsset) - languageJson: JsonAsset = null; - - private _networkComplete = false; - private _retryCount = 0; - private readonly MAX_RETRY = 5; - private INITIAL_PROGRESS = 0.3; - private _instanceGameNode = null; +import { AudioManager } from './manager/AudioManager'; +import { GameDataManager } from './manager/GameDataManager'; +import { ResManager } from './manager/ResManager'; +import { NodePoolManager } from './manager/NodePoolManager'; - // 新增动画 - private maskUITransform: UITransform = null; - private lightNode: Node = null; +const { ccclass, property } = _decorator; + +@ccclass('Loading') +export class Loading extends Component { + // UI组件 + @property(Node) progressNode: Node = null; + @property(ProgressBar) progressBar: ProgressBar = null; + @property(Label) progressLabel: Label = null; + @property(Label) loadingLabel: Label = null; + @property(Node) maskSpineNode: Node = null; + @property(Node) lightSpineNode: Node = null; + @property(Node) startBtnNode: Node = null; + @property(Node) LoadingUINode: Node = null; + @property(Node) rb7Logo: Node = null; + @property(JsonAsset) languageJson: JsonAsset = null; + + // 加载状态 + private isNetworkReady = false; + private readonly PROGRESS_ANIMATION_DURATION = 0.3; + + // 进度条阶段 + private readonly PROGRESS_INIT = 0.2; // 初始化完成 + private readonly PROGRESS_NETWORK = 0.5; // 网络请求完成 + private readonly PROGRESS_RESOURCE = 0.9; // 资源加载完成 + private readonly PROGRESS_COMPLETE = 1.0; // 完全加载完成 + + // 游戏节点 + private gameContainer: Node = null; + private gameNode: Node = null; + protected async onLoad() { - // initErrorManager(); - // 初始显示状态 - this.initUI(); - this.LoadingUINode.active = false; - } + initReqAddr(); + let language = getLanguage(); + if (getLanguage() == 'zh') { + this.node.getChildByPath("Mask/LoadingUINode/logo_zh").active = true; + this.node.getChildByPath("Mask/LoadingUINode/logo_en").active = false; + } else { + this.node.getChildByPath("Mask/LoadingUINode/logo_zh").active = false; + this.node.getChildByPath("Mask/LoadingUINode/logo_en").active = true; + } + + initErrorManager(); + await I18nManager.instance.ensureI18nSprite(language, '2'); + this.node.getChildByPath('Mask/LoadingUINode/msg').getComponent(LocalizedSprite).updateSpriteForPreload(language); + this.node.getChildByPath('Mask/LoadingUINode/msg').active = true; + + await I18nManager.instance.init(language, this.languageJson); + I18nManager.instance.updateSceneRenderers(); + + this.initializeUI(); + // 初始化完成,进度条到20% + this.updateProgress(this.PROGRESS_INIT); - async start() { try { - initReqAddr(); - this.node.getChildByName('Logo').active = getIsRB7(); - await I18nManager.instance.init(getLanguage(), this.languageJson); - I18nManager.instance.updateSceneRenderers(); - // this.LoadingUINode.getChildByName("bg").getComponent(LocalizedSprite).fetchRender(); - this.LoadingUINode.active = true; - // 更新进度条到 0.4 - this.updateProgress(0.4); - + await this.initializeSystem(); AudioManager.instance.init(); - game.setFrameRate(61); - // this.checkStartLoading(); - // 开始网络请求 - this.initNetwork(); + this.updateLoadingText('AID_LOADING'); + // 延迟一下让用户看到进度条开始 + this.scheduleOnce(() => { + this.startNetworkLoading(); + }, 0.2); } catch (error) { console.error('Network initialization failed:', error); - this.handleError(error); + // this.handleError(error); } - - } - - private initUI() { - this.BG.active = true; - this.startBtn.node.active = false; - this.maskUITransform = this.LoadingUINode.getChildByName('mask').getComponent(UITransform); - this.lightNode = this.LoadingUINode.getChildByName('light'); - this.updateProgress(this.INITIAL_PROGRESS); } - private async initNetwork() { + /** 初始化系统 */ + private async initializeSystem() { + this.rb7Logo.active = getIsRB7(); + // if (DEBUG) { + // await getTestToken('nova006', 'faketrans'); + // } + } + + /** 初始化UI */ + private initializeUI() { + this.startBtnNode.active = false; + this.gameContainer = this.node.getChildByPath('Mask/GameNode') + + // 初始化进度条为0 + this.updateProgress(0); + } + + /** 开始网络加载 */ + private async startNetworkLoading() { + this.updateLoadingText('AID_LOADING'); + try { - // 更新进度条到 0.6 - this.updateProgress(0.6); - this.loadingTipLabel.string = I18nManager.instance.t('AID_LOADING'); - this.retryTipLabel.string = ''; let gameInfo = await callGameApi("gameinfo", {}); - if (!gameInfo) throw new Error('Get game info failed'); + GameDataManager.instance.gameInfo = gameInfo; + this.isNetworkReady = true; - // 更新进度条到 0.8 - this.updateProgress(0.8); + // 网络请求完成,进度条到50% + this.updateProgress(this.PROGRESS_NETWORK); - this._networkComplete = true; - - await GameDataManager.instance.preloadFrameTypeCache(); - await GameDataManager.instance.preloadSymbolCache(); - this.checkStartLoading(); + // 稍微延迟一下让用户看到进度变化 + this.scheduleOnce(() => { + this.startResourceLoading(); + }, 0.3); } catch (error) { - console.error('Network initialization failed:', error); - this.handleError(error); + } + } - private checkStartLoading() { - if (this._networkComplete) { - this.LoadingUINode.active = true; - this.startLoadingGameBundle(); - } - } + /** 开始资源加载 */ + private async startResourceLoading() { + if (!this.isNetworkReady) return; - private async startLoadingGameBundle() { - try { - // 显示加载UI - this.loadingTipLabel.string = I18nManager.instance.t('AID_LOADING'); - this.retryTipLabel.string = ''; - this.startBtn.node.active = false; + // this.updateLoadingText('Loading More...'); + this.startBtnNode.active = false; - // 从 0.8 开始加载 - let startProgress = 0.8; - - // 使用新的合并函数加载 Bundle 和预制体 - this._instanceGameNode = await ResManager.instance.loadPrefabFromBundle( - 'Game', - 'prefabs/SlotScene', - (finished: number, total: number) => { - if (total <= 0) return; - let bundleProgress = finished / total; - // 将加载进度映射到 0.8-1 的范围 - let mappedProgress = startProgress + (bundleProgress * (1 - startProgress)); - this.updateProgress(mappedProgress); + this.gameNode = await ResManager.instance.loadPrefabFromBundle( + 'Game', + 'SlotScene', + (finished: number, total: number) => { + if (total > 0) { + // 资源加载进度从50%到90% + const resourceProgress = finished / total; + const currentProgress = this.PROGRESS_NETWORK + + (resourceProgress * (this.PROGRESS_RESOURCE - this.PROGRESS_NETWORK)); + this.updateProgress(currentProgress); } - ); + } + ); - this.updateProgress(1); - this.onLoadComplete(); - } catch (error) { - console.error('Loading error:', error); - this.handleError(error); - } + // 资源加载完成,进度条到90% + this.updateProgress(this.PROGRESS_RESOURCE); + + // 延迟一下然后完成最后的10% + this.scheduleOnce(() => { + this.finishLoading(); + }, 0.2); } + /** 完成加载 */ + private finishLoading() { + // this.updateLoadingText('Loading More...'); + // 最后10%快速完成 + this.updateProgress(this.PROGRESS_COMPLETE); + + // 0.5秒后显示开始按钮 + this.scheduleOnce(() => { + this.onLoadComplete(); + }, 0.5); + } + + /** 更新进度条 */ private updateProgress(progress: number) { - // 使用 tween 使进度条更新更平滑 + tween(this.progressBar) - .to(0.2, { progress: progress }, { + .to(this.PROGRESS_ANIMATION_DURATION, { progress }, { easing: 'smooth', - onUpdate: (target: any, ratio: number) => { - this.progressLabel.string = `${Math.floor(target.progress * 100)}%`; - this.maskUITransform.width = target.progress * 494; - this.lightNode.setPosition(target.progress * 496 - 274, -612, 0); + onUpdate: (target: any) => { + const currentProgress = target.progress; + this.progressLabel.string = `${Math.floor(currentProgress * 100)}%`; + this.maskSpineNode.getComponent(UITransform).setContentSize(currentProgress * 509, 100); + this.lightSpineNode.setPosition(currentProgress * 509 - 278, -612, 0) } }) .start(); } + + + /** 更新加载文本 */ + private updateLoadingText(key: string) { + this.loadingLabel.string = `${I18nManager.instance.t(key)}...`; + } + + /** 加载完成 */ private onLoadComplete() { - // 开始游戏 - this.scheduleOnce(() => { - this.loadingTipLabel.string = ''; - this.retryTipLabel.string = ''; - this.startBtn.node.active = true; - this.startBtnLabel.string = I18nManager.instance.t('AID_GET_STARTED'); - this.progressBar.node.active = false; - this.progressLabel.node.active = false; - - this.maskUITransform.node.active = false; - this.lightNode.active = false; - }, 0.3); + this.hideProgressUI(); + this.showStartButton(); } - private handleError(error: Error) { - this._retryCount++; - this.loadingTipLabel.string = ''; - if (this._retryCount <= this.MAX_RETRY) { - // 自动重试 - switch (this._retryCount) { - case 1: - this.retryTipLabel.string = I18nManager.instance.t('AID_NETWORK_RETRY_1'); - break - case 2: - this.retryTipLabel.string = I18nManager.instance.t('AID_NETWORK_RETRY_2'); - break - case 3: - this.retryTipLabel.string = I18nManager.instance.t('AID_NETWORK_RETRY_3'); - break - case 4: - this.retryTipLabel.string = I18nManager.instance.t('AID_NETWORK_RETRY_4'); - break - case 5: - this.retryTipLabel.string = I18nManager.instance.t('AID_NETWORK_RETRY_5'); - break - - } - this.scheduleOnce(() => { - if (!this._networkComplete) { - this.initNetwork(); - } else { - this.startLoadingGameBundle(); - } - }, 2); - } else { - // 显示重试按钮 - this.loadingTipLabel.string = I18nManager.instance.t('AID_LOADING'); - this.retryTipLabel.string = ''; - this.startBtn.node.active = true; - this.progressBar.node.active = false; - this.progressLabel.node.active = false; - - - this.maskUITransform.node.active = false; - this.lightNode.active = false; - - this.startBtnLabel.string = I18nManager.instance.t('AID_ERROR_RETRY_BUTTON'); - } + /** 隐藏进度UI */ + private hideProgressUI() { + this.loadingLabel.string = ''; + this.progressBar.node.active = false; + this.progressLabel.node.active = false; + this.maskSpineNode.active = false; + this.lightSpineNode.active = false; } + /** 显示开始按钮 */ + private showStartButton() { + this.startBtnNode.active = true; + } + + + /** 开始游戏 */ + // private startGame() { + // if (!this.gameContainer) { + // console.error('Game container not found'); + // return; + // } + + // this.gameContainer.addChild(this.gameNode); + // // this.node.destroy(); + // } + + /** 按钮点击事件 */ onStartBtnClick() { - if (this.startBtnLabel.string === I18nManager.instance.t('AID_ERROR_RETRY_BUTTON')) { - // 重试逻辑 - this._retryCount = 0; - this.startBtn.node.active = false; - this.progressBar.node.active = true; - this.progressLabel.node.active = true; - - - this.maskUITransform.node.active = true; - this.lightNode.active = true; - - if (!this._networkComplete) { - this.initNetwork(); - } else { - this.startLoadingGameBundle(); - } - } else if (this.startBtnLabel.string === I18nManager.instance.t('AID_GET_STARTED')) { - this.node.getChildByName('Logo').active = false; - // 确保 GameNode 存在 - if (!this.GameNode) { - throw new Error('GameNode is not set'); - } - // 添加到场景 - this.GameNode.addChild(this._instanceGameNode); - // 隐藏加载界面 - this.LoadingUINode.destroy(); - } + this.rb7Logo.active = false; + // 添加到场景 + this.gameContainer.addChild(this.gameNode); + // 隐藏加载界面 + this.LoadingUINode.destroy(); } onDestroy() { this.unscheduleAllCallbacks(); tween(this.progressBar).stop(); - AudioManager.instance.destroy(); NodePoolManager.instance.clearAll(); } - - - - // UNKNOWN = 0, // 未知平台 - // WINDOWS = 1, // Windows - // LINUX = 2, // Linux - // MACOS = 3, // macOS - // ANDROID = 4, // Android - // IOS = 5, // iOS - // MOBILE_BROWSER = 6, // 移动端浏览器 - // DESKTOP_BROWSER = 7,// 桌面端浏览器 - // WECHAT_GAME = 8, // 微信小游戏 - // BAIDU_MINI_GAME = 9,// 百度小游戏 - // XIAOMI_QUICK_GAME = 10,// 小米快游戏 - // ALIPAY_MINI_GAME = 11, // 支付宝小游戏 - // BYTEDANCE_MINI_GAME = 12,// 字节跳动小游戏 - // OPPO_MINI_GAME = 13,// OPPO小游戏 - // VIVO_MINI_GAME = 14,// vivo小游戏 - // HUAWEI_QUICK_GAME = 15,// 华为快游戏 - // COCOSPLAY = 16, // Cocos Play - // LINKSURE_MINI_GAME = 17,// 连尚小游戏 - // QTT_MINI_GAME = 18 // 趣头条小游戏 - - - } diff --git a/assets/Loading/scripts/manager/I18nManager.ts b/assets/Loading/scripts/manager/I18nManager.ts index 2529665..d07001f 100644 --- a/assets/Loading/scripts/manager/I18nManager.ts +++ b/assets/Loading/scripts/manager/I18nManager.ts @@ -1,148 +1,165 @@ -import { resources, JsonAsset, director, SpriteFrame, Sprite, Node, SpriteAtlas, sp } from 'cc'; -import { LocalizedSprite } from '../i18n/LocalizedSprite'; +import { resources, JsonAsset, director, SpriteFrame, SpriteAtlas, sp } from 'cc'; export class I18nManager { - private static _instance: I18nManager = null; + + private static _instance: I18nManager; spriteFrameCache: Map = new Map(); spineCache: Map = new Map(); + _sfTasks = new Map>(); languageData: Record = {}; currentLanguage: string = 'en'; ready: boolean = false; static get instance() { - if (this._instance) { - return this._instance; - } - this._instance = new I18nManager(); - return this._instance; + return this._instance || (this._instance = new I18nManager()); } private constructor() { } + + + // yield/await 风格:谁都可以 await,且只加载一次 + ensureI18nSprite(lang: string, name: string): Promise { + const key = `${lang}_${name}`; + const path = `i18nSprite/${lang}/${name}/spriteFrame`; + + const cached = this.spriteFrameCache.get(key); + if (cached) return Promise.resolve(cached); + + const pending = this._sfTasks.get(key); + if (pending) return pending; + + const task = new Promise((resolve, reject) => { + resources.load(path, SpriteFrame, (err, sf) => { + this._sfTasks.delete(key); + if (err || !sf) return reject(err); + this.spriteFrameCache.set(key, sf); + resolve(sf); + }); + }); + this._sfTasks.set(key, task); + return task; + } + /** - * 初始化语言管理器 - * @param language 初始语言 + * 初始化国际化管理器 + * @param language 初始语言代码 + * @param languageJson 语言数据JSON资源 */ - public async init(language: string = 'en', languageJson: JsonAsset): Promise { + public async init(language: string = 'en', languageJson: JsonAsset = null): Promise { this.currentLanguage = language; try { - this.languageData = languageJson.json; + if (languageJson) { + this.languageData = languageJson.json; + } - // 预加载并缓存图片资源 - await this.preloadSpriteFrames(); - await this.preloadSpriteFrameAltas(); - await this.preloadSpineAssets(); // 新增预加载 spine 资源 - this.ready = true; + // 预加载资源(目前资源列表为空,可根据需要添加) + let okSprite = await this.preloadAssets('spriteFrame', [ + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + '10', + '11', + '12', + '13', + '14', + '15', + '16', + '17', + '18', + '19', + '20', + '21', + '22', + '23', + '24', + '25', + '26', + '27', + '29', + '30', + '98', + '99', + 'Buy_5', + 'sysgift_completed', + 'sysgift_continue', + 'sysgift_fbs', + 'sysgift_info_fbs', + 'sysgift_received', + 'sysgift_symbols', + 'sysgift_total', + 'sysgift_win', + ]); + let okAtlas = await this.preloadAssets('atlas', []); + let okSpine = await this.preloadAssets('spine', []); + + this.ready = okSprite && okAtlas && okSpine; } catch (error) { - + console.error('I18nManager init failed:', error); } } - getIsReady() { - return this.ready; - } - /** - * 预加载并缓存图片资源 + * 预加载指定类型的资源 + * @param type 资源类型 + * @param names 资源名称列表 */ - private async preloadSpriteFrames(): Promise { - const imageNames = [ - 'loadingBg', - 'sysgift_completed', - 'sysgift_continue', - 'sysgift_fbs', - 'sysgift_info_fbs', - 'sysgift_received', - 'sysgift_symbols', - 'sysgift_total', - 'sysgift_win', - ]; - - for (const name of imageNames) { - const path = `i18nSprite/${this.currentLanguage}/${name}/spriteFrame`; - const cacheKey = `${this.currentLanguage}_${name}`; - - if (!this.spriteFrameCache.has(cacheKey)) { - await new Promise((resolve) => { - resources.load(path, SpriteFrame, (err, spriteFrame) => { - if (!err && spriteFrame) { - this.spriteFrameCache.set(cacheKey, spriteFrame); - } - resolve(); - }); - }); - } - } + private async preloadAssets(type: 'spriteFrame' | 'atlas' | 'spine', names: string[]): Promise { + let results = await Promise.all(names.map(name => this.loadAsset(type, name))); + return results.every(ok => ok); } - private async preloadSpriteFrameAltas(): Promise { - const altasNames = [ - `FreeSpinINOUT_${this.currentLanguage}`, - `BuyFeature_${this.currentLanguage}`, - `Others_${this.currentLanguage}`, - `SymbolsInfo_${this.currentLanguage}`, - ] + /** + * 加载单个资源 + * @param type 资源类型 + * @param name 资源名称 + */ + private loadAsset(type: 'spriteFrame' | 'atlas' | 'spine', name: string): Promise { + return new Promise(resolve => { + let cacheKey = `${this.currentLanguage}_${name}`; - for (const altasName of altasNames) { - const atlasPath = `i18nSprite/${this.currentLanguage}/${altasName}`; - // 加载图集并缓存其中的多个 SpriteFrame - await new Promise((resolve) => { - resources.load(atlasPath, SpriteAtlas, (err, atlas) => { - if (!err && atlas) { - const spriteFrames = atlas.getSpriteFrames(); - spriteFrames.forEach((frame, index) => { - let name = frame.name; - const cacheKey = `${this.currentLanguage}_${name}`; - this.spriteFrameCache.set(cacheKey, frame); - }); + if (type === 'spriteFrame') { + let path = `i18nSprite/${this.currentLanguage}/${name}/spriteFrame`; + resources.load(path, SpriteFrame, (err, asset) => { + if (!err && asset) { + this.spriteFrameCache.set(cacheKey, asset); + resolve(true); + } else { + console.warn(`[i18n] spriteFrame load failed: ${path}`, err?.message || err); + resolve(false); } - resolve(); }); - }); - } - } - - // 添加预加载 Spine 资源的方法 - private async preloadSpineAssets(): Promise { - const spineNames = [ - `WinWinWin_${this.currentLanguage}`, - ]; - - for (const name of spineNames) { - const path = `i18nSprite/${this.currentLanguage}/${name}`; - const cacheKey = `${this.currentLanguage}_${name}`; - - if (!this.spineCache.has(cacheKey)) { - await new Promise((resolve) => { - resources.load(path, sp.SkeletonData, (err, spineData) => { - if (!err && spineData) { - this.spineCache.set(cacheKey, spineData); - } - resolve(); - }); + } else if (type === 'atlas') { + let path = `i18nSprite/${this.currentLanguage}/${name}`; + resources.load(path, SpriteAtlas, (err, atlas) => { + if (!err && atlas) { + atlas.getSpriteFrames().forEach(frame => { + this.spriteFrameCache.set(`${this.currentLanguage}_${frame.name}`, frame); + }); + resolve(true); + } else { + console.warn(`[i18n] atlas load failed: ${path}`, err?.message || err); + resolve(false); + } + }); + } else if (type === 'spine') { + let path = `i18nSpine/${this.currentLanguage}/${name}`; + resources.load(path, sp.SkeletonData, (err, asset) => { + if (!err && asset) { + this.spineCache.set(cacheKey, asset); + resolve(true); + } else { + console.warn(`[i18n] spine load failed: ${path}`, err?.message || err); + resolve(false); + } }); } - } - } - - setSpriteFrame(node: Node, name: string) { - // 先尝试从缓存获取 - const cacheKey = `${this.currentLanguage}_${name}`; - const cachedFrame = this.spriteFrameCache.get(cacheKey); - - if (cachedFrame) { - const sprite = node.getComponent(Sprite); - if (sprite) { - sprite.spriteFrame = cachedFrame; - return; - } - } - - // 如果缓存中没有,则使用原有逻辑 - let spriteNode = node.getComponent(LocalizedSprite); - if (spriteNode) { - spriteNode.setSpriteName(name); - } + }); } /** @@ -159,17 +176,21 @@ export class I18nManager { /** * 翻译文本 * @param key 翻译键 + * @returns 翻译后的文本,如果找不到则返回键本身 */ public t(key: string): string { - const translation = this.languageData[this.currentLanguage]?.[key]; - if (!translation) { - return key; // Return the key itself if translation is not found - } - return translation; + return this.languageData[this.currentLanguage]?.[key] || key; + } + + public getSpriteFrame(spriteName: string): SpriteFrame { + let cacheKey = `${this.currentLanguage}_${spriteName}`; + let cachedFrame = this.spriteFrameCache.get(cacheKey); + return cachedFrame; } /** - * 更新场景中的本地化组件 + * 更新场景中的所有本地化组件 + * 在语言切换时调用,刷新所有本地化文本和资源 */ public updateSceneRenderers(): void { if (!this.ready) { @@ -178,41 +199,23 @@ export class I18nManager { } let scene = director.getScene(); - if (!scene || !scene.isValid) return; + if (!scene?.isValid) return; - const rootNodes = director.getScene()?.children || []; - const allLocalizedLabels: any[] = []; - const allLocalizedSprites: any[] = []; + // 收集所有本地化组件 + let allLocalizedLabels = []; + let allLocalizedSprites = []; - rootNodes.forEach(node => { + scene.children.forEach(node => { allLocalizedLabels.push(...node.getComponentsInChildren('LocalizedLabel')); allLocalizedSprites.push(...node.getComponentsInChildren('LocalizedSprite')); }); - allLocalizedLabels.forEach(label => { - if (label.node.active) { - label.updateLabel(); - } - }); - - allLocalizedSprites.forEach(sprite => { - if (sprite.node.active) { - sprite.updateSprite(); + // 更新所有激活的本地化组件 + [...allLocalizedLabels, ...allLocalizedSprites].forEach(component => { + if (component.node.active) { + // 调用对应的更新方法 + component.updateLabel?.() || component.updateSprite?.(); } }); } -} - -// // 供插件查询当前语言使用 -// const win = window as any; -// win._languageData = { -// get language() { -// return I18nManager.instance.currentLanguage; -// }, -// init(lang: string) { -// I18nManager.instance.init(lang); -// }, -// updateSceneRenderers() { -// I18nManager.instance.updateSceneRenderers(); -// }, -// }; \ No newline at end of file +} \ No newline at end of file diff --git a/assets/resources/i18nSprite/en/logo.png b/assets/Loading/textures/loadingImg/logo_en.png similarity index 100% rename from assets/resources/i18nSprite/en/logo.png rename to assets/Loading/textures/loadingImg/logo_en.png diff --git a/assets/resources/i18nSprite/en/logo.png.meta b/assets/Loading/textures/loadingImg/logo_en.png.meta similarity index 97% rename from assets/resources/i18nSprite/en/logo.png.meta rename to assets/Loading/textures/loadingImg/logo_en.png.meta index dbac5b1..7bc93ec 100644 --- a/assets/resources/i18nSprite/en/logo.png.meta +++ b/assets/Loading/textures/loadingImg/logo_en.png.meta @@ -11,7 +11,7 @@ "6c48a": { "importer": "texture", "uuid": "fc4357cf-5f55-416c-b94a-b412108a32a7@6c48a", - "displayName": "logo", + "displayName": "logo_en", "id": "6c48a", "name": "texture", "userData": { @@ -35,7 +35,7 @@ "f9941": { "importer": "sprite-frame", "uuid": "fc4357cf-5f55-416c-b94a-b412108a32a7@f9941", - "displayName": "logo", + "displayName": "logo_en", "id": "f9941", "name": "spriteFrame", "userData": { diff --git a/assets/resources/i18nSprite/zh/logo.png b/assets/Loading/textures/loadingImg/logo_zh.png similarity index 100% rename from assets/resources/i18nSprite/zh/logo.png rename to assets/Loading/textures/loadingImg/logo_zh.png diff --git a/assets/resources/i18nSprite/zh/logo.png.meta b/assets/Loading/textures/loadingImg/logo_zh.png.meta similarity index 97% rename from assets/resources/i18nSprite/zh/logo.png.meta rename to assets/Loading/textures/loadingImg/logo_zh.png.meta index 6a4f716..31ebd25 100644 --- a/assets/resources/i18nSprite/zh/logo.png.meta +++ b/assets/Loading/textures/loadingImg/logo_zh.png.meta @@ -11,7 +11,7 @@ "6c48a": { "importer": "texture", "uuid": "51ffde0b-ff7a-4e4e-b639-b58e4b55b73f@6c48a", - "displayName": "logo", + "displayName": "logo_zh", "id": "6c48a", "name": "texture", "userData": { @@ -35,7 +35,7 @@ "f9941": { "importer": "sprite-frame", "uuid": "51ffde0b-ff7a-4e4e-b639-b58e4b55b73f@f9941", - "displayName": "logo", + "displayName": "logo_zh", "id": "f9941", "name": "spriteFrame", "userData": {