├── README.md └── YiyuanCocosFramework ├── .gitignore ├── README.md ├── assets ├── Scene.meta ├── Scene │ ├── helloworld.fire │ └── helloworld.fire.meta ├── Script.meta ├── Script │ ├── Core.meta │ ├── Core │ │ ├── Audio.meta │ │ ├── Audio │ │ │ ├── AudioMgr.ts │ │ │ └── AudioMgr.ts.meta │ │ ├── Config.meta │ │ ├── Config │ │ │ ├── ConfigMgr.ts │ │ │ └── ConfigMgr.ts.meta │ │ ├── Event.meta │ │ ├── Event │ │ │ ├── EventMgr.ts │ │ │ └── EventMgr.ts.meta │ │ ├── HotUpdate.meta │ │ ├── HotUpdate │ │ │ ├── HotUpdateManager.ts │ │ │ └── HotUpdateManager.ts.meta │ │ ├── Language.meta │ │ ├── Language │ │ │ ├── LocalizationMgr.ts │ │ │ └── LocalizationMgr.ts.meta │ │ ├── Log.meta │ │ ├── Log │ │ │ ├── Log.ts │ │ │ └── Log.ts.meta │ │ ├── Map.meta │ │ ├── Map │ │ │ ├── AStar.meta │ │ │ ├── AStar │ │ │ │ ├── AstarTest.ts │ │ │ │ ├── AstarTest.ts.meta │ │ │ │ ├── SimpleAstar.ts │ │ │ │ └── SimpleAstar.ts.meta │ │ │ ├── Map.ts │ │ │ ├── Map.ts.meta │ │ │ ├── MapEditor.meta │ │ │ ├── MapEditor │ │ │ │ ├── MapEditor.ts │ │ │ │ └── MapEditor.ts.meta │ │ │ ├── MapGameData.ts │ │ │ ├── MapGameData.ts.meta │ │ │ ├── MapTile.ts │ │ │ ├── MapTile.ts.meta │ │ │ ├── MapTiles.ts │ │ │ └── MapTiles.ts.meta │ │ ├── Net.meta │ │ ├── Net │ │ │ ├── Http.ts │ │ │ ├── Http.ts.meta │ │ │ ├── Protocol.meta │ │ │ ├── Protocol │ │ │ │ ├── NoProtocolManager.ts │ │ │ │ ├── NoProtocolManager.ts.meta │ │ │ │ ├── ProtocolManager.ts │ │ │ │ ├── ProtocolManager.ts.meta │ │ │ │ ├── ProtocolManager2.ts │ │ │ │ └── ProtocolManager2.ts.meta │ │ │ ├── Socket.ts │ │ │ └── Socket.ts.meta │ │ ├── Pool.meta │ │ ├── Pool │ │ │ ├── ObjectPoolMgr.ts │ │ │ └── ObjectPoolMgr.ts.meta │ │ ├── Res.meta │ │ ├── Res │ │ │ ├── ResMgr.ts │ │ │ └── ResMgr.ts.meta │ │ ├── Scene.meta │ │ ├── Scene │ │ │ ├── SceneManager.ts │ │ │ └── SceneManager.ts.meta │ │ ├── Sdk.meta │ │ ├── Sdk │ │ │ ├── BaseSdk.ts │ │ │ ├── BaseSdk.ts.meta │ │ │ ├── SdkInterface.ts │ │ │ ├── SdkInterface.ts.meta │ │ │ ├── SdkMgr.ts │ │ │ ├── SdkMgr.ts.meta │ │ │ ├── WxSdk.ts │ │ │ └── WxSdk.ts.meta │ │ ├── Timer.meta │ │ ├── Timer │ │ │ ├── TimerMgr.ts │ │ │ └── TimerMgr.ts.meta │ │ ├── UI.meta │ │ ├── UI │ │ │ ├── Layer.ts │ │ │ ├── Layer.ts.meta │ │ │ ├── Popup.ts │ │ │ ├── Popup.ts.meta │ │ │ ├── ResMgr.ts │ │ │ ├── ResMgr.ts.meta │ │ │ ├── UI.ts │ │ │ ├── UI.ts.meta │ │ │ ├── UIMgr.ts │ │ │ └── UIMgr.ts.meta │ │ ├── Utils.meta │ │ └── Utils │ │ │ ├── DateUtils.ts │ │ │ ├── DateUtils.ts.meta │ │ │ ├── Instance.ts │ │ │ ├── Instance.ts.meta │ │ │ ├── MathUtils.ts │ │ │ ├── MathUtils.ts.meta │ │ │ ├── PathUtil.ts │ │ │ ├── PathUtil.ts.meta │ │ │ ├── Percent.ts │ │ │ ├── Percent.ts.meta │ │ │ ├── RandomUtils.ts │ │ │ ├── RandomUtils.ts.meta │ │ │ ├── StringBuffer.ts │ │ │ ├── StringBuffer.ts.meta │ │ │ ├── StringUtils.ts │ │ │ ├── StringUtils.ts.meta │ │ │ ├── UrlUtil.ts │ │ │ ├── UrlUtil.ts.meta │ │ │ ├── md5.ts │ │ │ └── md5.ts.meta │ ├── Helloworld.ts │ └── Helloworld.ts.meta ├── Texture.meta ├── Texture │ ├── HelloWorld.png │ ├── HelloWorld.png.meta │ ├── singleColor.png │ └── singleColor.png.meta ├── migration.meta └── migration │ ├── use_v2.1-2.2.1_cc.Toggle_event.js │ └── use_v2.1-2.2.1_cc.Toggle_event.js.meta ├── creator.d.ts ├── jsconfig.json ├── project.json ├── settings ├── builder.json ├── builder.panel.json ├── project.json └── services.json ├── template-banner.png ├── template.json └── tsconfig.json /README.md: -------------------------------------------------------------------------------- 1 | # YiyuanCocosFramework 2 | 8年主程手把手打造Cocos独立游戏开发框架系列教程,公众号:亿元程序员,欢迎关注阅读。 3 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/.gitignore: -------------------------------------------------------------------------------- 1 | #///////////////////////////////////////////////////////////////////////////// 2 | # Fireball Projects 3 | #///////////////////////////////////////////////////////////////////////////// 4 | 5 | /library/ 6 | /temp/ 7 | /local/ 8 | /build/ 9 | 10 | #///////////////////////////////////////////////////////////////////////////// 11 | # npm files 12 | #///////////////////////////////////////////////////////////////////////////// 13 | 14 | npm-debug.log 15 | node_modules/ 16 | 17 | #///////////////////////////////////////////////////////////////////////////// 18 | # Logs and databases 19 | #///////////////////////////////////////////////////////////////////////////// 20 | 21 | *.log 22 | *.sql 23 | *.sqlite 24 | 25 | #///////////////////////////////////////////////////////////////////////////// 26 | # files for debugger 27 | #///////////////////////////////////////////////////////////////////////////// 28 | 29 | *.sln 30 | *.pidb 31 | *.suo 32 | 33 | #///////////////////////////////////////////////////////////////////////////// 34 | # OS generated files 35 | #///////////////////////////////////////////////////////////////////////////// 36 | 37 | .DS_Store 38 | ehthumbs.db 39 | Thumbs.db 40 | 41 | #///////////////////////////////////////////////////////////////////////////// 42 | # WebStorm files 43 | #///////////////////////////////////////////////////////////////////////////// 44 | 45 | .idea/ 46 | 47 | #////////////////////////// 48 | # VS Code files 49 | #////////////////////////// 50 | 51 | .vscode/ 52 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/README.md: -------------------------------------------------------------------------------- 1 | # hello-world 2 | Hello world new project template. 3 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Scene.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "29f52784-2fca-467b-92e7-8fd9ef8c57b7", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Scene/helloworld.fire: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "__type__": "cc.SceneAsset", 4 | "_name": "", 5 | "_objFlags": 0, 6 | "_rawFiles": null, 7 | "scene": { 8 | "__id__": 1 9 | } 10 | }, 11 | { 12 | "__type__": "cc.Scene", 13 | "_objFlags": 0, 14 | "_parent": null, 15 | "_children": [ 16 | { 17 | "__id__": 2 18 | } 19 | ], 20 | "_tag": -1, 21 | "_active": true, 22 | "_components": [], 23 | "_prefab": null, 24 | "_id": "2d2f792f-a40c-49bb-a189-ed176a246e49", 25 | "_opacity": 255, 26 | "_color": { 27 | "__type__": "cc.Color", 28 | "r": 255, 29 | "g": 255, 30 | "b": 255, 31 | "a": 255 32 | }, 33 | "_cascadeOpacityEnabled": true, 34 | "_anchorPoint": { 35 | "__type__": "cc.Vec2", 36 | "x": 0, 37 | "y": 0 38 | }, 39 | "_contentSize": { 40 | "__type__": "cc.Size", 41 | "width": 0, 42 | "height": 0 43 | }, 44 | "_localZOrder": 0, 45 | "_globalZOrder": 0, 46 | "_opacityModifyRGB": false, 47 | "groupIndex": 0, 48 | "autoReleaseAssets": null, 49 | "_trs": { 50 | "__type__": "TypedArray", 51 | "ctor": "Float64Array", 52 | "array": [ 53 | 0, 54 | 0, 55 | 0, 56 | 0, 57 | 0, 58 | 0, 59 | 1, 60 | 1, 61 | 1, 62 | 1 63 | ] 64 | } 65 | }, 66 | { 67 | "__type__": "cc.Node", 68 | "_name": "Canvas", 69 | "_objFlags": 0, 70 | "_parent": { 71 | "__id__": 1 72 | }, 73 | "_children": [ 74 | { 75 | "__id__": 3 76 | }, 77 | { 78 | "__id__": 6 79 | }, 80 | { 81 | "__id__": 8 82 | } 83 | ], 84 | "_tag": -1, 85 | "_active": true, 86 | "_components": [ 87 | { 88 | "__id__": 10 89 | }, 90 | { 91 | "__id__": 11 92 | }, 93 | { 94 | "__id__": 12 95 | } 96 | ], 97 | "_prefab": null, 98 | "_id": "a286bbGknJLZpRpxROV6M94", 99 | "_opacity": 255, 100 | "_color": { 101 | "__type__": "cc.Color", 102 | "r": 252, 103 | "g": 252, 104 | "b": 252, 105 | "a": 255 106 | }, 107 | "_cascadeOpacityEnabled": true, 108 | "_anchorPoint": { 109 | "__type__": "cc.Vec2", 110 | "x": 0.5, 111 | "y": 0.5 112 | }, 113 | "_contentSize": { 114 | "__type__": "cc.Size", 115 | "width": 960, 116 | "height": 640 117 | }, 118 | "_skewX": 0, 119 | "_skewY": 0, 120 | "_localZOrder": 0, 121 | "_globalZOrder": 0, 122 | "_opacityModifyRGB": false, 123 | "groupIndex": 0, 124 | "_trs": { 125 | "__type__": "TypedArray", 126 | "ctor": "Float64Array", 127 | "array": [ 128 | 480, 129 | 320, 130 | 0, 131 | 0, 132 | 0, 133 | 0, 134 | 1, 135 | 1, 136 | 1, 137 | 1 138 | ] 139 | } 140 | }, 141 | { 142 | "__type__": "cc.Node", 143 | "_name": "background", 144 | "_objFlags": 0, 145 | "_parent": { 146 | "__id__": 2 147 | }, 148 | "_children": [], 149 | "_tag": -1, 150 | "_active": true, 151 | "_components": [ 152 | { 153 | "__id__": 4 154 | }, 155 | { 156 | "__id__": 5 157 | } 158 | ], 159 | "_prefab": null, 160 | "_id": "e2e0crkOLxGrpMxpbC4iQg1", 161 | "_opacity": 255, 162 | "_color": { 163 | "__type__": "cc.Color", 164 | "r": 27, 165 | "g": 38, 166 | "b": 46, 167 | "a": 255 168 | }, 169 | "_cascadeOpacityEnabled": true, 170 | "_anchorPoint": { 171 | "__type__": "cc.Vec2", 172 | "x": 0.5, 173 | "y": 0.5 174 | }, 175 | "_contentSize": { 176 | "__type__": "cc.Size", 177 | "width": 960, 178 | "height": 640 179 | }, 180 | "_skewX": 0, 181 | "_skewY": 0, 182 | "_localZOrder": 0, 183 | "_globalZOrder": 0, 184 | "_opacityModifyRGB": false, 185 | "groupIndex": 0, 186 | "_trs": { 187 | "__type__": "TypedArray", 188 | "ctor": "Float64Array", 189 | "array": [ 190 | 0, 191 | 0, 192 | 0, 193 | 0, 194 | 0, 195 | 0, 196 | 1, 197 | 1, 198 | 1, 199 | 1 200 | ] 201 | } 202 | }, 203 | { 204 | "__type__": "cc.Widget", 205 | "_name": "", 206 | "_objFlags": 0, 207 | "node": { 208 | "__id__": 3 209 | }, 210 | "_enabled": true, 211 | "isAlignOnce": true, 212 | "_target": null, 213 | "_alignFlags": 45, 214 | "_left": 0, 215 | "_right": 0, 216 | "_top": 0, 217 | "_bottom": 0, 218 | "_verticalCenter": 0, 219 | "_horizontalCenter": 0, 220 | "_isAbsLeft": true, 221 | "_isAbsRight": true, 222 | "_isAbsTop": true, 223 | "_isAbsBottom": true, 224 | "_isAbsHorizontalCenter": true, 225 | "_isAbsVerticalCenter": true, 226 | "_originalWidth": 200, 227 | "_originalHeight": 150 228 | }, 229 | { 230 | "__type__": "cc.Sprite", 231 | "_name": "", 232 | "_objFlags": 0, 233 | "node": { 234 | "__id__": 3 235 | }, 236 | "_enabled": true, 237 | "_spriteFrame": { 238 | "__uuid__": "410fb916-8721-4663-bab8-34397391ace7" 239 | }, 240 | "_type": 1, 241 | "_sizeMode": 0, 242 | "_fillType": 0, 243 | "_fillCenter": { 244 | "__type__": "cc.Vec2", 245 | "x": 0, 246 | "y": 0 247 | }, 248 | "_fillStart": 0, 249 | "_fillRange": 0, 250 | "_isTrimmedMode": true, 251 | "_srcBlendFactor": 770, 252 | "_dstBlendFactor": 771, 253 | "_atlas": null 254 | }, 255 | { 256 | "__type__": "cc.Node", 257 | "_name": "cocos", 258 | "_objFlags": 0, 259 | "_parent": { 260 | "__id__": 2 261 | }, 262 | "_children": [], 263 | "_tag": -1, 264 | "_active": true, 265 | "_components": [ 266 | { 267 | "__id__": 7 268 | } 269 | ], 270 | "_prefab": null, 271 | "_id": "c4f30YOS65G64U2TwufdJ+2", 272 | "_opacity": 255, 273 | "_color": { 274 | "__type__": "cc.Color", 275 | "r": 255, 276 | "g": 255, 277 | "b": 255, 278 | "a": 255 279 | }, 280 | "_cascadeOpacityEnabled": true, 281 | "_anchorPoint": { 282 | "__type__": "cc.Vec2", 283 | "x": 0.5, 284 | "y": 0.5 285 | }, 286 | "_contentSize": { 287 | "__type__": "cc.Size", 288 | "width": 195, 289 | "height": 270 290 | }, 291 | "_skewX": 0, 292 | "_skewY": 0, 293 | "_localZOrder": 0, 294 | "_globalZOrder": 0, 295 | "_opacityModifyRGB": false, 296 | "groupIndex": 0, 297 | "_trs": { 298 | "__type__": "TypedArray", 299 | "ctor": "Float64Array", 300 | "array": [ 301 | 0, 302 | 50, 303 | 0, 304 | 0, 305 | 0, 306 | 0, 307 | 1, 308 | 1, 309 | 1, 310 | 1 311 | ] 312 | } 313 | }, 314 | { 315 | "__type__": "cc.Sprite", 316 | "_name": "", 317 | "_objFlags": 0, 318 | "node": { 319 | "__id__": 6 320 | }, 321 | "_enabled": true, 322 | "_spriteFrame": { 323 | "__uuid__": "31bc895a-c003-4566-a9f3-2e54ae1c17dc" 324 | }, 325 | "_type": 0, 326 | "_sizeMode": 1, 327 | "_fillType": 0, 328 | "_fillCenter": { 329 | "__type__": "cc.Vec2", 330 | "x": 0, 331 | "y": 0 332 | }, 333 | "_fillStart": 0, 334 | "_fillRange": 0, 335 | "_isTrimmedMode": true, 336 | "_srcBlendFactor": 770, 337 | "_dstBlendFactor": 771, 338 | "_atlas": null 339 | }, 340 | { 341 | "__type__": "cc.Node", 342 | "_name": "label", 343 | "_objFlags": 0, 344 | "_parent": { 345 | "__id__": 2 346 | }, 347 | "_children": [], 348 | "_tag": -1, 349 | "_active": true, 350 | "_components": [ 351 | { 352 | "__id__": 9 353 | } 354 | ], 355 | "_prefab": null, 356 | "_id": "31f1bH7V69Ajr1iXhluMpTB", 357 | "_opacity": 255, 358 | "_color": { 359 | "__type__": "cc.Color", 360 | "r": 255, 361 | "g": 255, 362 | "b": 255, 363 | "a": 255 364 | }, 365 | "_cascadeOpacityEnabled": true, 366 | "_anchorPoint": { 367 | "__type__": "cc.Vec2", 368 | "x": 0.5, 369 | "y": 0.5 370 | }, 371 | "_contentSize": { 372 | "__type__": "cc.Size", 373 | "width": 342.33, 374 | "height": 60 375 | }, 376 | "_skewX": 0, 377 | "_skewY": 0, 378 | "_localZOrder": 0, 379 | "_globalZOrder": 0, 380 | "_opacityModifyRGB": false, 381 | "groupIndex": 0, 382 | "_trs": { 383 | "__type__": "TypedArray", 384 | "ctor": "Float64Array", 385 | "array": [ 386 | 0, 387 | -180, 388 | 0, 389 | 0, 390 | 0, 391 | 0, 392 | 1, 393 | 1, 394 | 1, 395 | 1 396 | ] 397 | } 398 | }, 399 | { 400 | "__type__": "cc.Label", 401 | "_name": "", 402 | "_objFlags": 0, 403 | "node": { 404 | "__id__": 8 405 | }, 406 | "_enabled": true, 407 | "_useOriginalSize": false, 408 | "_actualFontSize": 60, 409 | "_fontSize": 60, 410 | "_lineHeight": 60, 411 | "_enableWrapText": true, 412 | "_N$file": null, 413 | "_isSystemFontUsed": true, 414 | "_spacingX": 0, 415 | "_N$string": "Hello, World!", 416 | "_N$horizontalAlign": 1, 417 | "_N$verticalAlign": 1, 418 | "_N$fontFamily": "Arial", 419 | "_N$overflow": 0 420 | }, 421 | { 422 | "__type__": "cc.Canvas", 423 | "_name": "", 424 | "_objFlags": 0, 425 | "node": { 426 | "__id__": 2 427 | }, 428 | "_enabled": true, 429 | "_designResolution": { 430 | "__type__": "cc.Size", 431 | "width": 960, 432 | "height": 640 433 | }, 434 | "_fitWidth": false, 435 | "_fitHeight": true 436 | }, 437 | { 438 | "__type__": "e1b90/rohdEk4SdmmEZANaD", 439 | "_name": "", 440 | "_objFlags": 0, 441 | "node": { 442 | "__id__": 2 443 | }, 444 | "_enabled": true, 445 | "label": { 446 | "__id__": 9 447 | }, 448 | "text": "hello" 449 | }, 450 | { 451 | "__type__": "cc.Widget", 452 | "_name": "", 453 | "_objFlags": 0, 454 | "node": { 455 | "__id__": 2 456 | }, 457 | "_enabled": true, 458 | "alignMode": 1, 459 | "_target": null, 460 | "_alignFlags": 45, 461 | "_left": 0, 462 | "_right": 0, 463 | "_top": 0, 464 | "_bottom": 0, 465 | "_verticalCenter": 0, 466 | "_horizontalCenter": 0, 467 | "_isAbsLeft": true, 468 | "_isAbsRight": true, 469 | "_isAbsTop": true, 470 | "_isAbsBottom": true, 471 | "_isAbsHorizontalCenter": true, 472 | "_isAbsVerticalCenter": true, 473 | "_originalWidth": 0, 474 | "_originalHeight": 0 475 | } 476 | ] -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Scene/helloworld.fire.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.3.2", 3 | "uuid": "2d2f792f-a40c-49bb-a189-ed176a246e49", 4 | "importer": "scene", 5 | "asyncLoadAssets": false, 6 | "autoReleaseAssets": false, 7 | "subMetas": {} 8 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "4734c20c-0db8-4eb2-92ea-e692f4d70934", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "e16419b6-8873-41e0-9302-156115e435ae", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Audio.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "a4a9e7c4-8519-40aa-8a55-bd235b5adb37", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Audio/AudioMgr.ts: -------------------------------------------------------------------------------- 1 | export default class AudioMgr { 2 | 3 | private LocalStorageKey_Bg: string = "bgMusicFlag"; 4 | private LocalStorageKey_Effect: string = "effectMusicFlag"; 5 | 6 | private effectOn: boolean; 7 | private bgOn: boolean; 8 | private currBg: cc.AudioClip; 9 | private bgVolume: number; 10 | private effectVolume: number; 11 | 12 | public constructor() { 13 | this.bgVolume = 0.1; 14 | this.effectVolume = 0.5; 15 | this.setBgVolume(this.bgVolume); 16 | this.setEffectVolume(this.effectVolume); 17 | this.setDefaultSwitchState(); 18 | } 19 | 20 | /** 21 | * 读取背景音乐和音效的设置 22 | */ 23 | private setDefaultSwitchState(): void { 24 | let bgMusicFlag = cc.sys.localStorage.getItem(this.LocalStorageKey_Bg); 25 | if (!bgMusicFlag) { 26 | this.bgOn = true; 27 | } else { 28 | this.bgOn = bgMusicFlag == "1"; 29 | } 30 | 31 | let effectMusicFlag = cc.sys.localStorage.getItem(this.LocalStorageKey_Effect); 32 | if (!effectMusicFlag) { 33 | this.effectOn = true; 34 | } else { 35 | this.effectOn = effectMusicFlag == "1"; 36 | } 37 | } 38 | 39 | /** 40 | * 播放音效 41 | * @param audioClip 42 | */ 43 | public playEffect(audioClip: cc.AudioClip, loops: number = 1): void { 44 | if (!this.effectOn) 45 | return; 46 | 47 | cc.audioEngine.playEffect(audioClip, loops == 1); 48 | } 49 | 50 | /** 51 | * 停止音效播放 52 | * @param audioId 53 | */ 54 | public stopEffect(audioId: number): void { 55 | if (audioId && audioId > 0) { 56 | cc.audioEngine.stopEffect(audioId); 57 | } 58 | } 59 | 60 | /** 61 | * 播放背景音乐 62 | * @param key 63 | */ 64 | public playBg(audioClip: cc.AudioClip): void { 65 | this.currBg = audioClip; 66 | if (!this.bgOn) 67 | return; 68 | cc.audioEngine.playMusic(audioClip, true); 69 | } 70 | 71 | /** 72 | * 停止背景音乐 73 | */ 74 | public stopBg(): void { 75 | cc.audioEngine.stopMusic(); 76 | } 77 | 78 | /** 79 | * 设置音效是否开启 80 | * @param $isOn 81 | */ 82 | public setEffectOn($isOn: boolean): void { 83 | this.effectOn = $isOn; 84 | cc.sys.localStorage.setItem(this.LocalStorageKey_Effect, $isOn ? "1" : "0"); 85 | } 86 | 87 | /** 88 | * 设置背景音乐是否开启 89 | * @param $isOn 90 | */ 91 | public setBgOn($isOn: boolean): void { 92 | this.bgOn = $isOn; 93 | cc.sys.localStorage.setItem(this.LocalStorageKey_Bg, $isOn ? "1" : "0"); 94 | 95 | if (!this.bgOn) { 96 | this.stopBg(); 97 | } else { 98 | if (this.currBg) { 99 | this.playBg(this.currBg); 100 | } 101 | } 102 | } 103 | 104 | /** 105 | * 背景音乐是否已开启 106 | * @returns {boolean} 107 | */ 108 | public get bgIsOn(): boolean { 109 | return this.bgOn; 110 | } 111 | 112 | /** 113 | * 音效是否已开启 114 | * @returns {boolean} 115 | */ 116 | public get effectIsOn(): boolean { 117 | return this.effectOn; 118 | } 119 | 120 | /** 121 | * 设置背景音乐音量 122 | * @param volume 123 | */ 124 | public setBgVolume(volume: number): void { 125 | volume = Math.min(volume, 1); 126 | volume = Math.max(volume, 0); 127 | this.bgVolume = volume; 128 | cc.audioEngine.setMusicVolume(this.bgVolume); 129 | } 130 | 131 | /** 132 | * 获取背景音乐音量 133 | * @returns {number} 134 | */ 135 | public getBgVolume(): number { 136 | return this.bgVolume; 137 | } 138 | 139 | /** 140 | * 设置音效音量 141 | * @param volume 142 | */ 143 | public setEffectVolume(volume: number): void { 144 | volume = Math.min(volume, 1); 145 | volume = Math.max(volume, 0); 146 | this.effectVolume = volume; 147 | cc.audioEngine.setEffectsVolume(this.effectVolume); 148 | } 149 | 150 | /** 151 | * 获取音效音量 152 | * @returns {number} 153 | */ 154 | public getEffectVolume(): number { 155 | return this.effectVolume; 156 | } 157 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Audio/AudioMgr.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "a9190a16-4ab8-491b-9b9b-4a948295ef1f", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Config.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "13be29a4-5731-4c03-b743-034a6a8d875a", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Config/ConfigMgr.ts: -------------------------------------------------------------------------------- 1 | const { ccclass, property } = cc._decorator; 2 | 3 | @ccclass 4 | export default class ConfigMgr extends cc.Component { 5 | @property([cc.JsonAsset]) 6 | configFiles: cc.JsonAsset[] = []; 7 | 8 | private configData: { [key: string]: any } = {}; 9 | 10 | onLoad() { 11 | this.loadConfigData(); 12 | } 13 | 14 | loadConfigData() { 15 | for (const config of this.configFiles) { 16 | const key = config.name; // 使用文件名作为标识符 17 | this.configData[key] = config.json; 18 | cc.log(`Config data loaded for key "${key}":`, this.configData[key]); 19 | 20 | // 检查是否有配置更新,或者其他初始化操作 21 | // this.checkForConfigUpdate(key); 22 | } 23 | } 24 | 25 | getConfig(key: string) { 26 | if (this.configData[key]) { 27 | return this.configData[key]; 28 | } else { 29 | cc.error(`Config key not found: ${key}`); 30 | return null; 31 | } 32 | } 33 | 34 | checkForConfigUpdate(key: string) { 35 | // 检查是否有新的配置数据可用 36 | // 这可以是从服务器下载的最新配置文件 37 | // 如果有新数据,可以触发一个事件或者执行相应的更新逻辑 38 | // 例如,this.updateConfig(key,newConfigData); 39 | } 40 | 41 | // 可以添加其他方法来更新配置数据、重新加载配置等 42 | updateConfig(key: string, newConfigData: any) { 43 | // 更新配置数据的逻辑 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Config/ConfigMgr.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "11be7991-0951-45da-ad97-7333f449adbe", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Event.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "7956815c-4e18-4a1b-8b2b-d94330aa6c71", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Event/EventMgr.ts: -------------------------------------------------------------------------------- 1 | export default class EventMgr extends cc.EventTarget { 2 | 3 | private static _instace: EventMgr = null; 4 | public static GetInstance() { 5 | if (EventMgr._instace == null) { 6 | EventMgr._instace = new EventMgr(); 7 | } 8 | return EventMgr._instace; 9 | } 10 | 11 | /** 12 | * 注册事件目标的特定事件类型回调。这种类型的事件应该被 `emit` 触发。 13 | * @param type 事件类型 14 | * @param callback 回调 15 | * @param target 目标 16 | */ 17 | public static on(type: string, callback: Function, target?: any): void { 18 | this.GetInstance().on(type, callback, target); 19 | } 20 | 21 | /** 22 | * 注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。 23 | * @param type 事件类型 24 | * @param callback 回调 25 | * @param target 目标 26 | */ 27 | public static once(type: string, callback: (arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any) => void, target?: any): void { 28 | this.GetInstance().once(type, callback, target); 29 | } 30 | 31 | /** 32 | * 删除之前用同类型,回调,目标注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。 33 | * @param type 事件类型 34 | * @param callback 回调 35 | * @param target 目标 36 | */ 37 | public static off(type: string, callback?: Function, target?: any): void { 38 | this.GetInstance().off(type, callback, target); 39 | } 40 | 41 | /** 42 | * 在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。 43 | * @param target 目标 44 | */ 45 | public static targetOff(target: Object): void { 46 | this.GetInstance().targetOff(target); 47 | } 48 | 49 | /** 50 | * 通过事件名发送自定义事件 51 | * @param type 事件类型 52 | * @param arg1 参数1 53 | * @param arg2 参数2 54 | * @param arg3 参数3 55 | * @param arg4 参数4 56 | * @param arg5 参数5 57 | */ 58 | public static emit(type: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any): void { 59 | this.GetInstance().emit(type, arg1, arg2, arg3, arg4, arg5); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Event/EventMgr.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "b134ae82-bb56-4850-aac7-743945d8551b", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/HotUpdate.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "b15b1492-f56c-4fbb-9e8d-8da969bfb125", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/HotUpdate/HotUpdateManager.ts: -------------------------------------------------------------------------------- 1 | const { ccclass, property } = cc._decorator; 2 | 3 | @ccclass 4 | export default class HotUpdateManager extends cc.Component { 5 | // 用于存储远程manifest文件的URL的cc.Asset 6 | @property(cc.Asset) 7 | manifestUrl: cc.Asset = null; 8 | 9 | // 存储路径 10 | private storagePath: string; 11 | 12 | // AssetsManager实例 13 | private assetsManager: jsb.AssetsManager; 14 | 15 | onLoad() { 16 | if (!cc.sys.isNative) return; 17 | 18 | // 获取存储路径或使用空字符串作为默认值 19 | this.storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + 'remote-asset'); 20 | 21 | // 创建AssetsManager实例并传入存储路径 22 | this.assetsManager = new jsb.AssetsManager('', this.storagePath); 23 | 24 | // 设置版本比较回调函数 25 | this.assetsManager.setVersionCompareHandle(this.versionCompareHandle.bind(this)); 26 | 27 | if (!this.manifestUrl) { 28 | cc.error('Manifest URL is not set in HotUpdateManager script.'); 29 | return; 30 | } 31 | 32 | // 加载本地manifest文件 33 | this.assetsManager.loadLocalManifest(this.manifestUrl.nativeUrl); 34 | 35 | // 设置AssetsManager事件回调 36 | this.assetsManager.setEventCallback(this.onAssetsManagerEvent); 37 | 38 | // 如果是Android平台,设置最大并发下载任务数 39 | // if (cc.sys.os === cc.sys.OS_ANDROID) { 40 | // this.assetsManager.setMaxConcurrentTask(2); 41 | // } 42 | 43 | // 检查是否需要更新 44 | this.checkForUpdate(); 45 | } 46 | 47 | // 自定义版本比较函数 48 | versionCompareHandle(versionA, versionB) { 49 | // 在这里编写您自己的版本比较逻辑 50 | let vA = versionA.split('.'); 51 | let vB = versionB.split('.'); 52 | for (let i = 0; i < vA.length; ++i) { 53 | let a = parseInt(vA[i]); 54 | let b = parseInt(vB[i] || '0'); 55 | if (a !== b) { 56 | return a - b; 57 | } 58 | } 59 | if (vB.length > vA.length) { 60 | return -1; 61 | } else { 62 | return 0; 63 | } 64 | } 65 | 66 | // 检查是否需要更新 67 | checkForUpdate() { 68 | if (!this.assetsManager.getLocalManifest().isLoaded()) { 69 | cc.error('Failed to load local manifest.'); 70 | return; 71 | } 72 | 73 | // 设置检查资源更新的回调函数 74 | this.assetsManager.setEventCallback(this.onCheckResUpdateCallback.bind(this)); 75 | 76 | // 执行检查更新 77 | this.assetsManager.checkUpdate(); 78 | } 79 | 80 | // 检查资源更新的回调函数 81 | onCheckResUpdateCallback(event) { 82 | switch (event.getEventCode()) { 83 | case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST: 84 | cc.error('No local manifest file found.'); 85 | break; 86 | 87 | case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST: 88 | case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST: 89 | cc.error('Failed to download or parse the remote manifest file.'); 90 | break; 91 | 92 | case jsb.EventAssetsManager.ALREADY_UP_TO_DATE: 93 | cc.log('Already up to date.'); 94 | break; 95 | 96 | case jsb.EventAssetsManager.NEW_VERSION_FOUND: 97 | cc.log('New version found. Need to update.'); 98 | this.assetsManager.setEventCallback(null); 99 | this.updateAssets(); 100 | break; 101 | 102 | default: 103 | break; 104 | } 105 | } 106 | 107 | // 执行资源更新 108 | updateAssets() { 109 | if (this.assetsManager.getState() === jsb.AssetsManager.State.UPDATING) { 110 | cc.log('Already updating. Please wait...'); 111 | return; 112 | } 113 | 114 | // 设置AssetsManager事件回调 115 | this.assetsManager.setEventCallback(this.onAssetsManagerEvent); 116 | 117 | // 执行资源更新 118 | this.assetsManager.update(); 119 | } 120 | 121 | // 处理AssetsManager事件 122 | onAssetsManagerEvent(event) { 123 | switch (event.getEventCode()) { 124 | case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST: 125 | cc.error('No local manifest file found.'); 126 | break; 127 | 128 | case jsb.EventAssetsManager.UPDATE_PROGRESSION: 129 | cc.log(`Update progression: ${event.getPercent()}%`); 130 | // 更新进度处理 131 | break; 132 | 133 | case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST: 134 | case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST: 135 | cc.error('Failed to download or parse the remote manifest file.'); 136 | // 错误处理 137 | break; 138 | 139 | case jsb.EventAssetsManager.ALREADY_UP_TO_DATE: 140 | case jsb.EventAssetsManager.UPDATE_FINISHED: 141 | cc.log('Update finished.'); 142 | // 更新完成处理 143 | break; 144 | 145 | case jsb.EventAssetsManager.UPDATE_FAILED: 146 | cc.error('Update failed. ' + event.getMessage()); 147 | // 更新失败处理 148 | break; 149 | 150 | case jsb.EventAssetsManager.ERROR_UPDATING: 151 | cc.error('Asset update error: ' + event.getAssetId() + ', ' + event.getMessage()); 152 | // 更新中的错误处理 153 | break; 154 | 155 | default: 156 | break; 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/HotUpdate/HotUpdateManager.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "a6c519e7-bd24-460d-b274-4260728ec6fd", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Language.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "c65e50cf-e79c-4e81-9030-ef250447e5db", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Language/LocalizationMgr.ts: -------------------------------------------------------------------------------- 1 | import EventMgr from "../Event/EventMgr"; 2 | 3 | interface LanguageData { 4 | code: string; // 语言代码,如 "en", "fr" 5 | desc: string; // 语言描述 6 | texts: { [key: string]: string }; // 本地化文本 7 | font?: string; // 该语言的字体 8 | audio?: string; // 该语言的语音文件 9 | } 10 | 11 | export const LANGUAGECHANGEDEVENT: string = "LANGUAGECHANGEDEVENT"; 12 | 13 | // LocalizationManager.ts 14 | export default class LocalizationManager { 15 | private static instance: LocalizationManager; 16 | 17 | private currentLanguage: string; 18 | private languages: LanguageData[]; 19 | 20 | private constructor() { 21 | this.languages = []; 22 | this.currentLanguage = "en"; // 默认语言 23 | } 24 | 25 | public static getInstance() { 26 | if (!this.instance) { 27 | this.instance = new LocalizationManager(); 28 | } 29 | return this.instance; 30 | } 31 | 32 | public async init() { 33 | // 加载并解析多语言数据 34 | await this.loadLanguages(); 35 | } 36 | 37 | private async loadLanguages() { 38 | const supportedLanguages = ["en", "zh", "fr", "es", "de", "ja", "ko", "ru", "ar", "pt"]; 39 | const languageDescs = ["英语 (English)", "中文 (Chinese)", "法语 (French)", "西班牙语 (Spanish)", "德语 (German)" 40 | , "日语 (Japanese)", "韩语 (Korean)", "俄语 (Russian)", "阿拉伯语 (Arabic)", "葡萄牙语 (Portuguese)"]; 41 | 42 | try { 43 | const languagePromises = supportedLanguages.map(async (langCode, index) => { 44 | return new Promise((resolve, reject) => { 45 | cc.resources.load(`languages/${langCode}`, cc.JsonAsset, (err, asset) => { 46 | if (err) { 47 | reject(err); 48 | } else { 49 | resolve({ 50 | code: langCode, 51 | desc: languageDescs[index], 52 | texts: asset.json, 53 | font: asset.json.font, 54 | audio: asset.json.audio, 55 | }); 56 | } 57 | }); 58 | }); 59 | }); 60 | 61 | this.languages = await Promise.all(languagePromises); 62 | } catch (error) { 63 | console.error("Failed to load language resources:", error); 64 | } 65 | } 66 | 67 | public setLanguage(languageCode: string) { 68 | const language = this.languages.find((lang) => lang.code === languageCode); 69 | if (language) { 70 | this.currentLanguage = languageCode; 71 | // 切换字体、音频等资源 72 | // 通知UI更新 73 | EventMgr.emit(LANGUAGECHANGEDEVENT); 74 | } else { 75 | console.warn(`Language '${languageCode}' is not supported.`); 76 | } 77 | } 78 | 79 | public getLocalizedString(key: string): string { 80 | const language = this.languages.find((lang) => lang.code === this.currentLanguage); 81 | if (language && language.texts[key]) { 82 | return language.texts[key]; 83 | } else { 84 | console.warn(`Translation for key '${key}' not found in current language.`); 85 | return key; 86 | } 87 | } 88 | 89 | public getCurLanguageDesc(): string { 90 | for (const iterator of this.languages) { 91 | if (iterator.code == this.currentLanguage) { 92 | console.log(iterator.desc); 93 | return iterator.desc; 94 | } 95 | } 96 | return ""; 97 | } 98 | 99 | public getCurLanguages(): LanguageData[] { 100 | return this.languages; 101 | } 102 | 103 | public setLanguageByIndex(index) { 104 | this.setLanguage(this.languages[index].code); 105 | } 106 | 107 | // 可以添加其他功能,如获取当前语言的字体、播放本地化语音等 108 | } 109 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Language/LocalizationMgr.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "d48fb052-e12d-4767-8f87-a50e8777714a", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Log.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "f611c6a0-fa8f-4ea3-a688-d3c78b7a60e5", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Log/Log.ts: -------------------------------------------------------------------------------- 1 | export default class Log { 2 | 3 | private logLevel: number; 4 | 5 | constructor(logLevel: number) { 6 | this.logLevel = logLevel; 7 | } 8 | 9 | public log(message: string, logLevel: number): void { 10 | if (logLevel >= this.logLevel) { 11 | const formattedMessage = this.formatMessage(message, logLevel); 12 | this.emit(formattedMessage); 13 | } 14 | } 15 | 16 | private formatMessage(message: string, logLevel: number): string { 17 | const timestamp = new Date().toLocaleString(); 18 | return `[${timestamp}] [${this.getLogLevelString(logLevel)}] ${message}`; 19 | } 20 | 21 | private getLogLevelString(logLevel: number): string { 22 | switch (logLevel) { 23 | case 1: 24 | return "DEBUG"; 25 | case 2: 26 | return "INFO"; 27 | case 3: 28 | return "WARNING"; 29 | case 4: 30 | return "ERROR"; 31 | default: 32 | return "UNKNOWN"; 33 | } 34 | } 35 | 36 | private emit(formattedMessage: string): void { 37 | cc.log(formattedMessage); 38 | } 39 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Log/Log.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "d2e3e191-bb62-4d94-8dce-b0d6f1d6a8a9", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "f26c2142-64fe-4ce4-9210-08c7d83315cd", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/AStar.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "5b878b25-7bac-49fa-8a65-809fcd6c418f", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/AStar/AstarTest.ts: -------------------------------------------------------------------------------- 1 | import MapGameData from "../MapGameData"; 2 | import SimpleAstar from "./SimpleAstar"; 3 | 4 | export default class AstarTest { 5 | private mapdata: number[][]; 6 | private rootNode: cc.Node; 7 | private graphics: cc.Graphics; 8 | private myPos: cc.Vec2 = cc.Vec2.ZERO; 9 | private simpleAstar: SimpleAstar; 10 | private offsetX: number; 11 | private offsetY: number; 12 | private touchPos: cc.Vec2; 13 | private tgtPos: cc.Vec2; 14 | private pathNodes: any; 15 | private myNode: cc.Node; 16 | public constructor(mapdata: number[][], mapEditorNode: cc.Node) { 17 | this.mapdata = mapdata; 18 | this.rootNode = mapEditorNode.parent; 19 | this.simpleAstar = new SimpleAstar(mapdata); 20 | this.offsetX = mapEditorNode.width / 2; 21 | this.offsetY = mapEditorNode.height / 2; 22 | } 23 | 24 | public init() { 25 | this.myNode = new cc.Node(); 26 | this.rootNode.addChild(this.myNode); 27 | this.myNode.x = this.myPos.x; 28 | this.myNode.y = this.myPos.y; 29 | var graphics = this.myNode.addComponent(cc.Graphics); 30 | this.drawPoint(graphics, 0, 0, 7.5, cc.Color.BLUE); 31 | 32 | var node = new cc.Node(); 33 | this.rootNode.addChild(node); 34 | this.graphics = node.addComponent(cc.Graphics); 35 | var that = this; 36 | this.rootNode.parent.on(cc.Node.EventType.TOUCH_START, function (event) { 37 | this.touchPos = event.getLocation(); 38 | }.bind(this), this); 39 | this.rootNode.parent.on(cc.Node.EventType.TOUCH_END, function (event) { 40 | var W_poss = event.getLocation(); 41 | if (this.touchPos.x != W_poss.x && this.touchPos.y != W_poss.y) { 42 | return; 43 | } 44 | let pos = this.rootNode.parent.convertToNodeSpaceAR(W_poss); 45 | that.tgtPos = new cc.Vec2(-this.rootNode.x + pos.x, -this.rootNode.y + pos.y); 46 | cc.log(that.tgtPos.x, that.tgtPos.y); 47 | var pathNodes = that.simpleAstar.find(this.offsetX + that.myPos.x, this.offsetY - that.myPos.y, 48 | this.offsetX + that.tgtPos.x, this.offsetY - that.tgtPos.y); 49 | if (!pathNodes) { 50 | cc.log("!pathNodes"); 51 | return; 52 | } 53 | that.pathNodes = pathNodes; 54 | that.draw(); 55 | 56 | }.bind(this), this); 57 | } 58 | 59 | private drawPoint(graphics: cc.Graphics, cx: number, cy: number, r: number, fillColor: cc.Color) { 60 | // 设置颜色 61 | graphics.fillColor = fillColor; 62 | // 绘制 63 | graphics.circle(cx, cy, r); 64 | // 确认绘制 65 | graphics.fill(); 66 | } 67 | 68 | private draw() { 69 | this.graphics.clear(); 70 | this.drawPoint(this.graphics, this.tgtPos.x, this.tgtPos.y, 7.5, cc.Color.GREEN); 71 | for (let index = 0; index < this.pathNodes.length; index++) { 72 | const element = this.pathNodes[index]; 73 | var pos = this.getPosByIndex(element); 74 | this.drawPoint( 75 | this.graphics, 76 | pos.x, 77 | pos.y, 78 | 3, 79 | cc.Color.WHITE 80 | ); 81 | } 82 | } 83 | 84 | private getPosByIndex(element) { 85 | return { 86 | x: element.x * MapGameData.GameCellWidth + MapGameData.GameCellWidth / 2 - this.offsetX 87 | , y: - element.y * MapGameData.GameCellHeight - MapGameData.GameCellHeight / 2 + this.offsetY 88 | }; 89 | } 90 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/AStar/AstarTest.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "5a7d4800-f4d6-45d6-81c4-cb4d5e053c8d", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/AStar/SimpleAstar.ts: -------------------------------------------------------------------------------- 1 | import MapGameData from "../MapGameData"; 2 | 3 | export default class SimpleAstar { 4 | 5 | /** 6 | * 寻路方式,8方向和4方向,有效值为8和4 7 | */ 8 | private WorkMode: number = 8; 9 | 10 | private _grid: Grid; 11 | private _path: PathNode[]; 12 | private _astar: AStar; 13 | 14 | /** 15 | * @param mapdata 地图数据 16 | */ 17 | public constructor(mapdata: number[][]) { 18 | this.makeGrid(mapdata); 19 | } 20 | 21 | /** 22 | * @param xnow 当前坐标X(世界坐标) 23 | * @param ynow 当前坐标Y(世界坐标) 24 | * @param xpos 目标点X(世界坐标) 25 | * @param ypos 目标点Y(世界坐标) 26 | */ 27 | public find(xnow: number, ynow: number, xpos: number, ypos: number): PathNode[] { 28 | xpos = Math.floor(xpos / MapGameData.GameCellWidth); 29 | ypos = Math.floor(ypos / MapGameData.GameCellHeight); 30 | xpos = Math.min(xpos, this._grid.numCols - 1); 31 | ypos = Math.min(ypos, this._grid.numRows - 1); 32 | this._grid.setEndNode(xpos, ypos); //1 33 | 34 | xnow = Math.floor(xnow / MapGameData.GameCellWidth); 35 | ynow = Math.floor(ynow / MapGameData.GameCellHeight); 36 | this._grid.setStartNode(xnow, ynow); //2 37 | 38 | // var time: number = egret.getTimer(); 39 | 40 | if (this._astar.findPath()) { //3 41 | // this._astar.floyd(); 42 | // this._path = this._astar.floydPath; 43 | this._path = this._astar.path; 44 | 45 | // time = egret.getTimer() - time; 46 | // console.log("[SilzAstar]", time + "ms length:" + this._astar.path.length); 47 | 48 | return this._path; 49 | } else { 50 | this._grid.setEndNode(xpos - 1, ypos - 1); 51 | // time = egret.getTimer() - time; 52 | // console.log("[SilzAstar]", time + "ms 找不到"); 53 | } 54 | 55 | return null; 56 | } 57 | 58 | private makeGrid(data: number[][]): void { 59 | var rows: number = data.length; 60 | var cols: number = data[0].length; 61 | this._grid = new Grid(cols, rows); 62 | 63 | var px: number; 64 | var py: number; 65 | 66 | for (py = 0; py < rows; py++) { 67 | for (px = 0; px < cols; px++) { 68 | this._grid.setWalkable(px, py, data[py][px] == 1); 69 | } 70 | } 71 | 72 | if (this.WorkMode == 4) 73 | this._grid.calculateLinks(1); 74 | else 75 | this._grid.calculateLinks(); 76 | 77 | this._astar = new AStar(this._grid); 78 | } 79 | } 80 | 81 | export class AStar { 82 | private _open: BinaryHeap; 83 | private _grid: Grid; 84 | private _endNode: PathNode; 85 | private _startNode: PathNode; 86 | private _path: PathNode[]; 87 | private _floydPath: PathNode[]; 88 | private _straightCost: number = 1.0; 89 | private _diagCost: number = Math.SQRT2; 90 | private _nowversion: number = 1; 91 | private _heuristic: Function; 92 | 93 | 94 | public constructor(grid: Grid) { 95 | this._grid = grid; 96 | this._heuristic = this.manhattan; 97 | } 98 | 99 | private justMin(x: any, y: any): boolean { 100 | return x.f < y.f; 101 | } 102 | 103 | public findPath(): boolean { 104 | this._endNode = this._grid.endNode; 105 | this._nowversion++; 106 | this._startNode = this._grid.startNode; 107 | this._open = new BinaryHeap(this.justMin); 108 | this._startNode.g = 0; 109 | return this.search(); 110 | } 111 | 112 | public floyd(): void { 113 | if (this.path == null) 114 | return; 115 | this._floydPath = this.path.concat(); 116 | var len: number = this._floydPath.length; 117 | if (len > 2) { 118 | var vector: PathNode = new PathNode(0, 0); 119 | var tempVector: PathNode = new PathNode(0, 0); 120 | this.floydVector(vector, this._floydPath[len - 1], this._floydPath[len - 2]); 121 | for (var i: number = this._floydPath.length - 3; i >= 0; i--) { 122 | this.floydVector(tempVector, this._floydPath[i + 1], this._floydPath[i]); 123 | if (vector.x == tempVector.x && vector.y == tempVector.y) { 124 | this._floydPath.splice(i + 1, 1); 125 | } else { 126 | vector.x = tempVector.x; 127 | vector.y = tempVector.y; 128 | } 129 | } 130 | } 131 | len = this._floydPath.length; 132 | for (i = len - 1; i >= 0; i--) { 133 | for (var j: number = 0; j <= i - 2; j++) { 134 | if (this.floydCrossAble(this._floydPath[i], this._floydPath[j])) { 135 | for (var k: number = i - 1; k > j; k--) { 136 | this._floydPath.splice(k, 1); 137 | } 138 | i = j; 139 | len = this._floydPath.length; 140 | break; 141 | } 142 | } 143 | } 144 | } 145 | 146 | private floydCrossAble(n1: PathNode, n2: PathNode): boolean { 147 | var ps: cc.Vec2[] = this.bresenhamNodes(new cc.Vec2(n1.x, n1.y), new cc.Vec2(n2.x, n2.y)); 148 | for (var i: number = ps.length - 2; i > 0; i--) { 149 | if (!this._grid.getNode(ps[i].x, ps[i].y).walkable) { 150 | return false; 151 | } 152 | } 153 | return true; 154 | } 155 | 156 | private bresenhamNodes(p1: cc.Vec2, p2: cc.Vec2): cc.Vec2[] { 157 | var steep: boolean = Math.abs(p2.y - p1.y) > Math.abs(p2.x - p1.x); 158 | if (steep) { 159 | var temp: number = p1.x; 160 | p1.x = p1.y; 161 | p1.y = temp; 162 | temp = p2.x; 163 | p2.x = p2.y; 164 | p2.y = temp; 165 | } 166 | var stepX: number = p2.x > p1.x ? 1 : (p2.x < p1.x ? -1 : 0); 167 | var stepY: number = p2.y > p1.y ? 1 : (p2.y < p1.y ? -1 : 0); 168 | var deltay: number = (p2.y - p1.y) / Math.abs(p2.x - p1.x); 169 | var ret: cc.Vec2[] = []; 170 | var nowX: number = p1.x + stepX; 171 | var nowY: number = p1.y + deltay; 172 | if (steep) { 173 | ret.push(new cc.Vec2(p1.y, p1.x)); 174 | } else { 175 | ret.push(new cc.Vec2(p1.x, p1.y)); 176 | } 177 | while (nowX != p2.x) { 178 | var fy: number = Math.floor(nowY) 179 | var cy: number = Math.ceil(nowY); 180 | if (steep) { 181 | ret.push(new cc.Vec2(fy, nowX)); 182 | } else { 183 | ret.push(new cc.Vec2(nowX, fy)); 184 | } 185 | if (fy != cy) { 186 | if (steep) { 187 | ret.push(new cc.Vec2(cy, nowX)); 188 | } else { 189 | ret.push(new cc.Vec2(nowX, cy)); 190 | } 191 | } 192 | nowX += stepX; 193 | nowY += deltay; 194 | } 195 | if (steep) { 196 | ret.push(new cc.Vec2(p2.y, p2.x)); 197 | } else { 198 | ret.push(new cc.Vec2(p2.x, p2.y)); 199 | } 200 | return ret; 201 | } 202 | 203 | private floydVector(target: PathNode, n1: PathNode, n2: PathNode): void { 204 | target.x = n1.x - n2.x; 205 | target.y = n1.y - n2.y; 206 | } 207 | 208 | public search(): boolean { 209 | var node: PathNode = this._startNode; 210 | node.version = this._nowversion; 211 | while (node != this._endNode) { 212 | var len: number = node.links.length; 213 | for (var i: number = 0; i < len; i++) { 214 | var test: PathNode = node.links[i].node; 215 | if (!test.walkable) { 216 | continue; 217 | } 218 | var cost: number = node.links[i].cost; 219 | var g: number = node.g + cost; 220 | var h: number = this._heuristic(test); 221 | var f: number = g + h; 222 | if (test.version == this._nowversion) { 223 | if (test.f > f) { 224 | test.f = f; 225 | test.g = g; 226 | test.h = h; 227 | test.parent = node; 228 | } 229 | } else { 230 | test.f = f; 231 | test.g = g; 232 | test.h = h; 233 | test.parent = node; 234 | this._open.ins(test); 235 | test.version = this._nowversion; 236 | } 237 | 238 | } 239 | if (this._open.a.length == 1) { 240 | return false; 241 | } 242 | node = this._open.pop(); 243 | } 244 | this.buildPath(); 245 | return true; 246 | } 247 | 248 | private buildPath(): void { 249 | this._path = []; 250 | var node: PathNode = this._endNode; 251 | this._path.push(node); 252 | while (node != this._startNode) { 253 | node = node.parent; 254 | this._path.unshift(node); 255 | } 256 | } 257 | 258 | public get path(): PathNode[] { 259 | return this._path; 260 | } 261 | 262 | public get floydPath(): PathNode[] { 263 | return this._floydPath; 264 | } 265 | 266 | public manhattan(node: PathNode): number { 267 | return Math.abs(node.x - this._endNode.x) + Math.abs(node.y - this._endNode.y); 268 | } 269 | 270 | public manhattan2(node: PathNode): number { 271 | var dx: number = Math.abs(node.x - this._endNode.x); 272 | var dy: number = Math.abs(node.y - this._endNode.y); 273 | return dx + dy + Math.abs(dx - dy) / 1000; 274 | } 275 | 276 | public euclidian(node: PathNode): number { 277 | var dx: number = node.x - this._endNode.x; 278 | var dy: number = node.y - this._endNode.y; 279 | return Math.sqrt(dx * dx + dy * dy); 280 | } 281 | 282 | private TwoOneTwoZero: number = 2 * Math.cos(Math.PI / 3); 283 | 284 | public chineseCheckersEuclidian2(node: PathNode): number { 285 | var y: number = node.y / this.TwoOneTwoZero; 286 | var x: number = node.x + node.y / 2; 287 | var dx: number = x - this._endNode.x - this._endNode.y / 2; 288 | var dy: number = y - this._endNode.y / this.TwoOneTwoZero; 289 | return this.sqrt(dx * dx + dy * dy); 290 | } 291 | 292 | private sqrt(x: number): number { 293 | return Math.sqrt(x); 294 | } 295 | 296 | public euclidian2(node: PathNode): number { 297 | var dx: number = node.x - this._endNode.x; 298 | var dy: number = node.y - this._endNode.y; 299 | return dx * dx + dy * dy; 300 | } 301 | 302 | public diagonal(node: PathNode): number { 303 | var dx: number = Math.abs(node.x - this._endNode.x); 304 | var dy: number = Math.abs(node.y - this._endNode.y); 305 | var diag: number = Math.min(dx, dy); 306 | var straight: number = dx + dy; 307 | return this._diagCost * diag + this._straightCost * (straight - 2 * diag); 308 | } 309 | } 310 | 311 | export class BinaryHeap { 312 | public a: any[] = []; 313 | 314 | public justMinFun = function (x: any, y: any): boolean { 315 | return x < y; 316 | }; 317 | 318 | public constructor(justMinFun = null) { 319 | this.a.push(-1); 320 | if (justMinFun != null) { 321 | this.justMinFun = justMinFun; 322 | } 323 | } 324 | 325 | public ins(value: any): void { 326 | var p: number = this.a.length; 327 | this.a[p] = value; 328 | var pp: number = p >> 1; 329 | while (p > 1 && this.justMinFun(this.a[p], this.a[pp])) { 330 | var temp: any = this.a[p]; 331 | this.a[p] = this.a[pp]; 332 | this.a[pp] = temp; 333 | p = pp; 334 | pp = p >> 1; 335 | } 336 | } 337 | 338 | public pop(): any { 339 | var min: any = this.a[1]; 340 | this.a[1] = this.a[this.a.length - 1]; 341 | this.a.pop(); 342 | var p: number = 1; 343 | var l: number = this.a.length; 344 | var sp1: number = p << 1; 345 | var sp2: number = sp1 + 1; 346 | while (sp1 < l) { 347 | if (sp2 < l) { 348 | var minp: number = this.justMinFun(this.a[sp2], this.a[sp1]) ? sp2 : sp1; 349 | } else { 350 | minp = sp1; 351 | } 352 | if (this.justMinFun(this.a[minp], this.a[p])) { 353 | var temp: any = this.a[p]; 354 | this.a[p] = this.a[minp]; 355 | this.a[minp] = temp; 356 | p = minp; 357 | sp1 = p << 1; 358 | sp2 = sp1 + 1; 359 | } else { 360 | break; 361 | } 362 | } 363 | return min; 364 | } 365 | } 366 | 367 | export class Grid { 368 | 369 | private _startNode: PathNode; 370 | private _endNode: PathNode; 371 | private _nodes: PathNode[][]; 372 | private _numCols: number; 373 | private _numRows: number; 374 | 375 | private type: number; 376 | 377 | private _straightCost: number = 1.0; 378 | private _diagCost: number = Math.SQRT2; 379 | 380 | public constructor(numCols: number, numRows: number) { 381 | this._numCols = numCols; 382 | this._numRows = numRows; 383 | this._nodes = []; 384 | 385 | for (var i: number = 0; i < this._numCols; i++) { 386 | this._nodes[i] = []; 387 | for (var j: number = 0; j < this._numRows; j++) { 388 | this._nodes[i][j] = new PathNode(i, j); 389 | } 390 | } 391 | } 392 | 393 | /** 394 | * 395 | * @param type 0八方向 1四方向 2跳棋 396 | */ 397 | public calculateLinks(type: number = 0): void { 398 | this.type = type; 399 | for (var i: number = 0; i < this._numCols; i++) { 400 | for (var j: number = 0; j < this._numRows; j++) { 401 | this.initNodeLink(this._nodes[i][j], type); 402 | } 403 | } 404 | } 405 | 406 | public getType(): number { 407 | return this.type; 408 | } 409 | 410 | /** 411 | * 412 | * @param node 413 | * @param type 0八方向 1四方向 2跳棋 414 | */ 415 | private initNodeLink(node: PathNode, type: number): void { 416 | var startX: number = Math.max(0, node.x - 1); 417 | var endX: number = Math.min(this.numCols - 1, node.x + 1); 418 | var startY: number = Math.max(0, node.y - 1); 419 | var endY: number = Math.min(this.numRows - 1, node.y + 1); 420 | node.links = []; 421 | for (var i: number = startX; i <= endX; i++) { 422 | for (var j: number = startY; j <= endY; j++) { 423 | var test: PathNode = this.getNode(i, j); 424 | if (test == node || !test.walkable) { 425 | continue; 426 | } 427 | if (type != 2 && i != node.x && j != node.y) { 428 | var test2: PathNode = this.getNode(node.x, j); 429 | if (!test2.walkable) { 430 | continue; 431 | } 432 | test2 = this.getNode(i, node.y); 433 | if (!test2.walkable) { 434 | continue; 435 | } 436 | } 437 | var cost: number = this._straightCost; 438 | if (!((node.x == test.x) || (node.y == test.y))) { 439 | if (type == 1) { 440 | continue; 441 | } 442 | if (type == 2 && (node.x - test.x) * (node.y - test.y) == 1) { 443 | continue; 444 | } 445 | if (type == 2) { 446 | cost = this._straightCost; 447 | } else { 448 | cost = this._diagCost; 449 | } 450 | } 451 | node.links.push(new Link(test, cost)); 452 | } 453 | } 454 | } 455 | 456 | public getNode(x: number, y: number): PathNode { 457 | return this._nodes[x][y]; 458 | } 459 | 460 | public setEndNode(x: number, y: number): void { 461 | this._endNode = this._nodes[x][y]; 462 | } 463 | 464 | public setStartNode(x: number, y: number): void { 465 | this._startNode = this._nodes[x][y]; 466 | } 467 | 468 | public setWalkable(x: number, y: number, value: boolean): void { 469 | this._nodes[x][y].walkable = value; 470 | } 471 | 472 | public get endNode(): PathNode { 473 | return this._endNode; 474 | } 475 | 476 | public get numCols(): number { 477 | return this._numCols; 478 | } 479 | 480 | public get numRows(): number { 481 | return this._numRows; 482 | } 483 | 484 | public get startNode(): PathNode { 485 | return this._startNode; 486 | } 487 | 488 | } 489 | 490 | export class Link { 491 | public node: PathNode; 492 | public cost: number; 493 | 494 | public constructor(node: PathNode, cost: number) { 495 | this.node = node; 496 | this.cost = cost; 497 | } 498 | } 499 | 500 | export class PathNode { 501 | public x: number; 502 | public y: number; 503 | public f: number; 504 | public g: number; 505 | public h: number; 506 | public walkable: boolean = true; 507 | public parent: PathNode; 508 | //public costMultiplier:number = 1.0; 509 | public version: number = 1; 510 | public links: Link[]; 511 | 512 | //public index:number; 513 | public constructor(x: number, y: number) { 514 | this.x = x; 515 | this.y = y; 516 | } 517 | 518 | public toString(): String { 519 | return "x:" + this.x + " y:" + this.y; 520 | } 521 | } 522 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/AStar/SimpleAstar.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "9285e294-e331-4b5d-8eec-c7ec8da4cc48", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/Map.ts: -------------------------------------------------------------------------------- 1 | import MapTiles from "./MapTiles"; 2 | 3 | export default class Map { 4 | private tiles: MapTiles; 5 | private node: cc.Node; 6 | private mapData: any; 7 | 8 | constructor(node) { 9 | this.node = node; 10 | } 11 | 12 | public async init(mapId: number) { 13 | var that = this; 14 | await new Promise((complete: Function) => { 15 | cc.resources.load("/map/" + mapId + "/data", function (err, data) { 16 | if (err) { 17 | cc.error(err.message || err); 18 | complete(); 19 | } 20 | var mapData: any = data.json; 21 | that.mapData = mapData; 22 | complete(); 23 | }); 24 | }); 25 | 26 | this.tiles = new MapTiles(this.node); 27 | this.tiles.init(mapId, this.mapData); 28 | this.updateCameraPos(0, 0); 29 | } 30 | 31 | public updateCameraPos($x: number, $y: number): void { 32 | // cc.log($x + "," + $y); 33 | this.tiles.updateCameraPos($x, $y); 34 | } 35 | 36 | public getMapData() { 37 | return this.mapData; 38 | } 39 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/Map.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "d59560ee-4a6a-459e-8979-5841816d0ba9", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/MapEditor.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "89ded10b-9b36-45d9-a29f-c685dd4d8384", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/MapEditor/MapEditor.ts: -------------------------------------------------------------------------------- 1 | import MapGameData from "../MapGameData"; 2 | 3 | export default class MapEditor { 4 | private mouseDown: number; 5 | public async init(mapNode: cc.Node, mapData) { 6 | mapNode.active = false; 7 | var width = MapGameData.GameCellWidth; 8 | var height = MapGameData.GameCellHeight; 9 | var blocks = mapData.blocks; 10 | for (let j = 0; j < blocks.length; j++) { 11 | for (let i = 0; i < blocks[j].length; i++) { 12 | let node = new cc.Node(); 13 | mapNode.addChild(node); 14 | node.x = -mapNode.width / 2 + i * width + width / 2; 15 | node.y = mapNode.height / 2 - j * height - height / 2; 16 | // cc.log(j + "," + i + "," + node.x + "," + node.y); 17 | node.width = width; 18 | node.height = height; 19 | 20 | if (blocks[j][i] == 0) { 21 | this.setBlock(node, true); 22 | } 23 | 24 | node.on(cc.Node.EventType.MOUSE_DOWN, (event: cc.Event.EventMouse) => { 25 | this.mouseDown = event.getButton(); 26 | blocks[j][i] = this.mouseDown == cc.Event.EventMouse.BUTTON_LEFT ? 0 : 1; 27 | this.setBlock(node, blocks[j][i] == 0); 28 | }, this); 29 | 30 | node.on(cc.Node.EventType.MOUSE_UP, (event) => { 31 | this.mouseDown = -1; 32 | }, this); 33 | 34 | node.on(cc.Node.EventType.MOUSE_ENTER, (event) => { 35 | if (this.mouseDown >= 0) { 36 | blocks[j][i] = this.mouseDown == cc.Event.EventMouse.BUTTON_LEFT ? 0 : 1; 37 | this.setBlock(node, blocks[j][i] == 0); 38 | } 39 | }, this); 40 | 41 | node.on(cc.Node.EventType.TOUCH_MOVE, function (event) { 42 | event.stopPropagation(); 43 | }, this); 44 | } 45 | } 46 | cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, function (event) { 47 | if (event.keyCode == cc.macro.KEY.i) { 48 | mapNode.active = !mapNode.active; 49 | } 50 | else if (event.keyCode == cc.macro.KEY.w) { 51 | if (cc.sys.isBrowser) { 52 | let textFileAsBlob = new Blob([JSON.stringify(mapData)], { type: 'application/json' }); 53 | let downloadLink = document.createElement("a"); 54 | downloadLink.download = "data.json"; 55 | downloadLink.innerHTML = "Download File"; 56 | if (window.webkitURL != null) { 57 | downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob); 58 | } 59 | downloadLink.click(); 60 | } 61 | } 62 | }, this); 63 | } 64 | 65 | public setBlock(node: cc.Node, block: boolean) { 66 | let graphics = node.getComponent(cc.Graphics); 67 | if (!graphics) { 68 | graphics = node.addComponent(cc.Graphics); 69 | } 70 | graphics.clear(); 71 | if (block) { 72 | // 设置矩形的颜色 73 | var color = new cc.Color(255, 0, 0, 128); // 使用RGBA颜色表示,最后一个参数是透明度 74 | graphics.fillColor = color; 75 | // 绘制矩形 76 | graphics.fillRect(-node.width / 2, -node.height / 2, node.width - 1, node.height - 1); 77 | // 确认绘制 78 | graphics.fill(); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/MapEditor/MapEditor.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "a919a028-4395-4647-afc5-ba69295489c9", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/MapGameData.ts: -------------------------------------------------------------------------------- 1 | export default class MapGameData { 2 | public static GameTileWidth: number = 256; 3 | public static GameTileHeight: number = 256; 4 | 5 | public static GameCellWidth: number = 32; 6 | public static GameCellHeight: number = 16; 7 | 8 | public static GameAoiWidth: number = 256; 9 | public static GameAoiHeight: number = 256; 10 | 11 | public static WalkSpeed: number = 3; 12 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/MapGameData.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "78c73325-a6d8-4fc8-8fac-14d2828750a4", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/MapTile.ts: -------------------------------------------------------------------------------- 1 | import MapGameData from "./MapGameData"; 2 | 3 | export default class MapTile extends cc.Sprite { 4 | public col: number; 5 | public row: number; 6 | private tileResKey: string; 7 | 8 | public constructor() { 9 | super(); 10 | } 11 | 12 | public init(mapId: number, col: number, row: number) { 13 | this.col = col; 14 | this.row = row; 15 | // 获取屏幕大小 16 | const screenSize = cc.view.getVisibleSize(); 17 | // 获取屏幕宽度 18 | const screenWidth = screenSize.width; 19 | // 获取屏幕高度 20 | const screenHeight = screenSize.height; 21 | this.node.x = this.col * MapGameData.GameTileWidth - screenWidth / 2 + MapGameData.GameTileWidth / 2; 22 | this.node.y = screenHeight / 2 - this.row * MapGameData.GameTileHeight - MapGameData.GameTileHeight / 2; 23 | 24 | var tileResName: string = row + "_" + col; 25 | var tileResPath: string = "/map/" + mapId + "/" + tileResName; 26 | this.tileResKey = tileResPath;//"map_" + mapId + "_" + tileResName; 27 | 28 | var that = this; 29 | //异步加载 30 | cc.resources.load(tileResPath, (error: Error, asset: cc.Asset) => { 31 | if (error) { 32 | cc.log(error.message); 33 | return; 34 | } 35 | that.spriteFrame = new cc.SpriteFrame(asset as cc.Texture2D); 36 | }); 37 | } 38 | 39 | public destory(): void { 40 | cc.resources.release(this.tileResKey); 41 | // App.DisplayUtils.removeFromParent(this); 42 | // RES.destroyRes(this.tileResKey); 43 | // this.texture = null; 44 | } 45 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/MapTile.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "7ae7c75d-cd89-4359-9023-4f3b8087656c", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/MapTiles.ts: -------------------------------------------------------------------------------- 1 | import MapGameData from "./MapGameData"; 2 | import MapTile from "./MapTile"; 3 | 4 | export default class MapTiles { 5 | 6 | private mapId: number; 7 | private tiles: any = []; 8 | private screenTiles: string[] = []; 9 | private cols: number; 10 | private rows: number; 11 | private node: cc.Node; 12 | 13 | constructor(node) { 14 | this.node = node; 15 | } 16 | 17 | public init(mapId: number, mapData: any) { 18 | this.mapId = mapId; 19 | this.cols = Math.floor(mapData.width / MapGameData.GameTileWidth); 20 | this.rows = Math.floor(mapData.height / MapGameData.GameTileHeight); 21 | } 22 | 23 | public updateCameraPos($x: number, $y: number): void { 24 | var currCol: number = Math.round($x / MapGameData.GameTileWidth); 25 | var currRow: number = Math.round($y / MapGameData.GameTileHeight); 26 | 27 | // 获取屏幕大小 28 | const screenSize = cc.view.getVisibleSize(); 29 | // 获取屏幕宽度 30 | const screenWidth = screenSize.width; 31 | // 获取屏幕高度 32 | const screenHeight = screenSize.height; 33 | var screenCols: number = Math.ceil(screenWidth / MapGameData.GameTileWidth) + 1; 34 | var screenRows: number = Math.ceil(screenHeight / MapGameData.GameTileHeight) + 1; 35 | 36 | var halfScreenCols: number = screenCols;//Math.ceil(screenCols / 2); 37 | var halfScreenRows: number = screenRows;//Math.ceil(screenRows / 2); 38 | 39 | var minCol: number = currCol - halfScreenCols; 40 | var maxCol: number = currCol + halfScreenCols; 41 | if (minCol < 0) { 42 | maxCol += -minCol; 43 | minCol = 0; 44 | } 45 | if (maxCol > this.cols) { 46 | minCol -= (maxCol - this.cols); 47 | maxCol = this.cols; 48 | } 49 | var minRow: number = currRow - halfScreenRows; 50 | var maxRow: number = currRow + halfScreenRows; 51 | if (minRow < 0) { 52 | maxRow += -minRow; 53 | minRow = 0; 54 | } 55 | if (maxRow > this.rows) { 56 | minRow -= (maxRow - this.rows); 57 | maxRow = this.rows; 58 | } 59 | 60 | var screenTiles = []; 61 | // cc.log(minCol + "," + maxCol + "," + minRow + "," + maxRow); 62 | for (var i = minCol; i <= maxCol; i++) { 63 | for (var j = minRow; j <= maxRow; j++) { 64 | var tileKey: string = i + "_" + j; 65 | var tile: MapTile = this.tiles[tileKey]; 66 | if (!tile) { 67 | var node = new cc.Node(); 68 | this.node.addChild(node); 69 | tile = node.addComponent(MapTile); 70 | tile.init(this.mapId, i, j); 71 | this.tiles[tileKey] = tile; 72 | } 73 | if (!tile.node.active) { 74 | tile.node.active = true; 75 | } 76 | screenTiles.push(tileKey); 77 | } 78 | } 79 | 80 | //移除不在屏幕内的格子 81 | this.screenTiles.forEach(function (tileKey: string) { 82 | if (screenTiles.indexOf(tileKey) == -1) { 83 | var tile: MapTile = this.tiles[tileKey]; 84 | tile.node.active = false; 85 | } 86 | }.bind(this)); 87 | this.screenTiles = screenTiles; 88 | } 89 | 90 | public destory(): void { 91 | var keys: string[] = Object.keys(this.tiles); 92 | for (var i = 0; i < keys.length; i++) { 93 | var key: string = keys[i]; 94 | var tile: MapTile = this.tiles[key]; 95 | tile.destory(); 96 | 97 | this.tiles[key] = null; 98 | delete this.tiles[key]; 99 | } 100 | 101 | this.screenTiles.splice(0); 102 | } 103 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Map/MapTiles.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "7ee6b602-e795-4335-977e-d732b38f3f6b", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "e7476488-60e7-4045-bed5-cf6ee1d083d2", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Http.ts: -------------------------------------------------------------------------------- 1 | export const enum IHttpMethod { 2 | GET = "get", 3 | POST = "post" 4 | } 5 | 6 | export default class Http { 7 | /** 8 | * 请求 9 | * @param url 链接 10 | * @param param 参数 11 | * @param callback 回调 12 | * @param method 方案 13 | * @param https 是否使用 https协议 14 | */ 15 | public static request(url: string, param: Object, callback: (data: any) => void, method: IHttpMethod = IHttpMethod.GET, https?: boolean): void { 16 | switch (method) { 17 | case IHttpMethod.GET: 18 | this.getRequest(url, param, callback); 19 | break; 20 | case IHttpMethod.POST: 21 | this.postRequest(url, param, callback); 22 | break; 23 | } 24 | } 25 | 26 | /** 27 | * GET 28 | * @param url 链接 29 | * @param param 参数 30 | * @param callback 回调 31 | * @param https 是否使用 https协议 32 | */ 33 | private static getRequest(url: string, param: Object, callback: (data: any) => void, https?: boolean): void { 34 | if (param) { 35 | let s = "?"; 36 | for (let key in param) { 37 | url += `${s}${key}=${param[key]}`; 38 | s = '&'; 39 | } 40 | } 41 | url = this.getUrl(url, https); 42 | cc.log(`http send:${url}`); 43 | let request = new XMLHttpRequest(); 44 | request.open(IHttpMethod.GET, url, true); 45 | this.setRequestHeader(request); 46 | request.onreadystatechange = () => { 47 | if (request.readyState == 4) { 48 | if (request.status >= 200 && request.status < 400) { 49 | callback(request.responseText); 50 | } else { 51 | cc.log(`url:(${url}) request error. status:(${request.status})`); 52 | callback(null); 53 | } 54 | } 55 | }; 56 | request.send(); 57 | } 58 | 59 | /** 60 | * POST 61 | * @param url 链接 62 | * @param param 参数 63 | * @param callback 回调 64 | * @param https 是否使用 https协议 65 | */ 66 | private static postRequest(url: string, param: Object, callback: (data: any) => void, https?: boolean): void { 67 | let paramStr = ""; 68 | if (param) { 69 | let s = ""; 70 | for (let key in param) { 71 | paramStr += `${s}${key}=${param[key]}`; 72 | s = '&'; 73 | } 74 | } 75 | url = this.getUrl(url, https); 76 | cc.log(`http send:${url}`); 77 | let request = new XMLHttpRequest(); 78 | request.open(IHttpMethod.POST, url); 79 | this.setRequestHeader(request); 80 | request.onreadystatechange = () => { 81 | if (request.readyState == 4) { 82 | if (request.status >= 200 && request.status < 400) { 83 | callback(request.responseText); 84 | } else { 85 | cc.log(`${url}请求失败:${request.status}`); 86 | callback(null); 87 | } 88 | } 89 | }; 90 | request.send(paramStr); 91 | } 92 | 93 | /** 94 | * 设置http头 95 | * @param request XMLHttpRequest 96 | */ 97 | private static setRequestHeader(request: XMLHttpRequest): void { 98 | request.setRequestHeader("Content-Type", "text/plain;charset=UTF-8;application/x-www-form-urlencoded;application/json;charset=UTF-8"); 99 | request.setRequestHeader("Cache-Control", "no-store"); 100 | } 101 | 102 | /** 103 | * 获取请求链接 104 | * @param url 链接 105 | * @param https 是否使用 https协议 106 | * @returns {string} 107 | */ 108 | private static getUrl(url: string, https: boolean): string { 109 | if (https) { 110 | if (url.indexOf("https") == -1) { 111 | url = url.replace("http", "https"); 112 | } 113 | } 114 | return url; 115 | } 116 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Http.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "992ccef0-e039-405b-a059-4454b27c485d", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Protocol.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "72836ded-b35a-46d1-8cba-e84898724fbb", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Protocol/NoProtocolManager.ts: -------------------------------------------------------------------------------- 1 | const { ccclass, property } = cc._decorator; 2 | 3 | @ccclass 4 | export default class NoProtocolManager extends cc.Component { 5 | 6 | start() { 7 | // 发送玩家移动协议到服务器 8 | const playerMoveData = { x: 100, y: 200 }; 9 | sendProtocolToServer("playerMove", playerMoveData); 10 | 11 | // 发送敌人攻击协议到服务器 12 | const enemyAttackData = { damage: 20 }; 13 | sendProtocolToServer("enemyAttack", enemyAttackData); 14 | } 15 | } 16 | 17 | // 发送协议到服务器 18 | function sendProtocolToServer(protocol: string, data: any) { 19 | const xhr = new XMLHttpRequest(); 20 | xhr.open("POST", "http://192.168.0.160:82/", true); 21 | xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); 22 | xhr.onreadystatechange = function () { 23 | if (xhr.readyState === 4 && xhr.status === 200) { 24 | // 协议发送成功,接收服务器响应 25 | const response = JSON.parse(xhr.responseText); 26 | handleServerResponse(protocol, response); 27 | } 28 | }; 29 | const requestData = { protocol, data }; 30 | xhr.send(JSON.stringify(requestData)); 31 | } 32 | 33 | // 处理服务器响应 34 | function handleServerResponse(protocol: string, response: any) { 35 | if (protocol === "playerMove") { 36 | // 处理玩家移动协议 37 | console.log(`Received playerMove protocol response: ${JSON.stringify(response)}`); 38 | // 处理协议逻辑 39 | } else if (protocol === "enemyAttack") { 40 | // 处理敌人攻击协议 41 | console.log(`Received enemyAttack protocol response: ${JSON.stringify(response)}`); 42 | // 处理协议逻辑 43 | } 44 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Protocol/NoProtocolManager.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "2f106e7b-fe99-4162-99fe-2c10dc237fc3", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Protocol/ProtocolManager.ts: -------------------------------------------------------------------------------- 1 | // ProtocolManager.ts 2 | 3 | class ProtocolManager { 4 | private static instance: ProtocolManager; 5 | 6 | private constructor() { 7 | // 私有构造函数,确保只有一个实例 8 | } 9 | 10 | public static getInstance(): ProtocolManager { 11 | if (!ProtocolManager.instance) { 12 | ProtocolManager.instance = new ProtocolManager(); 13 | } 14 | return ProtocolManager.instance; 15 | } 16 | 17 | // 添加发送协议的方法 18 | public sendProtocolToServer(protocol: string, data: any) { 19 | const xhr = new XMLHttpRequest(); 20 | xhr.open("POST", "http://192.168.0.160:82/", true); 21 | xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); 22 | xhr.onreadystatechange = function () { 23 | if (xhr.readyState === 4 && xhr.status === 200) { 24 | // 协议发送成功,接收服务器响应 25 | const response = JSON.parse(xhr.responseText); 26 | this.handleServerResponse(protocol, response); 27 | } 28 | }.bind(this); 29 | const requestData = { protocol, data }; 30 | xhr.send(JSON.stringify(requestData)); 31 | } 32 | 33 | // 添加处理服务器响应的方法 34 | private handleServerResponse(protocol: string, response: any) { 35 | if (protocol === "playerMove") { 36 | // 处理玩家移动协议 37 | console.log(`Received playerMove protocol response: ${JSON.stringify(response)}`); 38 | // 处理协议逻辑 39 | } else if (protocol === "enemyAttack") { 40 | // 处理敌人攻击协议 41 | console.log(`Received enemyAttack protocol response: ${JSON.stringify(response)}`); 42 | // 处理协议逻辑 43 | } 44 | } 45 | } 46 | 47 | export default ProtocolManager; 48 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Protocol/ProtocolManager.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "31c4fec8-1367-4569-96cd-f5e8106e140c", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Protocol/ProtocolManager2.ts: -------------------------------------------------------------------------------- 1 | // ProtocolManager2.ts 2 | 3 | type ProtocolHandler = (data: any) => void; 4 | 5 | class ProtocolManager2 { 6 | private static instance: ProtocolManager2; 7 | 8 | private protocolHandlers: Map = new Map(); 9 | 10 | private constructor() { 11 | // 私有构造函数,确保只有一个实例 12 | } 13 | 14 | public static getInstance(): ProtocolManager2 { 15 | if (!ProtocolManager2.instance) { 16 | ProtocolManager2.instance = new ProtocolManager2(); 17 | } 18 | return ProtocolManager2.instance; 19 | } 20 | 21 | // 注册协议处理函数 22 | public registerProtocolHandler(protocol: string, handler: ProtocolHandler) { 23 | this.protocolHandlers.set(protocol, handler); 24 | } 25 | 26 | // 发送协议到服务器 27 | public sendProtocolToServer(protocol: string, data: any) { 28 | const xhr = new XMLHttpRequest(); 29 | xhr.open("POST", "http://192.168.0.160:82/", true); 30 | xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); 31 | xhr.onreadystatechange = () => { 32 | if (xhr.readyState === 4 && xhr.status === 200) { 33 | // 协议发送成功,接收服务器响应 34 | const response = JSON.parse(xhr.responseText); 35 | this.handleServerResponse(protocol, response); 36 | } 37 | }; 38 | const requestData = { protocol, data }; 39 | xhr.send(JSON.stringify(requestData)); 40 | } 41 | 42 | // 处理服务器响应 43 | private handleServerResponse(protocol: string, response: any) { 44 | const handler = this.protocolHandlers.get(protocol); 45 | if (handler) { 46 | // 调用注册的协议处理函数 47 | handler(response); 48 | } 49 | } 50 | } 51 | 52 | export default ProtocolManager2; 53 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Protocol/ProtocolManager2.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "c7544c1a-ce25-4ad3-85ef-1595b39453f2", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Socket.ts: -------------------------------------------------------------------------------- 1 | enum ESocketState { 2 | None = 0, 3 | Connecting = 1, 4 | Connected = 2 5 | } 6 | 7 | export default class Socket { 8 | //webSocket 9 | private socket: WebSocket = null; 10 | //状态 11 | private state: number = ESocketState.None; 12 | //连接已建立回调 13 | public onOpen: () => void = null; 14 | //链接已关闭回调 15 | public onClose: (ev: CloseEvent) => void = null; 16 | //接收到数据回调 17 | public onMessage: (data: string | Uint8Array) => void = null; 18 | //WebSocket错误回调 19 | public onError: (ev: Event) => void = null; 20 | 21 | /** 22 | * 连接 23 | * @param url socket地址 24 | */ 25 | public connect(url: string): void { 26 | if (this.state == ESocketState.None) { 27 | this.state = ESocketState.Connecting; 28 | 29 | cc.log(`socket connect:(${url})`); 30 | this.socket = new WebSocket(url); 31 | this.bindEvent(); 32 | } 33 | } 34 | 35 | /** 36 | * 绑定WebSocket事件 37 | */ 38 | private bindEvent(): void { 39 | this.socket.onopen = () => { 40 | this.state = ESocketState.Connected; 41 | cc.log(`socket onopen`); 42 | this.onOpen && this.onOpen(); 43 | }; 44 | this.socket.onclose = (ev: CloseEvent) => { 45 | cc.log(`socket onclose code:(${ev.code})`); 46 | this.state = ESocketState.None; 47 | this.onClose && this.onClose(ev); 48 | }; 49 | this.socket.onerror = (e: Event) => { 50 | cc.log(`socket onerror`); 51 | this.state = ESocketState.None; 52 | this.onError && this.onError(e); 53 | }; 54 | this.socket.onmessage = (e: MessageEvent) => { 55 | if (this.onMessage) { 56 | console.log("收到消息:" + e.data); 57 | this.onMessage(e.data); 58 | } 59 | }; 60 | } 61 | 62 | /** 63 | * 往WebSocket发送数据 64 | * @param data 65 | * @returns 66 | */ 67 | public send(data: string | ArrayBuffer): void { 68 | if (this.state != ESocketState.Connected) { 69 | cc.log(`socket not connect`); 70 | return; 71 | } 72 | console.log("发送消息:" + data); 73 | this.socket.send(data); 74 | } 75 | 76 | /** 77 | * 关闭WebSocket 78 | */ 79 | public close(): void { 80 | if (this.state != ESocketState.Connected) { 81 | return; 82 | } 83 | cc.log(`socket close`); 84 | this.socket.close(); 85 | } 86 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Net/Socket.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "ba845217-ebae-4367-8e54-7f4d5a14c527", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Pool.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "e716179d-3c90-4dad-8249-a77d2ce055e6", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Pool/ObjectPoolMgr.ts: -------------------------------------------------------------------------------- 1 | const { ccclass } = cc._decorator; 2 | 3 | @ccclass 4 | export default class ObjectPoolMgr extends cc.Component { 5 | private static instance: ObjectPoolMgr = null; 6 | 7 | private objectPools: { [key: string]: cc.NodePool } = {}; 8 | 9 | public static getInstance(): ObjectPoolMgr { 10 | if (this.instance === null) { 11 | this.instance = new ObjectPoolMgr(); 12 | } 13 | return this.instance; 14 | } 15 | 16 | public createObjectPool(poolName: string, prefab: cc.Prefab, initialSize: number, maxSize: number = 100): void { 17 | if (!this.objectPools[poolName]) { 18 | const pool = new cc.NodePool(); 19 | this.objectPools[poolName] = pool; 20 | 21 | for (let i = 0; i < initialSize; i++) { 22 | const node = cc.instantiate(prefab); 23 | pool.put(node); 24 | } 25 | } 26 | } 27 | 28 | public getObject(poolName: string): cc.Node { 29 | const pool = this.objectPools[poolName]; 30 | if (pool && pool.size() > 0) { 31 | const node = pool.get(); 32 | node.active = true; 33 | return node; 34 | } 35 | return null; 36 | } 37 | 38 | public putObject(poolName: string, node: cc.Node): void { 39 | const pool = this.objectPools[poolName]; 40 | if (pool) { 41 | node.active = false; 42 | pool.put(node); 43 | } 44 | } 45 | 46 | public autoExpandPool(poolName: string, prefab: cc.Prefab, incrementSize: number = 10, maxSize: number = 100): void { 47 | const pool = this.objectPools[poolName]; 48 | if (!pool) { 49 | this.createObjectPool(poolName, prefab, incrementSize, maxSize); 50 | } else if (pool.size() < maxSize) { 51 | for (let i = 0; i < incrementSize; i++) { 52 | const node = cc.instantiate(prefab); 53 | pool.put(node); 54 | } 55 | } 56 | } 57 | 58 | public clearPool(poolName: string): void { 59 | const pool = this.objectPools[poolName]; 60 | if (pool) { 61 | pool.clear(); 62 | delete this.objectPools[poolName]; 63 | } 64 | } 65 | 66 | public getAllPoolNames(): string[] { 67 | return Object.keys(this.objectPools); 68 | } 69 | 70 | public getPoolSize(poolName: string): number { 71 | const pool = this.objectPools[poolName]; 72 | if (pool) { 73 | return pool.size(); 74 | } 75 | return 0; 76 | } 77 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Pool/ObjectPoolMgr.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "eab823b0-2750-47ef-95e7-9e94c29f52ba", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Res.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "c28e67d1-9002-41d6-ae9a-1577d63ff4b5", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Res/ResMgr.ts: -------------------------------------------------------------------------------- 1 | type RState = { count: number, complete: boolean, on: Function[] }; 2 | 3 | export default class ResMgr { 4 | 5 | private states: Map = new Map(); 6 | 7 | public loadFile(path: string): Promise { 8 | if (!this.existFile(path)) return null; 9 | return new Promise((complete: Function) => { 10 | let state = this.getState(path, true); 11 | if (state.complete) { 12 | complete(cc.resources.get(path)); 13 | } else { 14 | state.on.push(complete); 15 | if (state.count == 0) { 16 | cc.resources.load(path, (error: Error, asset: cc.Asset) => { 17 | if (error) { 18 | cc.log(error.message); 19 | return; 20 | } 21 | state.complete = true; 22 | if (state.count == 0) { 23 | state.on.forEach((on: Function) => { 24 | on(null); 25 | }); 26 | this._releaseFile(path); 27 | } else { 28 | state.on.forEach((on: Function) => { 29 | on(asset); 30 | }); 31 | state.on = []; 32 | } 33 | }); 34 | } 35 | } 36 | state.count++; 37 | }); 38 | } 39 | 40 | public releaseFile(path: string): void { 41 | let state = this.getState(path); 42 | if (state && state.count > 0) { 43 | if (--state.count == 0 && state.complete) { 44 | this._releaseFile(path); 45 | } 46 | } 47 | } 48 | 49 | private _releaseFile(path: string): void { 50 | let state = this.getState(path); 51 | if (state && state.complete) { 52 | cc.resources.release(path); 53 | this.states.delete(path); 54 | } 55 | } 56 | 57 | private getState(key: string, create?: boolean): RState { 58 | let state = this.states.get(key); 59 | if (create && !state) { 60 | state = { count: 0, complete: false, on: [] }; 61 | this.states.set(key, state); 62 | } 63 | return state; 64 | } 65 | 66 | public existFile(path: string): boolean { 67 | let assetWith = null; 68 | let dirname = this.dirname(path) || ""; 69 | let basename = this.basename(path) || path; 70 | let dirWith = cc.resources.getDirWithPath(dirname); 71 | for (let i = 0; i < dirWith.length; i++) { 72 | if (basename == this.basename(dirWith[i].path)) { 73 | assetWith = dirWith[i]; 74 | break; 75 | } 76 | } 77 | if (!assetWith) { 78 | return false; 79 | } 80 | return true; 81 | } 82 | 83 | public basename(path: string, extname?: string): string { 84 | let index = path.indexOf("?"); 85 | if (index > 0) path = path.substring(0, index); 86 | let reg = /(\/|\\)([^\/\\]+)$/g; 87 | let result = reg.exec(path.replace(/(\/|\\)$/, "")); 88 | if (!result) return path; 89 | let baseName = result[2]; 90 | if (extname && path.substring(path.length - extname.length).toLowerCase() === extname.toLowerCase()) 91 | return baseName.substring(0, baseName.length - extname.length); 92 | return baseName; 93 | } 94 | 95 | public dirname(path: string): string { 96 | var temp = /((.*)(\/|\\|\\\\))?(.*?\..*$)?/.exec(path); 97 | return temp ? temp[2] : ''; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Res/ResMgr.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "1634dc5d-7e72-4be6-9bd7-076ab4120a98", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Scene.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "3a2e79b9-e568-427b-95ab-caca655620c8", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Scene/SceneManager.ts: -------------------------------------------------------------------------------- 1 | const { ccclass, property } = cc._decorator; 2 | 3 | @ccclass 4 | export default class SceneManager extends cc.Component { 5 | @property(cc.Node) 6 | private loadingScreen: cc.Node = null; // 加载界面节点 7 | 8 | private currentScene: string = ""; // 当前场景名称 9 | private isLoading: boolean = false; // 是否正在加载场景 10 | 11 | // 预加载的场景名称列表 12 | @property([cc.String]) 13 | private preloadScenes: string[] = []; 14 | 15 | onLoad() { 16 | cc.game.addPersistRootNode(this.node); 17 | // 注册一个场景加载完成的回调 18 | cc.director.on(cc.Director.EVENT_AFTER_SCENE_LAUNCH, this.onSceneLoaded, this); 19 | 20 | // 预加载所有场景 21 | this.preloadScenes.forEach((sceneName) => { 22 | cc.director.preloadScene(sceneName, () => { 23 | cc.log(`预加载场景: ${sceneName} 完成`); 24 | }); 25 | }); 26 | } 27 | 28 | onDestroy() { 29 | cc.director.off(cc.Director.EVENT_AFTER_SCENE_LAUNCH, this.onSceneLoaded, this); 30 | } 31 | 32 | // 切换到指定场景 33 | public async changeScene(sceneName: string) { 34 | if (this.isLoading) { 35 | cc.warn("正在加载场景,请稍候..."); 36 | return; 37 | } 38 | 39 | if (sceneName === this.currentScene) { 40 | cc.warn(`当前已经在场景 ${sceneName} 中`); 41 | return; 42 | } 43 | 44 | this.isLoading = true; 45 | this.loadingScreen.active = true; 46 | 47 | await this.waitTwoSeconds(); 48 | 49 | // 加载新场景 50 | cc.director.loadScene(sceneName); 51 | } 52 | 53 | async waitTwoSeconds(): Promise { 54 | return new Promise((resolve) => { 55 | setTimeout(() => { 56 | resolve(); 57 | }, 2000); // 2000毫秒等于2秒 58 | }); 59 | } 60 | 61 | // 场景加载完成后的回调 62 | private onSceneLoaded(event: cc.Event.EventCustom) { 63 | this.isLoading = false; 64 | this.loadingScreen.active = false; 65 | 66 | const newSceneName: string = cc.director.getScene().name; 67 | cc.log(`切换到场景: ${newSceneName}`); 68 | 69 | this.currentScene = newSceneName; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Scene/SceneManager.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "dbc45f51-9b29-4b1d-a54a-f258f1c8cdf7", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Sdk.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "48fdd513-1d63-409b-8080-470e6f8c88a2", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Sdk/BaseSdk.ts: -------------------------------------------------------------------------------- 1 | import SdkInterface from "./SdkInterface"; 2 | export default class BaseSdk implements SdkInterface { 3 | /** 4 | * 初始化 5 | * @param callback 初始化成功后回调 6 | * @param target 监听对象 7 | */ 8 | public init(callback: Function, target: Object): void { 9 | cc.log("BaseSdk init"); 10 | } 11 | 12 | /** 13 | * 登录 14 | * @param callback 登录成功后回调 15 | * @param target 监听对象 16 | */ 17 | public login(callback: Function, target: Object): void { 18 | cc.log("BaseSdk login"); 19 | } 20 | 21 | /** 22 | * 登出 23 | */ 24 | public logout(): void { 25 | cc.log("BaseSdk logout"); 26 | } 27 | 28 | /** 29 | * 退出 30 | */ 31 | public exit(): void { 32 | cc.log("BaseSdk exit"); 33 | } 34 | 35 | /** 36 | * 切换账号 37 | */ 38 | public switchLogin(): void { 39 | cc.log("BaseSdk switchLogin"); 40 | } 41 | 42 | /** 43 | * 数据上报 44 | * @param param 参数 45 | */ 46 | public report(...param: any[]): void { 47 | cc.log("BaseSdk report"); 48 | } 49 | 50 | /** 51 | * 数据上报 52 | * @param param 参数 53 | */ 54 | public pay(...param: any[]): void { 55 | cc.log("BaseSdk pay"); 56 | } 57 | 58 | /** 59 | * 播放广告 60 | */ 61 | createRewardAd(): void { 62 | } 63 | /** 64 | * 播放广告 65 | */ 66 | playRewardAd(callback: Function, target: any): void { 67 | callback.call(target, true); 68 | } 69 | /** 70 | * 显示banner广告 71 | */ 72 | showBannerAd(show: boolean): void { 73 | } 74 | /** 75 | * 显示插屏广告 76 | */ 77 | showInterstitialAd(): void { } 78 | /** 79 | * 显示自定义广告 80 | */ 81 | showCustomAd(show, top?, left?): void { } 82 | /** 83 | * 主动拉起转发(小程序) 84 | */ 85 | shareAppMessage(title: string, imageUrlId: string, imageUrl: string, query: any = null, shareCallback: any = null): void { 86 | if (shareCallback) { 87 | shareCallback(); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Sdk/BaseSdk.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "05340832-5482-45da-8530-a516af85e089", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Sdk/SdkInterface.ts: -------------------------------------------------------------------------------- 1 | export default interface SdkInterface { 2 | /** 3 | * 初始化 4 | * @param callback 初始化成功后回调 5 | * @param target 监听对象 6 | */ 7 | init(callback: Function, target: Object): void; 8 | 9 | /** 10 | * 登录 11 | * @param callback 登录成功后回调 12 | * @param target 监听对象 13 | */ 14 | login(callback: Function, target: Object): void; 15 | 16 | /** 17 | * 登出 18 | */ 19 | logout(): void; 20 | 21 | /** 22 | * 退出 23 | */ 24 | exit(): void; 25 | 26 | /** 27 | * 切换账号 28 | */ 29 | switchLogin(): void; 30 | 31 | /** 32 | * 数据上报 33 | * @param param 参数 34 | */ 35 | report(...param: any[]): void; 36 | 37 | /** 38 | * 支付 39 | * @param param 参数 40 | */ 41 | pay(...param: any[]): void; 42 | 43 | /** 44 | * 播放激励视频广告 45 | */ 46 | createRewardAd(): void; 47 | /** 48 | * 播放激励视频广告 49 | */ 50 | playRewardAd(callback: Function, target: any): void; 51 | /** 52 | * 显示banner广告 53 | */ 54 | showBannerAd(show: boolean): void; 55 | /** 56 | * 显示插屏广告 57 | */ 58 | showInterstitialAd(): void; 59 | /** 60 | * 显示自定义广告 61 | */ 62 | showCustomAd(show, top?, left?): void; 63 | /** 64 | * 主动拉起转发(小程序) 65 | */ 66 | shareAppMessage(title: string, imageUrlId: string, imageUrl: string, query: any, shareCallback: any): void; 67 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Sdk/SdkInterface.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "9c06de94-bd69-40ea-b7d4-fbe98556a1bb", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Sdk/SdkMgr.ts: -------------------------------------------------------------------------------- 1 | import BaseSdk from "./BaseSdk"; 2 | import SdkInterface from "./SdkInterface"; 3 | import WxSdk from "./WxSdk"; 4 | 5 | export enum SDK_TYPE { 6 | PC = 0, //PC 7 | WX_DEBUG, //微信测试 8 | } 9 | 10 | export default class SdkMgr { 11 | private sdkObj: SdkInterface = null; 12 | public constructor(sdkType: number) { 13 | switch (sdkType) { 14 | case SDK_TYPE.WX_DEBUG: //微信debug 15 | this.sdkObj = new WxSdk(); 16 | break; 17 | default: //pc 18 | this.sdkObj = new BaseSdk(); 19 | break; 20 | } 21 | } 22 | 23 | /** 24 | * 初始化 25 | * @param callback 初始化成功后回调 26 | * @param target 监听对象 27 | */ 28 | public init(callback: Function, target: Object): void { 29 | console.log("SdkMgr init"); 30 | this.sdkObj.init(callback, target); 31 | } 32 | 33 | /** 34 | * 登录 35 | * @param callback 登录成功后回调 36 | * @param target 监听对象 37 | */ 38 | public login(callback: Function, target: Object): void { 39 | console.log("SdkMgr login"); 40 | this.sdkObj.login(callback, target); 41 | } 42 | 43 | /** 44 | * 登出 45 | */ 46 | public logout(): void { 47 | console.log("SdkMgr logout"); 48 | this.sdkObj.logout(); 49 | } 50 | 51 | /** 52 | * 退出 53 | */ 54 | public exit(): void { 55 | console.log("SdkMgr exit"); 56 | this.sdkObj.exit(); 57 | } 58 | 59 | /** 60 | * 切换账号 61 | */ 62 | public switchLogin(): void { 63 | console.log("SdkMgr switchLogin"); 64 | this.sdkObj.switchLogin(); 65 | } 66 | 67 | /** 68 | * 数据上报 69 | * @param param 参数 70 | */ 71 | public report(...param: any[]): void { 72 | console.log("SdkMgr report"); 73 | this.sdkObj.report(param); 74 | } 75 | 76 | /** 77 | * 数据上报 78 | * @param param 参数 79 | */ 80 | public pay(...param: any[]): void { 81 | console.log("SdkMgr pay"); 82 | this.sdkObj.pay(param); 83 | } 84 | 85 | /** 86 | * 主动拉起转发(小程序) 87 | */ 88 | shareAppMessage(title: string = "", imageUrlId: string = "", imageUrl: string = "", query: any = null, shareCallback: any = null): void { 89 | this.sdkObj.shareAppMessage(title, imageUrlId, imageUrl, query, shareCallback); 90 | } 91 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Sdk/SdkMgr.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "94a0c15d-d209-49c2-91d8-86f5047f39ac", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Sdk/WxSdk.ts: -------------------------------------------------------------------------------- 1 | declare var wx: any; 2 | import SdkInterface from "./SdkInterface"; 3 | export default class WxSdk implements SdkInterface { 4 | 5 | private videoAd: any; 6 | private callback: any; 7 | private target: any; 8 | private bannerAd: any; 9 | private interstitialAd: any; 10 | private customAd: any; 11 | 12 | /** 13 | * 初始化 14 | * @param callback 初始化成功后回调 15 | * @param target 监听对象 16 | */ 17 | public init(callback: Function, target: Object): void { 18 | console.log("WxSdk init"); 19 | //转发 20 | wx.showShareMenu({ 21 | withShareTicket: true, 22 | menus: ["shareAppMessage", "shareTimeline"] 23 | }); 24 | } 25 | 26 | /** 27 | * 登录 28 | * @param callback 登录成功后回调 29 | * @param target 监听对象 30 | */ 31 | public login(callback: Function, target: Object): void { 32 | console.log("WxSdk login"); 33 | } 34 | 35 | /** 36 | * 登出 37 | */ 38 | public logout(): void { 39 | console.log("WxSdk logout"); 40 | } 41 | 42 | /** 43 | * 退出 44 | */ 45 | public exit(): void { 46 | console.log("WxSdk exit"); 47 | } 48 | 49 | /** 50 | * 切换账号 51 | */ 52 | public switchLogin(): void { 53 | console.log("WxSdk switchLogin"); 54 | } 55 | 56 | /** 57 | * 数据上报 58 | * @param param 参数 59 | */ 60 | public report(...param: any[]): void { 61 | console.log("WxSdk report"); 62 | } 63 | 64 | /** 65 | * 数据上报 66 | * @param param 参数 67 | */ 68 | public pay(...param: any[]): void { 69 | console.log("WxSdk pay"); 70 | } 71 | 72 | /** 73 | * 播放广告 74 | */ 75 | playRewardAd(callback: Function, target: any): void { 76 | this.callback = callback; 77 | this.target = target; 78 | this.createRewardAd(); 79 | 80 | // 用户触发广告后,显示激励视频广告 81 | this.videoAd.show().catch(() => { 82 | // 失败重试 83 | this.videoAd.load() 84 | .then(() => this.videoAd.show()) 85 | .catch(err => { 86 | console.log('激励视频 广告显示失败') 87 | this.onRewardAdCallback(false); 88 | }) 89 | }) 90 | } 91 | 92 | createRewardAd() { 93 | if (!this.videoAd) { 94 | this.videoAd = wx.createRewardedVideoAd({ 95 | adUnitId: "adunit-" 96 | }) 97 | 98 | this.videoAd.onClose(res => { 99 | // 用户点击了【关闭广告】按钮 100 | // 小于 2.1.0 的基础库版本,res 是一个 undefined 101 | if (res && res.isEnded || res === undefined) { 102 | // 正常播放结束,可以下发游戏奖励 103 | // callback.call(target, true); 104 | this.onRewardAdCallback(true); 105 | } 106 | else { 107 | // 播放中途退出,不下发游戏奖励 108 | // callback.call(target, false); 109 | this.onRewardAdCallback(false); 110 | } 111 | }) 112 | 113 | this.videoAd.onError(err => { 114 | // callback.call(target, false); 115 | // console.log(err, "1"); 116 | this.onRewardAdCallback(false); 117 | }) 118 | } 119 | } 120 | 121 | onRewardAdCallback(success) { 122 | if (this.callback) { 123 | this.callback.call(this.target, success); 124 | if (success) { 125 | this.videoAd.load(); 126 | } 127 | this.callback = null; 128 | } 129 | } 130 | 131 | /** 132 | * 显示banner广告 133 | */ 134 | showBannerAd(show: boolean): void { 135 | if (show) { 136 | // 在适合的场景显示 Banner 广告 137 | this.createBannerAd(); 138 | this.bannerAd.show(); 139 | } 140 | else { 141 | this.bannerAd.hide(); 142 | this.bannerAd.destroy(); 143 | this.bannerAd = null; 144 | this.createBannerAd(); 145 | } 146 | } 147 | 148 | createBannerAd() { 149 | if (!this.bannerAd) { 150 | let sysInfo = wx.getSystemInfoSync(); 151 | // 创建 Banner 广告实例,提前初始化 152 | var width = 320; 153 | this.bannerAd = wx.createBannerAd({ 154 | adUnitId: 'adunit-', 155 | adIntervals: 30, // 自动刷新频率不能小于30秒 156 | style: { 157 | left: sysInfo.screenWidth / 2 - width / 2, 158 | top: sysInfo.screenHeight, 159 | width: width 160 | } 161 | }) 162 | 163 | this.bannerAd.onResize(res => { 164 | this.bannerAd.style.top = sysInfo.screenHeight - this.bannerAd.style.realHeight; 165 | }) 166 | 167 | this.bannerAd.onError(err => { 168 | console.log(err) 169 | }) 170 | } 171 | } 172 | 173 | createInterstitialAd() { 174 | // 创建插屏广告实例,提前初始化 175 | if (wx.createInterstitialAd && !this.interstitialAd) { 176 | this.interstitialAd = wx.createInterstitialAd({ 177 | adUnitId: 'adunit-' 178 | }) 179 | 180 | this.interstitialAd.onClose(res => { 181 | this.interstitialAd = null; 182 | this.createInterstitialAd(); 183 | }) 184 | } 185 | } 186 | 187 | showInterstitialAd() { 188 | // 在适合的场景显示插屏广告 189 | this.createInterstitialAd(); 190 | if (this.interstitialAd) { 191 | this.interstitialAd.show().catch((err) => { 192 | console.error(err) 193 | }) 194 | } 195 | } 196 | 197 | /** 198 | * 显示自定义广告 199 | */ 200 | showCustomAd(show, top?, left?): void { 201 | // console.log(top, left); 202 | if (!this.customAd) { 203 | this.customAd = wx.createCustomAd({ 204 | adIntervals: 30, 205 | adUnitId: "adunit-", 206 | style: { 207 | fixed: true, 208 | left: left, 209 | top: top, 210 | }, 211 | }) 212 | } 213 | if (show) { 214 | this.customAd.show(); 215 | } 216 | else { 217 | this.customAd.destroy(); 218 | this.customAd = null; 219 | } 220 | } 221 | 222 | /** 223 | * 主动拉起转发 224 | */ 225 | shareAppMessage(title: string = "", imageUrlId: string = "", imageUrl: string = "", query: any = null, shareCallback: any = null): void { 226 | title = title; 227 | imageUrlId = imageUrlId; 228 | imageUrl = imageUrl; 229 | var data = { 230 | title: title, 231 | imageUrlId: imageUrlId, 232 | imageUrl: imageUrl, 233 | query: "" 234 | }; 235 | wx.shareAppMessage(data); 236 | } 237 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Sdk/WxSdk.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "10306498-4488-4507-bd89-a6a01e8f4a80", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Timer.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "6b1c088b-a912-436a-991a-ffb265a8866f", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Timer/TimerMgr.ts: -------------------------------------------------------------------------------- 1 | interface ITimer { 2 | tick: number; 3 | interval: number; 4 | repeat: number; 5 | func: Function; 6 | target: Object; 7 | } 8 | 9 | export default class TimerMgr { 10 | 11 | private timers: ITimer[] = []; 12 | 13 | public add(delay: number, repeat: number, func: Function, target: Object) { 14 | 15 | if (repeat == 0) { 16 | return; 17 | } 18 | 19 | this.remove(func, target); 20 | 21 | this.timers.push({ 22 | tick: 0, 23 | interval: delay, 24 | repeat: repeat, 25 | func: func, 26 | target: target 27 | }); 28 | } 29 | 30 | public remove(func: Function, target: Object) { 31 | for (let index = 0; index < this.timers.length; index++) { 32 | const element = this.timers[index]; 33 | if (element.func == func && element.target == target) { 34 | this.timers.splice(index, 1); 35 | break; 36 | } 37 | } 38 | } 39 | 40 | public init() { 41 | cc.director.on(cc.Director.EVENT_BEFORE_UPDATE, this.update, this); 42 | } 43 | 44 | public update(dt: number) { 45 | for (let index = 0; index < this.timers.length; index++) { 46 | const element = this.timers[index]; 47 | element.tick += dt * 1000; 48 | if (element.tick >= element.interval) { 49 | element.tick -= element.interval; 50 | element.func.call(element.target); 51 | if (element.repeat > 0) { 52 | element.repeat--; 53 | if (element.repeat == 0) { 54 | this.timers.splice(index, 1); 55 | index--; 56 | } 57 | } 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Timer/TimerMgr.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "da302d7d-ab9b-4593-983c-53f778e682fc", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "4d2bafe6-7abd-441f-a48a-b91649ec8e92", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI/Layer.ts: -------------------------------------------------------------------------------- 1 | export default class Layer extends cc.Node { 2 | constructor(name: string) { 3 | super(name); 4 | } 5 | 6 | public addUI(node: cc.Node): void { 7 | if (node.parent) { 8 | node.removeFromParent(false); 9 | } 10 | node.setAnchorPoint(0.5, 0.5); 11 | this.addChild(node); 12 | } 13 | 14 | public removeUI(node: cc.Node): void { 15 | if (node.isChildOf(this)) { 16 | node.removeFromParent(true); 17 | node.destroy(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI/Layer.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "16df0288-1c69-49b7-8ecd-334ab4075f96", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI/Popup.ts: -------------------------------------------------------------------------------- 1 | import View from "./UI"; 2 | 3 | const { ccclass, property } = cc._decorator; 4 | 5 | @ccclass 6 | export default class Popup extends View { 7 | public async _open(...param: any[]): Promise { 8 | await super._open(...param); 9 | } 10 | 11 | public async _close(): Promise { 12 | return new Promise((complete: Function) => { 13 | super._close(); 14 | complete(); 15 | }); 16 | } 17 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI/Popup.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "10c9ec3a-5f5b-4182-8014-69d1ba07632e", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI/ResMgr.ts: -------------------------------------------------------------------------------- 1 | type RState = { count: number, complete: boolean, on: Function[] }; 2 | 3 | export default class ResMgr { 4 | 5 | private static _instance: ResMgr; 6 | public static getInstance() { 7 | if (!this._instance) { 8 | this._instance = new ResMgr(); 9 | } 10 | return this._instance; 11 | } 12 | 13 | private states: Map = new Map(); 14 | 15 | public loadFile(path: string): Promise { 16 | if (!this.existFile(path)) return null; 17 | return new Promise((complete: Function) => { 18 | let state = this.getState(path, true); 19 | if (state.complete) { 20 | complete(cc.resources.get(path)); 21 | } else { 22 | state.on.push(complete); 23 | if (state.count == 0) { 24 | cc.resources.load(path, (error: Error, asset: cc.Asset) => { 25 | if (error) { 26 | cc.log(error.message); 27 | return; 28 | } 29 | state.complete = true; 30 | if (state.count == 0) { 31 | state.on.forEach((on: Function) => { 32 | on(null); 33 | }); 34 | this._releaseFile(path); 35 | } else { 36 | state.on.forEach((on: Function) => { 37 | on(asset); 38 | }); 39 | state.on = []; 40 | } 41 | }); 42 | } 43 | } 44 | state.count++; 45 | }); 46 | } 47 | 48 | public releaseFile(path: string): void { 49 | let state = this.getState(path); 50 | if (state && state.count > 0) { 51 | if (--state.count == 0 && state.complete) { 52 | this._releaseFile(path); 53 | } 54 | } 55 | } 56 | 57 | private _releaseFile(path: string): void { 58 | let state = this.getState(path); 59 | if (state && state.complete) { 60 | cc.resources.release(path); 61 | this.states.delete(path); 62 | } 63 | } 64 | 65 | private getState(key: string, create?: boolean): RState { 66 | let state = this.states.get(key); 67 | if (create && !state) { 68 | state = { count: 0, complete: false, on: [] }; 69 | this.states.set(key, state); 70 | } 71 | return state; 72 | } 73 | 74 | public existFile(path: string): boolean { 75 | let assetWith = null; 76 | let dirname = this.dirname(path) || ""; 77 | let basename = this.basename(path) || path; 78 | let dirWith = cc.resources.getDirWithPath(dirname); 79 | for (let i = 0; i < dirWith.length; i++) { 80 | if (basename == this.basename(dirWith[i].path)) { 81 | assetWith = dirWith[i]; 82 | break; 83 | } 84 | } 85 | if (!assetWith) { 86 | return false; 87 | } 88 | return true; 89 | } 90 | 91 | public basename(path: string, extname?: string): string { 92 | let index = path.indexOf("?"); 93 | if (index > 0) path = path.substring(0, index); 94 | let reg = /(\/|\\)([^\/\\]+)$/g; 95 | let result = reg.exec(path.replace(/(\/|\\)$/, "")); 96 | if (!result) return path; 97 | let baseName = result[2]; 98 | if (extname && path.substring(path.length - extname.length).toLowerCase() === extname.toLowerCase()) 99 | return baseName.substring(0, baseName.length - extname.length); 100 | return baseName; 101 | } 102 | 103 | public dirname(path: string): string { 104 | var temp = /((.*)(\/|\\|\\\\))?(.*?\..*$)?/.exec(path); 105 | return temp ? temp[2] : ''; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI/ResMgr.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "ffe3a1ae-6be0-489d-a64d-c28afa2a58b8", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI/UI.ts: -------------------------------------------------------------------------------- 1 | const { ccclass, property } = cc._decorator; 2 | 3 | @ccclass 4 | export default class UI extends cc.Component { 5 | private visible: boolean = false; 6 | 7 | public async _open(...param: any[]): Promise { 8 | this.node.active = true; 9 | await this.open(...param); 10 | } 11 | 12 | protected async open(...param: any[]): Promise { 13 | 14 | } 15 | 16 | public async _close(): Promise { 17 | this.node.active = false; 18 | this.close(); 19 | } 20 | 21 | protected close(): void { 22 | 23 | } 24 | 25 | public _show(): void { 26 | if (this.visible) return; 27 | this.visible = this.node.active = true; 28 | this.onShow(); 29 | } 30 | 31 | protected onShow(): void { 32 | 33 | } 34 | 35 | public _hide(): void { 36 | if (!this.visible) return; 37 | this.visible = this.node.active = false; 38 | this.onHide(); 39 | } 40 | 41 | protected onHide(): void { 42 | 43 | } 44 | 45 | protected start(): void { 46 | 47 | } 48 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI/UI.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "cf686082-f4ff-4841-aa23-023922e607fd", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI/UIMgr.ts: -------------------------------------------------------------------------------- 1 | import Layer from "./Layer"; 2 | import ResMgr from "./ResMgr"; 3 | import UI from "./UI"; 4 | 5 | interface IPrefabState { 6 | loading: boolean; 7 | node: cc.Node; 8 | on: Function[]; 9 | } 10 | 11 | export default class UIMgr { 12 | 13 | private canvas: cc.Canvas = null; 14 | private rootLayer: Layer = null; 15 | private uiLayer: Layer = null; 16 | private popupLayer: Layer = null; 17 | private tipsLayer: Layer = null; 18 | private prefabState: { [path: string]: IPrefabState } = {}; 19 | 20 | private static _instance: UIMgr; 21 | public static GetInstance() { 22 | if (!this._instance) { 23 | this._instance = new UIMgr(); 24 | this._instance.init(); 25 | } 26 | return this._instance; 27 | } 28 | 29 | public init(): void { 30 | let scene = cc.director.getScene(); 31 | this.canvas = scene.getComponentInChildren(cc.Canvas); 32 | if (!this.canvas) { 33 | return; 34 | } 35 | this.initCanvas(); 36 | this.createLayer(); 37 | } 38 | 39 | private initCanvas(): void { 40 | let size = cc.size(960, 640); 41 | let canvas = this.canvas; 42 | canvas.node.setContentSize(size); 43 | canvas.designResolution = size; 44 | canvas.fitWidth = canvas.fitHeight = true; 45 | } 46 | 47 | private createLayer(): void { 48 | let canvas = this.canvas.node; 49 | this.rootLayer = new Layer("rootLayer"); 50 | canvas.addChild(this.rootLayer); 51 | this.uiLayer = new Layer("uiLayer"); 52 | this.rootLayer.addChild(this.uiLayer); 53 | this.popupLayer = new Layer("popupLayer"); 54 | this.rootLayer.addChild(this.popupLayer); 55 | this.tipsLayer = new Layer("tipsLayer"); 56 | this.rootLayer.addChild(this.tipsLayer); 57 | } 58 | 59 | private openUI(layer: Layer, path: string, ...param: any[]): Promise { 60 | return new Promise(async (complete: Function) => { 61 | if (!this.prefabState[path]) { 62 | this.prefabState[path] = { loading: true, node: null, on: [] }; 63 | let prefab = await ResMgr.getInstance().loadFile(path) as cc.Prefab; 64 | if (!prefab) { 65 | return complete(null); 66 | } 67 | this.prefabState[path].node = cc.instantiate(prefab); 68 | this.prefabState[path].loading = false; 69 | } 70 | 71 | let state = this.prefabState[path]; 72 | if (state) { 73 | state.on.push(complete); 74 | if (!state.loading) { 75 | let node = state.node; 76 | let ui = node.getComponent(UI); 77 | if (!ui) { 78 | } 79 | let time = cc.director.getTotalTime(); 80 | await ui?._open(...param); 81 | if (node.isValid) { 82 | layer.addUI(node); 83 | state.on.forEach((on: Function) => { 84 | on(node); 85 | }); 86 | } else { 87 | state.on.forEach((on: Function) => { 88 | on(null); 89 | }); 90 | } 91 | state.on = []; 92 | } 93 | } 94 | }); 95 | } 96 | 97 | private async closeUI(layer: Layer, path: string): Promise { 98 | let state = this.prefabState[path]; 99 | if (!state) { 100 | return; 101 | } 102 | if (!state.loading) { 103 | let inst = state.node; 104 | await inst.getComponent(UI)?._close(); 105 | layer.removeUI(inst); 106 | } 107 | ResMgr.getInstance().releaseFile(path); 108 | delete this.prefabState[path]; 109 | } 110 | 111 | public async openPage(path: string, ...param: any[]): Promise { 112 | return await this.openUI(this.uiLayer, path, ...param); 113 | } 114 | 115 | public async closePage(path: string): Promise { 116 | await this.closeUI(this.uiLayer, path); 117 | } 118 | 119 | public async openPopup(path: string, ...param: any[]): Promise { 120 | return await this.openUI(this.popupLayer, path, ...param); 121 | } 122 | 123 | public async closePopup(path: string): Promise { 124 | await this.closeUI(this.popupLayer, path); 125 | } 126 | 127 | public async addTips(path: string): Promise { 128 | let node = cc.instantiate(await ResMgr.getInstance().loadFile(path) as cc.Prefab); 129 | this.tipsLayer.addChild(node); 130 | return node; 131 | } 132 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/UI/UIMgr.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "0635a459-af02-452e-a31b-dca611c6ae02", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "c4002a1e-6e48-4350-9ede-3086ecd83c8c", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/DateUtils.ts: -------------------------------------------------------------------------------- 1 | import Instance from "./Instance"; 2 | 3 | class DateUtils { 4 | 5 | public static getInstance(): DateUtils { 6 | return Instance.get(DateUtils); 7 | } 8 | 9 | /** 10 | * 根据秒数格式化字符串 11 | * @param second 秒数 12 | * @param type 1:00:00:00 2:yyyy-mm-dd h:m:s 3:00:00(分:秒) 4:xx天前,xx小时前,xx分钟前 6:00:00(时:分) 13 | * @return 14 | * 15 | */ 16 | public getFormatBySecond(second: number, type: number = 1): string { 17 | var str: string = ""; 18 | switch (type) { 19 | case 1: 20 | str = this.getFormatBySecond1(second); 21 | break; 22 | case 2: 23 | str = this.getFormatBySecond2(second); 24 | break; 25 | case 3: 26 | str = this.getFormatBySecond3(second); 27 | break; 28 | case 4: 29 | str = this.getFormatBySecond4(second); 30 | break; 31 | case 5: 32 | str = this.getFormatBySecond5(second); 33 | break; 34 | case 6: 35 | str = this.getFormatBySecond6(second); 36 | break; 37 | } 38 | return str; 39 | } 40 | 41 | //1: 00:00:00 42 | private getFormatBySecond1(t: number = 0): string { 43 | var hourst: number = Math.floor(t / 3600); 44 | var hours: string; 45 | if (hourst == 0) { 46 | hours = "00"; 47 | } else { 48 | if (hourst < 10) 49 | hours = "0" + hourst; 50 | else 51 | hours = "" + hourst; 52 | } 53 | var minst: number = Math.floor((t - hourst * 3600) / 60); 54 | var secondt: number = Math.floor((t - hourst * 3600) % 60); 55 | var mins: string; 56 | var sens: string; 57 | if (minst == 0) { 58 | mins = "00"; 59 | } else if (minst < 10) { 60 | mins = "0" + minst; 61 | } else { 62 | mins = "" + minst; 63 | } 64 | if (secondt == 0) { 65 | sens = "00"; 66 | } else if (secondt < 10) { 67 | sens = "0" + secondt; 68 | } else { 69 | sens = "" + secondt; 70 | } 71 | return hours + ":" + mins + ":" + sens; 72 | } 73 | 74 | //3:00:00(分:秒) 75 | private getFormatBySecond3(t: number = 0): string { 76 | var hourst: number = Math.floor(t / 3600); 77 | var minst: number = Math.floor((t - hourst * 3600) / 60); 78 | var secondt: number = Math.floor((t - hourst * 3600) % 60); 79 | var mins: string; 80 | var sens: string; 81 | if (minst == 0) { 82 | mins = "00"; 83 | } else if (minst < 10) { 84 | mins = "0" + minst; 85 | } else { 86 | mins = "" + minst; 87 | } 88 | if (secondt == 0) { 89 | sens = "00"; 90 | } else if (secondt < 10) { 91 | sens = "0" + secondt; 92 | } else { 93 | sens = "" + secondt; 94 | } 95 | return mins + ":" + sens; 96 | } 97 | 98 | //2:yyyy-mm-dd h:m:s 99 | private getFormatBySecond2(time: number): string { 100 | var date: Date = new Date(time); 101 | var year: number = date.getFullYear(); 102 | var month: number = date.getMonth() + 1; //返回的月份从0-11; 103 | var day: number = date.getDate(); 104 | var hours: number = date.getHours(); 105 | var minute: number = date.getMinutes(); 106 | var second: number = date.getSeconds(); 107 | return year + "-" + month + "-" + day + " " + hours + ":" + minute + ":" + second; 108 | 109 | } 110 | 111 | //4:xx天前,xx小时前,xx分钟前 112 | private getFormatBySecond4(time: number): string { 113 | var t = Math.floor(time / 3600); 114 | if (t > 0) { 115 | if (t > 24) { 116 | return Math.floor(t / 24) + "天前"; 117 | } 118 | else { 119 | return t + "小时前"; 120 | } 121 | } 122 | else { 123 | return Math.floor(time / 60) + "分钟前"; 124 | } 125 | } 126 | 127 | private getFormatBySecond5(time: number): string { 128 | //每个时间单位所对应的秒数 129 | var oneDay: number = 3600 * 24; 130 | var oneHourst: number = 3600; 131 | var oneMinst: number = 60; 132 | 133 | var days = Math.floor(time / oneDay); 134 | var hourst: number = Math.floor(time % oneDay / oneHourst) 135 | var minst: number = Math.floor((time - hourst * oneHourst) / oneMinst) //Math.floor(time % oneDay % oneHourst / oneMinst); 136 | var secondt: number = Math.floor((time - hourst * oneHourst) % oneMinst) //time; 137 | 138 | var dayss: string = ""; 139 | var hourss: string = "" 140 | var minss: string = ""; 141 | var secss: string = "" 142 | if (time > 0) { 143 | //天 144 | if (days == 0) { 145 | dayss = ""; 146 | //小时 147 | if (hourst == 0) { 148 | hourss = ""; 149 | //分 150 | if (minst == 0) { 151 | minss = ""; 152 | if (secondt == 0) { 153 | secss = ""; 154 | } else if (secondt < 10) { 155 | secss = "0" + secondt + "秒"; 156 | } else { 157 | secss = "" + secondt + "秒"; 158 | } 159 | 160 | return secss; 161 | } 162 | else { 163 | minss = "" + minst + "分"; 164 | if (secondt == 0) { 165 | secss = ""; 166 | } else if (secondt < 10) { 167 | secss = "0" + secondt + "秒"; 168 | } else { 169 | secss = "" + secondt + "秒"; 170 | } 171 | 172 | } 173 | 174 | return minss + secss; 175 | } 176 | else { 177 | hourss = hourst + "小时"; 178 | if (minst == 0) { 179 | minss = ""; 180 | if (secondt == 0) { 181 | secss = ""; 182 | } else if (secondt < 10) { 183 | secss = "0" + secondt + "秒"; 184 | } else { 185 | secss = "" + secondt + "秒"; 186 | } 187 | 188 | return secss 189 | 190 | } else if (minst < 10) { 191 | minss = "0" + minst + "分"; 192 | } else { 193 | minss = "" + minst + "分"; 194 | } 195 | 196 | return hourss + minss; 197 | 198 | } 199 | } 200 | else { 201 | dayss = days + "天"; 202 | if (hourst == 0) { 203 | hourss = ""; 204 | } else { 205 | if (hourst < 10) 206 | hourss = "0" + hourst + "小时"; 207 | else 208 | hourss = "" + hourst + "小时"; 209 | ; 210 | } 211 | return dayss + hourss; 212 | } 213 | } 214 | return ""; 215 | } 216 | 217 | //6:00:00(时:分) 218 | private getFormatBySecond6(t: number = 0): string { 219 | var hourst: number = Math.floor(t / 3600); 220 | var minst: number = Math.floor((t - hourst * 3600) / 60); 221 | var houers: string; 222 | var mins: string; 223 | if (hourst == 0) { 224 | houers = "00"; 225 | } else if (hourst < 10) { 226 | houers = "0" + hourst; 227 | } else { 228 | houers = "" + hourst; 229 | } 230 | if (minst == 0) { 231 | mins = "00"; 232 | } else if (minst < 10) { 233 | mins = "0" + minst; 234 | } else { 235 | mins = "" + minst; 236 | } 237 | return houers + ":" + mins; 238 | } 239 | 240 | 241 | /** 242 | * 获取当前是周几 243 | * ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"] 244 | */ 245 | public getDay(timestamp: number): number { 246 | let date = new Date(timestamp); 247 | return date.getDay(); 248 | } 249 | 250 | /** 251 | * 判定两个时间是否是同一天 252 | */ 253 | public isSameDate(timestamp1: number, timestamp2: number): boolean { 254 | let date1 = new Date(timestamp1); 255 | let date2 = new Date(timestamp2); 256 | return date1.getFullYear() == date2.getFullYear() 257 | && date1.getMonth() == date2.getMonth() 258 | && date1.getDate() == date2.getDate(); 259 | } 260 | 261 | /** 262 | * 日期格式化 263 | */ 264 | public format(d: Date, fmt: string = "yyyy-MM-dd hh:mm:ss"): string { 265 | let o = { 266 | "M+": d.getMonth() + 1, //month 267 | "d+": d.getDate(), //day 268 | "h+": d.getHours(), //hour 269 | "m+": d.getMinutes(), //minute 270 | "s+": d.getSeconds(), //second 271 | "q+": Math.floor((d.getMonth() + 3) / 3), //quarter 272 | "S": d.getMilliseconds() //millisecond 273 | } 274 | if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, 275 | (d.getFullYear() + "").substr(4 - RegExp.$1.length)); 276 | for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) 277 | fmt = fmt.replace(RegExp.$1, 278 | RegExp.$1.length == 1 ? o[k] : 279 | ("00" + o[k]).substr(("" + o[k]).length)); 280 | return fmt; 281 | } 282 | 283 | /** 284 | * 计算两个时间相差天数 285 | */ 286 | public dateDifference(timestamp1: number, timestamp2: number): number { 287 | const d_value: number = Math.abs(timestamp2 - timestamp1); 288 | return Math.ceil(d_value / (24 * 60 * 60 * 1000)); 289 | } 290 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/DateUtils.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "1578f5ff-21d4-4014-8e48-183a0353d6bf", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/Instance.ts: -------------------------------------------------------------------------------- 1 | export type IClazz = new (...param: any[]) => T; 2 | 3 | export default class Instance { 4 | 5 | public static get(clazz: IClazz, ...param: any[]): T { 6 | if (clazz["__Instance__"] == null) { 7 | clazz["__Instance__"] = new clazz(...param); 8 | } 9 | return clazz["__Instance__"]; 10 | } 11 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/Instance.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "81aaedc5-49b9-46b5-80a1-1f73e7a552ad", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/MathUtils.ts: -------------------------------------------------------------------------------- 1 | import Instance from "./Instance"; 2 | 3 | class MathUtils { 4 | 5 | public static getInstance(): MathUtils { 6 | return Instance.get(MathUtils); 7 | } 8 | 9 | /** 10 | * 弧度制转换为角度值 11 | * @param radian 弧度制 12 | * @returns {number} 13 | */ 14 | public getAngle(radian: number): number { 15 | return 180 * radian / Math.PI; 16 | } 17 | 18 | /** 19 | * 角度值转换为弧度制 20 | * @param angle 21 | */ 22 | public getRadian(angle: number): number { 23 | return angle / 180 * Math.PI; 24 | } 25 | 26 | /** 27 | * 获取两点间弧度 28 | * @param p1X 29 | * @param p1Y 30 | * @param p2X 31 | * @param p2Y 32 | * @returns {number} 33 | */ 34 | public getRadian2(p1X: number, p1Y: number, p2X: number, p2Y: number): number { 35 | var xdis: number = p2X - p1X; 36 | var ydis: number = p2Y - p1Y; 37 | return Math.atan2(ydis, xdis); 38 | } 39 | 40 | /** 41 | * 获取两点间距离 42 | * @param p1X 43 | * @param p1Y 44 | * @param p2X 45 | * @param p2Y 46 | * @returns {number} 47 | */ 48 | public getDistance(p1X: number, p1Y: number, p2X: number, p2Y: number): number { 49 | var disX: number = p2X - p1X; 50 | var disY: number = p2Y - p1Y; 51 | var disQ: number = disX * disX + disY * disY; 52 | return Math.sqrt(disQ); 53 | } 54 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/MathUtils.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "2522d218-0a24-4111-b255-82e9600a82b1", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/PathUtil.ts: -------------------------------------------------------------------------------- 1 | 2 | export default class PathUtil { 3 | /** 4 | * 返回 Path 的扩展名 5 | * @param path 路径 6 | * @returns {string} 7 | */ 8 | public static extname(path: string): string { 9 | var temp = /(\.[^\.\/\?\\]*)(\?.*)?$/.exec(path); 10 | return temp ? temp[1] : ''; 11 | } 12 | 13 | /** 14 | * 获取文件路径的文件名。 15 | * @param path 路径 16 | * @param extname 扩展名 17 | * @returns {string} 18 | */ 19 | public static basename(path: string, extname?: string): string { 20 | let index = path.indexOf("?"); 21 | if (index > 0) path = path.substring(0, index); 22 | let reg = /(\/|\\)([^\/\\]+)$/g; 23 | let result = reg.exec(path.replace(/(\/|\\)$/, "")); 24 | if (!result) return path; 25 | let baseName = result[2]; 26 | if (extname && path.substring(path.length - extname.length).toLowerCase() === extname.toLowerCase()) 27 | return baseName.substring(0, baseName.length - extname.length); 28 | return baseName; 29 | } 30 | 31 | /** 32 | * 获取文件路径的目录名 33 | * @param path 路径 34 | * @returns {string} 35 | */ 36 | public static dirname(path: string): string { 37 | var temp = /((.*)(\/|\\|\\\\))?(.*?\..*$)?/.exec(path); 38 | return temp ? temp[2] : ''; 39 | } 40 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/PathUtil.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "78e415e8-a6dd-42dc-bb5f-b08989f685d1", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/Percent.ts: -------------------------------------------------------------------------------- 1 | 2 | class Percent { 3 | public currentValue: number; 4 | public totalValue: number; 5 | 6 | /** 7 | * 构造函数 8 | * @param $currentValue 当前值 9 | * @param $totalValue 总值 10 | */ 11 | public constructor($currentValue: number, $totalValue: number) { 12 | this.currentValue = $currentValue; 13 | this.totalValue = $totalValue; 14 | } 15 | 16 | /** 17 | * 计算当前百分比 18 | * @returns {number} 19 | */ 20 | public computePercent(): number { 21 | return this.currentValue / this.totalValue * 100; 22 | } 23 | 24 | /** 25 | * 计算当前比例 26 | * @returns {number} 27 | */ 28 | public computeRate(): number { 29 | return this.currentValue / this.totalValue; 30 | } 31 | 32 | /** 33 | * 反转 34 | * @returns {Percent} 35 | */ 36 | public reverse(): Percent { 37 | this.currentValue = this.totalValue - this.currentValue; 38 | return this; 39 | } 40 | 41 | /** 42 | * 复制 43 | * @returns {Percent} 44 | */ 45 | public copy(): Percent { 46 | return new Percent(this.currentValue, this.totalValue); 47 | } 48 | 49 | /** 50 | * 计算百分比反转 51 | * @returns {number} 52 | */ 53 | public computePercentReverse(): number { 54 | return (this.totalValue - this.currentValue) / this.totalValue * 100; 55 | } 56 | 57 | /** 58 | * 计算比例反转 59 | * @returns {number} 60 | */ 61 | public computeRateReverse(): number { 62 | return (this.totalValue - this.currentValue) / this.totalValue; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/Percent.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "3b70dc7a-1f8a-406b-b773-b395738a19cc", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/RandomUtils.ts: -------------------------------------------------------------------------------- 1 | import Instance from "./Instance"; 2 | 3 | class RandomUtils { 4 | 5 | public static getInstance(): RandomUtils { 6 | return Instance.get(RandomUtils); 7 | } 8 | /** 9 | * 获取一个区间的随机数 10 | * @param $from 最小值 11 | * @param $end 最大值 12 | * @returns {number} 13 | */ 14 | public limit($from: number, $end: number): number { 15 | $from = Math.min($from, $end); 16 | $end = Math.max($from, $end); 17 | var range: number = $end - $from; 18 | return $from + Math.random() * range; 19 | } 20 | 21 | /** 22 | * 获取一个区间的随机数(整数) 23 | * @param $from 最小值 24 | * @param $end 最大值 25 | * @returns {number} 26 | */ 27 | public limitInteger($from: number, $end: number): number { 28 | return Math.floor(this.limit($from, $end + 1)); 29 | } 30 | 31 | /** 32 | * 在一个数组中随机获取一个元素 33 | * @param arr 数组 34 | * @returns {any} 随机出来的结果 35 | */ 36 | public randomArray(arr: Array): any { 37 | if (!arr) { 38 | return null; 39 | } 40 | var index: number = Math.floor(Math.random() * arr.length); 41 | return arr[index]; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/RandomUtils.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "1e7e3962-2371-45d6-8999-1d50d94816f5", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/StringBuffer.ts: -------------------------------------------------------------------------------- 1 | 2 | class StringBuffer { 3 | private _strings: Array; 4 | 5 | /** 6 | * 构造函数 7 | */ 8 | public constructor() { 9 | this._strings = new Array(); 10 | } 11 | 12 | /** 13 | * 追加一个字符串 14 | * @param str 15 | */ 16 | public append(str: string): void { 17 | this._strings.push(str); 18 | } 19 | 20 | /** 21 | * 转换为字符串 22 | * @returns {string} 23 | */ 24 | public toString(): string { 25 | return this._strings.join(""); 26 | } 27 | 28 | /** 29 | * 清空 30 | */ 31 | public clear(): void { 32 | this._strings.length = 0; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/StringBuffer.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "3acc209b-55e2-4c93-9659-dc188c4988b8", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/StringUtils.ts: -------------------------------------------------------------------------------- 1 | import Instance from "./Instance"; 2 | 3 | class StringUtils { 4 | 5 | public static getInstance(): StringUtils { 6 | return Instance.get(StringUtils); 7 | } 8 | 9 | /** 10 | * 去掉前后空格 11 | * @param str 12 | * @returns {string} 13 | */ 14 | public trimSpace(str: string): string { 15 | return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1'); 16 | } 17 | 18 | /** 19 | * 获取字符串长度,中文为2 20 | * @param str 21 | */ 22 | public getStringLength(str: string): number { 23 | var strArr = str.split(""); 24 | var length = 0; 25 | for (var i = 0; i < strArr.length; i++) { 26 | var s = strArr[i]; 27 | if (this.isChinese(s)) { 28 | length += 2; 29 | } else { 30 | length += 1; 31 | } 32 | } 33 | return length; 34 | } 35 | 36 | /** 37 | * 判断一个字符串是否包含中文 38 | * @param str 39 | * @returns {boolean} 40 | */ 41 | public isChinese(str: string): boolean { 42 | var reg = /^.*[\u4E00-\u9FA5]+.*$/; 43 | return reg.test(str); 44 | } 45 | 46 | /** 47 | * 格式化字符串 "{0},{1}.format("text0","text1") 48 | */ 49 | public format(val: string, ...param: any[]): string { 50 | for (let i = 0, len = param.length; i < len; i++) { 51 | let reg = new RegExp("({)" + i + "(})", "g"); 52 | val = val.replace(reg, param[i]); 53 | } 54 | return val; 55 | } 56 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/StringUtils.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "f7695cba-c019-41ee-9e80-ec23ff6c99d9", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/UrlUtil.ts: -------------------------------------------------------------------------------- 1 | export default class UrlUtil { 2 | /** 3 | * 获取URL参数(字符串) 4 | * @param url 地址 5 | * @returns {string} 6 | */ 7 | private static getParamString(url?: string): string { 8 | url = url || window.location?.href; 9 | if (url != void 0) { 10 | let index = url.indexOf('?'); 11 | if (index != -1) { 12 | return url.substring(index + 1); 13 | } 14 | } 15 | return null; 16 | } 17 | 18 | /** 19 | * 获取URL参数 20 | * @param url 地址 21 | * @returns {JSON} 22 | */ 23 | public static getParam(url?: string): { [key: string]: string } { 24 | let param = {}; 25 | let paramString = this.getParamString(url); 26 | if (paramString) { 27 | paramString.split("&").forEach((value: string) => { 28 | let values = value.split("="); 29 | if (values.length == 2) { 30 | param[values[0]] = values[1]; 31 | } 32 | }); 33 | } 34 | return param; 35 | } 36 | 37 | /** 38 | * 根据key获取URL参数 39 | * @param key key 40 | * @param url 地址 41 | * @returns {string} 42 | */ 43 | public static getParamValue(key: string, url?: string): string { 44 | let paramString = this.getParamString(url); 45 | if (paramString) { 46 | let values = paramString.match(`(^|&)${key}=([^&]*)(&|$)`); 47 | if (values) { 48 | return values[2]; 49 | } 50 | } 51 | return null; 52 | } 53 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/UrlUtil.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "2df65a6b-01c8-4281-845a-71b8a5e16271", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/md5.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message 3 | * Digest Algorithm, as defined in RFC 1321. 4 | * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009 5 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet 6 | * Distributed under the BSD License 7 | * See http://pajhome.org.uk/crypt/md5 for more info. 8 | */ 9 | 10 | /* 11 | * Configurable variables. You may need to tweak these to be compatible with 12 | * the server-side, but the defaults work in most cases. 13 | */ 14 | class md5 { 15 | public constructor() { 16 | 17 | } 18 | 19 | private hexcase = 0; 20 | /* hex output format. 0 - lowercase; 1 - uppercase */ 21 | private b64pad = ""; 22 | /* base-64 pad character. "=" for strict RFC compliance */ 23 | 24 | /* 25 | * These are the privates you'll usually want to call 26 | * They take string arguments and return either hex or base-64 encoded strings 27 | */ 28 | public hex_md5(s) { 29 | return this.rstr2hex(this.rstr_md5(this.str2rstr_utf8(s))); 30 | } 31 | 32 | private b64_md5(s) { 33 | return this.rstr2b64(this.rstr_md5(this.str2rstr_utf8(s))); 34 | } 35 | 36 | private any_md5(s, e) { 37 | return this.rstr2any(this.rstr_md5(this.str2rstr_utf8(s)), e); 38 | } 39 | 40 | private hex_hmac_md5(k, d) { 41 | return this.rstr2hex(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d))); 42 | } 43 | 44 | private b64_hmac_md5(k, d) { 45 | return this.rstr2b64(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d))); 46 | } 47 | 48 | private any_hmac_md5(k, d, e) { 49 | return this.rstr2any(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d)), e); 50 | } 51 | 52 | /* 53 | * Perform a simple self-test to see if the VM is working 54 | */ 55 | private md5_vm_test() { 56 | return this.hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72"; 57 | } 58 | 59 | /* 60 | * Calculate the MD5 of a raw string 61 | */ 62 | private rstr_md5(s) { 63 | return this.binl2rstr(this.binl_md5(this.rstr2binl(s), s.length * 8)); 64 | } 65 | 66 | /* 67 | * Calculate the HMAC-MD5, of a key and some data (raw strings) 68 | */ 69 | private rstr_hmac_md5(key, data) { 70 | var bkey = this.rstr2binl(key); 71 | if (bkey.length > 16) bkey = this.binl_md5(bkey, key.length * 8); 72 | 73 | var ipad = Array(16), opad = Array(16); 74 | for (var i = 0; i < 16; i++) { 75 | ipad[i] = bkey[i] ^ 0x36363636; 76 | opad[i] = bkey[i] ^ 0x5C5C5C5C; 77 | } 78 | 79 | var hash = this.binl_md5(ipad.concat(this.rstr2binl(data)), 512 + data.length * 8); 80 | return this.binl2rstr(this.binl_md5(opad.concat(hash), 512 + 128)); 81 | } 82 | 83 | /* 84 | * Convert a raw string to a hex string 85 | */ 86 | private rstr2hex(input) { 87 | try { 88 | this.hexcase 89 | } catch (e) { 90 | this.hexcase = 0; 91 | } 92 | var hex_tab = this.hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 93 | var output = ""; 94 | var x; 95 | for (var i = 0; i < input.length; i++) { 96 | x = input.charCodeAt(i); 97 | output += hex_tab.charAt((x >>> 4) & 0x0F) 98 | + hex_tab.charAt(x & 0x0F); 99 | } 100 | return output; 101 | } 102 | 103 | /* 104 | * Convert a raw string to a base-64 string 105 | */ 106 | private rstr2b64(input) { 107 | try { 108 | this.b64pad 109 | } catch (e) { 110 | this.b64pad = ''; 111 | } 112 | var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 113 | var output = ""; 114 | var len = input.length; 115 | for (var i = 0; i < len; i += 3) { 116 | var triplet = (input.charCodeAt(i) << 16) 117 | | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) 118 | | (i + 2 < len ? input.charCodeAt(i + 2) : 0); 119 | for (var j = 0; j < 4; j++) { 120 | if (i * 8 + j * 6 > input.length * 8) output += this.b64pad; 121 | else output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F); 122 | } 123 | } 124 | return output; 125 | } 126 | 127 | /* 128 | * Convert a raw string to an arbitrary string encoding 129 | */ 130 | private rstr2any(input, encoding) { 131 | var divisor = encoding.length; 132 | var i, j, q, x, quotient; 133 | 134 | /* Convert to an array of 16-bit big-endian values, forming the dividend */ 135 | var dividend = Array(Math.ceil(input.length / 2)); 136 | for (i = 0; i < dividend.length; i++) { 137 | dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1); 138 | } 139 | 140 | /* 141 | * Repeatedly perform a long division. The binary array forms the dividend, 142 | * the length of the encoding is the divisor. Once computed, the quotient 143 | * forms the dividend for the next step. All remainders are stored for later 144 | * use. 145 | */ 146 | var full_length = Math.ceil(input.length * 8 / 147 | (Math.log(encoding.length) / Math.log(2))); 148 | var remainders = Array(full_length); 149 | for (j = 0; j < full_length; j++) { 150 | quotient = Array(); 151 | x = 0; 152 | for (i = 0; i < dividend.length; i++) { 153 | x = (x << 16) + dividend[i]; 154 | q = Math.floor(x / divisor); 155 | x -= q * divisor; 156 | if (quotient.length > 0 || q > 0) 157 | quotient[quotient.length] = q; 158 | } 159 | remainders[j] = x; 160 | dividend = quotient; 161 | } 162 | 163 | /* Convert the remainders to the output string */ 164 | var output = ""; 165 | for (i = remainders.length - 1; i >= 0; i--) 166 | output += encoding.charAt(remainders[i]); 167 | 168 | return output; 169 | } 170 | 171 | /* 172 | * Encode a string as utf-8. 173 | * For efficiency, this assumes the input is valid utf-16. 174 | */ 175 | private str2rstr_utf8(input) { 176 | var output = ""; 177 | var i = -1; 178 | var x, y; 179 | 180 | while (++i < input.length) { 181 | /* Decode utf-16 surrogate pairs */ 182 | x = input.charCodeAt(i); 183 | y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; 184 | if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) { 185 | x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); 186 | i++; 187 | } 188 | 189 | /* Encode output as utf-8 */ 190 | if (x <= 0x7F) 191 | output += String.fromCharCode(x); 192 | else if (x <= 0x7FF) 193 | output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F), 194 | 0x80 | (x & 0x3F)); 195 | else if (x <= 0xFFFF) 196 | output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), 197 | 0x80 | ((x >>> 6) & 0x3F), 198 | 0x80 | (x & 0x3F)); 199 | else if (x <= 0x1FFFFF) 200 | output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), 201 | 0x80 | ((x >>> 12) & 0x3F), 202 | 0x80 | ((x >>> 6) & 0x3F), 203 | 0x80 | (x & 0x3F)); 204 | } 205 | return output; 206 | } 207 | 208 | /* 209 | * Encode a string as utf-16 210 | */ 211 | private str2rstr_utf16le(input) { 212 | var output = ""; 213 | for (var i = 0; i < input.length; i++) 214 | output += String.fromCharCode(input.charCodeAt(i) & 0xFF, 215 | (input.charCodeAt(i) >>> 8) & 0xFF); 216 | return output; 217 | } 218 | 219 | private str2rstr_utf16be(input) { 220 | var output = ""; 221 | for (var i = 0; i < input.length; i++) 222 | output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, 223 | input.charCodeAt(i) & 0xFF); 224 | return output; 225 | } 226 | 227 | /* 228 | * Convert a raw string to an array of little-endian words 229 | * Characters >255 have their high-byte silently ignored. 230 | */ 231 | private rstr2binl(input) { 232 | var output = Array(input.length >> 2); 233 | for (var i = 0; i < output.length; i++) 234 | output[i] = 0; 235 | for (var i = 0; i < input.length * 8; i += 8) 236 | output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (i % 32); 237 | return output; 238 | } 239 | 240 | /* 241 | * Convert an array of little-endian words to a string 242 | */ 243 | private binl2rstr(input) { 244 | var output = ""; 245 | for (var i = 0; i < input.length * 32; i += 8) 246 | output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF); 247 | return output; 248 | } 249 | 250 | /* 251 | * Calculate the MD5 of an array of little-endian words, and a bit length. 252 | */ 253 | private binl_md5(x, len) { 254 | /* append padding */ 255 | x[len >> 5] |= 0x80 << ((len) % 32); 256 | x[(((len + 64) >>> 9) << 4) + 14] = len; 257 | 258 | var a = 1732584193; 259 | var b = -271733879; 260 | var c = -1732584194; 261 | var d = 271733878; 262 | 263 | for (var i = 0; i < x.length; i += 16) { 264 | var olda = a; 265 | var oldb = b; 266 | var oldc = c; 267 | var oldd = d; 268 | 269 | a = this.md5_ff(a, b, c, d, x[i + 0], 7, -680876936); 270 | d = this.md5_ff(d, a, b, c, x[i + 1], 12, -389564586); 271 | c = this.md5_ff(c, d, a, b, x[i + 2], 17, 606105819); 272 | b = this.md5_ff(b, c, d, a, x[i + 3], 22, -1044525330); 273 | a = this.md5_ff(a, b, c, d, x[i + 4], 7, -176418897); 274 | d = this.md5_ff(d, a, b, c, x[i + 5], 12, 1200080426); 275 | c = this.md5_ff(c, d, a, b, x[i + 6], 17, -1473231341); 276 | b = this.md5_ff(b, c, d, a, x[i + 7], 22, -45705983); 277 | a = this.md5_ff(a, b, c, d, x[i + 8], 7, 1770035416); 278 | d = this.md5_ff(d, a, b, c, x[i + 9], 12, -1958414417); 279 | c = this.md5_ff(c, d, a, b, x[i + 10], 17, -42063); 280 | b = this.md5_ff(b, c, d, a, x[i + 11], 22, -1990404162); 281 | a = this.md5_ff(a, b, c, d, x[i + 12], 7, 1804603682); 282 | d = this.md5_ff(d, a, b, c, x[i + 13], 12, -40341101); 283 | c = this.md5_ff(c, d, a, b, x[i + 14], 17, -1502002290); 284 | b = this.md5_ff(b, c, d, a, x[i + 15], 22, 1236535329); 285 | 286 | a = this.md5_gg(a, b, c, d, x[i + 1], 5, -165796510); 287 | d = this.md5_gg(d, a, b, c, x[i + 6], 9, -1069501632); 288 | c = this.md5_gg(c, d, a, b, x[i + 11], 14, 643717713); 289 | b = this.md5_gg(b, c, d, a, x[i + 0], 20, -373897302); 290 | a = this.md5_gg(a, b, c, d, x[i + 5], 5, -701558691); 291 | d = this.md5_gg(d, a, b, c, x[i + 10], 9, 38016083); 292 | c = this.md5_gg(c, d, a, b, x[i + 15], 14, -660478335); 293 | b = this.md5_gg(b, c, d, a, x[i + 4], 20, -405537848); 294 | a = this.md5_gg(a, b, c, d, x[i + 9], 5, 568446438); 295 | d = this.md5_gg(d, a, b, c, x[i + 14], 9, -1019803690); 296 | c = this.md5_gg(c, d, a, b, x[i + 3], 14, -187363961); 297 | b = this.md5_gg(b, c, d, a, x[i + 8], 20, 1163531501); 298 | a = this.md5_gg(a, b, c, d, x[i + 13], 5, -1444681467); 299 | d = this.md5_gg(d, a, b, c, x[i + 2], 9, -51403784); 300 | c = this.md5_gg(c, d, a, b, x[i + 7], 14, 1735328473); 301 | b = this.md5_gg(b, c, d, a, x[i + 12], 20, -1926607734); 302 | 303 | a = this.md5_hh(a, b, c, d, x[i + 5], 4, -378558); 304 | d = this.md5_hh(d, a, b, c, x[i + 8], 11, -2022574463); 305 | c = this.md5_hh(c, d, a, b, x[i + 11], 16, 1839030562); 306 | b = this.md5_hh(b, c, d, a, x[i + 14], 23, -35309556); 307 | a = this.md5_hh(a, b, c, d, x[i + 1], 4, -1530992060); 308 | d = this.md5_hh(d, a, b, c, x[i + 4], 11, 1272893353); 309 | c = this.md5_hh(c, d, a, b, x[i + 7], 16, -155497632); 310 | b = this.md5_hh(b, c, d, a, x[i + 10], 23, -1094730640); 311 | a = this.md5_hh(a, b, c, d, x[i + 13], 4, 681279174); 312 | d = this.md5_hh(d, a, b, c, x[i + 0], 11, -358537222); 313 | c = this.md5_hh(c, d, a, b, x[i + 3], 16, -722521979); 314 | b = this.md5_hh(b, c, d, a, x[i + 6], 23, 76029189); 315 | a = this.md5_hh(a, b, c, d, x[i + 9], 4, -640364487); 316 | d = this.md5_hh(d, a, b, c, x[i + 12], 11, -421815835); 317 | c = this.md5_hh(c, d, a, b, x[i + 15], 16, 530742520); 318 | b = this.md5_hh(b, c, d, a, x[i + 2], 23, -995338651); 319 | 320 | a = this.md5_ii(a, b, c, d, x[i + 0], 6, -198630844); 321 | d = this.md5_ii(d, a, b, c, x[i + 7], 10, 1126891415); 322 | c = this.md5_ii(c, d, a, b, x[i + 14], 15, -1416354905); 323 | b = this.md5_ii(b, c, d, a, x[i + 5], 21, -57434055); 324 | a = this.md5_ii(a, b, c, d, x[i + 12], 6, 1700485571); 325 | d = this.md5_ii(d, a, b, c, x[i + 3], 10, -1894986606); 326 | c = this.md5_ii(c, d, a, b, x[i + 10], 15, -1051523); 327 | b = this.md5_ii(b, c, d, a, x[i + 1], 21, -2054922799); 328 | a = this.md5_ii(a, b, c, d, x[i + 8], 6, 1873313359); 329 | d = this.md5_ii(d, a, b, c, x[i + 15], 10, -30611744); 330 | c = this.md5_ii(c, d, a, b, x[i + 6], 15, -1560198380); 331 | b = this.md5_ii(b, c, d, a, x[i + 13], 21, 1309151649); 332 | a = this.md5_ii(a, b, c, d, x[i + 4], 6, -145523070); 333 | d = this.md5_ii(d, a, b, c, x[i + 11], 10, -1120210379); 334 | c = this.md5_ii(c, d, a, b, x[i + 2], 15, 718787259); 335 | b = this.md5_ii(b, c, d, a, x[i + 9], 21, -343485551); 336 | 337 | a = this.safe_add(a, olda); 338 | b = this.safe_add(b, oldb); 339 | c = this.safe_add(c, oldc); 340 | d = this.safe_add(d, oldd); 341 | } 342 | return [a, b, c, d]; 343 | } 344 | 345 | /* 346 | * These privates implement the four basic operations the algorithm uses. 347 | */ 348 | private md5_cmn(q, a, b, x, s, t) { 349 | return this.safe_add(this.bit_rol(this.safe_add(this.safe_add(a, q), this.safe_add(x, t)), s), b); 350 | } 351 | 352 | private md5_ff(a, b, c, d, x, s, t) { 353 | return this.md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); 354 | } 355 | 356 | private md5_gg(a, b, c, d, x, s, t) { 357 | return this.md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); 358 | } 359 | 360 | private md5_hh(a, b, c, d, x, s, t) { 361 | return this.md5_cmn(b ^ c ^ d, a, b, x, s, t); 362 | } 363 | 364 | private md5_ii(a, b, c, d, x, s, t) { 365 | return this.md5_cmn(c ^ (b | (~d)), a, b, x, s, t); 366 | } 367 | 368 | /* 369 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally 370 | * to work around bugs in some JS interpreters. 371 | */ 372 | private safe_add(x, y) { 373 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); 374 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); 375 | return (msw << 16) | (lsw & 0xFFFF); 376 | } 377 | 378 | /* 379 | * Bitwise rotate a 32-bit number to the left. 380 | */ 381 | private bit_rol(num, cnt) { 382 | return (num << cnt) | (num >>> (32 - cnt)); 383 | } 384 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Core/Utils/md5.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "d1ff8156-e5a2-4bbf-9752-4f0b7031778a", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Helloworld.ts: -------------------------------------------------------------------------------- 1 | const {ccclass, property} = cc._decorator; 2 | 3 | @ccclass 4 | export default class Helloworld extends cc.Component { 5 | 6 | @property(cc.Label) 7 | label: cc.Label = null; 8 | 9 | @property 10 | text: string = 'hello'; 11 | 12 | start () { 13 | // init logic 14 | this.label.string = this.text; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Script/Helloworld.ts.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "e1b90feb-a217-4493-849d-9a611900d683", 4 | "importer": "typescript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Texture.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "7b81d4e8-ec84-4716-968d-500ac1d78a54", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Texture/HelloWorld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lswgit/YiyuanCocosFramework/baf0e2f46f9bc2b88b1397901d14f137563bdfcf/YiyuanCocosFramework/assets/Texture/HelloWorld.png -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Texture/HelloWorld.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "2.3.7", 3 | "uuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4", 4 | "importer": "texture", 5 | "type": "sprite", 6 | "wrapMode": "clamp", 7 | "filterMode": "bilinear", 8 | "premultiplyAlpha": false, 9 | "genMipmaps": false, 10 | "packable": true, 11 | "width": 256, 12 | "height": 256, 13 | "platformSettings": {}, 14 | "subMetas": { 15 | "HelloWorld": { 16 | "ver": "1.0.6", 17 | "uuid": "31bc895a-c003-4566-a9f3-2e54ae1c17dc", 18 | "importer": "sprite-frame", 19 | "rawTextureUuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4", 20 | "trimType": "auto", 21 | "trimThreshold": 1, 22 | "rotated": false, 23 | "offsetX": 3.5, 24 | "offsetY": 1, 25 | "trimX": 44, 26 | "trimY": 14, 27 | "width": 175, 28 | "height": 226, 29 | "rawWidth": 256, 30 | "rawHeight": 256, 31 | "borderTop": 0, 32 | "borderBottom": 0, 33 | "borderLeft": 0, 34 | "borderRight": 0, 35 | "subMetas": {} 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Texture/singleColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lswgit/YiyuanCocosFramework/baf0e2f46f9bc2b88b1397901d14f137563bdfcf/YiyuanCocosFramework/assets/Texture/singleColor.png -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/Texture/singleColor.png.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "2.3.7", 3 | "uuid": "a8027877-d8d6-4645-97a0-52d4a0123dba", 4 | "importer": "texture", 5 | "type": "sprite", 6 | "wrapMode": "clamp", 7 | "filterMode": "bilinear", 8 | "premultiplyAlpha": false, 9 | "genMipmaps": false, 10 | "packable": true, 11 | "width": 2, 12 | "height": 2, 13 | "platformSettings": {}, 14 | "subMetas": { 15 | "singleColor": { 16 | "ver": "1.0.6", 17 | "uuid": "410fb916-8721-4663-bab8-34397391ace7", 18 | "importer": "sprite-frame", 19 | "rawTextureUuid": "a8027877-d8d6-4645-97a0-52d4a0123dba", 20 | "trimType": "auto", 21 | "trimThreshold": 1, 22 | "rotated": false, 23 | "offsetX": 0, 24 | "offsetY": 0, 25 | "trimX": 0, 26 | "trimY": 0, 27 | "width": 2, 28 | "height": 2, 29 | "rawWidth": 2, 30 | "rawHeight": 2, 31 | "borderTop": 0, 32 | "borderBottom": 0, 33 | "borderLeft": 0, 34 | "borderRight": 0, 35 | "subMetas": {} 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/migration.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.3", 3 | "uuid": "83bb9bd9-6ad4-40cf-b6e8-ae4ac47da7b7", 4 | "importer": "folder", 5 | "isBundle": false, 6 | "bundleName": "", 7 | "priority": 1, 8 | "compressionType": {}, 9 | "optimizeHotUpdate": {}, 10 | "inlineSpriteFrames": {}, 11 | "isRemoteBundle": {}, 12 | "subMetas": {} 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/migration/use_v2.1-2.2.1_cc.Toggle_event.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This script is automatically generated by Cocos Creator and is only used for projects compatible with the v2.1.0 ~ 2.2.1 version. 3 | * You do not need to manually add this script in any other project. 4 | * If you don't use cc.Toggle in your project, you can delete this script directly. 5 | * If your project is hosted in VCS such as git, submit this script together. 6 | * 7 | * 此脚本由 Cocos Creator 自动生成,仅用于兼容 v2.1.0 ~ 2.2.1 版本的工程, 8 | * 你无需在任何其它项目中手动添加此脚本。 9 | * 如果你的项目中没用到 Toggle,可直接删除该脚本。 10 | * 如果你的项目有托管于 git 等版本库,请将此脚本一并上传。 11 | */ 12 | 13 | if (cc.Toggle) { 14 | // Whether to trigger 'toggle' and 'checkEvents' events when modifying 'toggle.isChecked' in the code 15 | // 在代码中修改 'toggle.isChecked' 时是否触发 'toggle' 与 'checkEvents' 事件 16 | cc.Toggle._triggerEventInScript_isChecked = true; 17 | } 18 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/assets/migration/use_v2.1-2.2.1_cc.Toggle_event.js.meta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.1.0", 3 | "uuid": "4da53b4a-baac-42cd-89cd-bad152c340d4", 4 | "importer": "javascript", 5 | "isPlugin": false, 6 | "loadPluginInWeb": true, 7 | "loadPluginInNative": true, 8 | "loadPluginInEditor": false, 9 | "subMetas": {} 10 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs" 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "library", 9 | "local", 10 | "settings", 11 | "temp" 12 | ] 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "engine": "cocos2d-html5", 3 | "packages": "packages", 4 | "version": "2.4.11", 5 | "id": "199311fb-5f0a-495e-9ac7-d19f23709519", 6 | "isNew": false 7 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/settings/builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "excludeScenes": [], 3 | "orientation": { 4 | "landscapeLeft": true, 5 | "landscapeRight": true, 6 | "portrait": false, 7 | "upsideDown": false 8 | }, 9 | "packageName": "org.cocos2d.helloworld", 10 | "startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49", 11 | "title": "hello_world", 12 | "webOrientation": "auto" 13 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/settings/builder.panel.json: -------------------------------------------------------------------------------- 1 | { 2 | "excludeScenes": [], 3 | "packageName": "org.cocos2d.helloworld", 4 | "platform": "web-mobile", 5 | "startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49", 6 | "title": "HelloWorld" 7 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/settings/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "collision-matrix": [ 3 | [ 4 | true 5 | ] 6 | ], 7 | "excluded-modules": [ 8 | "3D Physics/cannon.js", 9 | "3D Physics/Builtin", 10 | "3D Particle", 11 | "SafeArea" 12 | ], 13 | "group-list": [ 14 | "default" 15 | ], 16 | "start-scene": "2d2f792f-a40c-49bb-a189-ed176a246e49", 17 | "design-resolution-width": 960, 18 | "design-resolution-height": 640, 19 | "fit-width": false, 20 | "fit-height": true, 21 | "use-project-simulator-setting": false, 22 | "simulator-orientation": false, 23 | "use-customize-simulator": false, 24 | "simulator-resolution": { 25 | "width": 960, 26 | "height": 640 27 | }, 28 | "last-module-event-record-time": 0, 29 | "assets-sort-type": "name", 30 | "facebook": { 31 | "enable": false, 32 | "appID": "", 33 | "live": { 34 | "enable": false 35 | }, 36 | "audience": { 37 | "enable": false 38 | } 39 | }, 40 | "migrate-history": [ 41 | "cloud-function" 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /YiyuanCocosFramework/settings/services.json: -------------------------------------------------------------------------------- 1 | { 2 | "game": { 3 | "name": "未知游戏", 4 | "appid": "UNKNOW" 5 | } 6 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/template-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lswgit/YiyuanCocosFramework/baf0e2f46f9bc2b88b1397901d14f137563bdfcf/YiyuanCocosFramework/template-banner.png -------------------------------------------------------------------------------- /YiyuanCocosFramework/template.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TEMPLATES.helloworld-ts.name", 3 | "desc": "TEMPLATES.helloworld-ts.desc", 4 | "banner": "template-banner.png" 5 | } -------------------------------------------------------------------------------- /YiyuanCocosFramework/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": [ "es2015", "es2017", "dom" ], 5 | "target": "es5", 6 | "experimentalDecorators": true, 7 | "skipLibCheck": true, 8 | "outDir": "temp/vscode-dist", 9 | "forceConsistentCasingInFileNames": true 10 | }, 11 | "exclude": [ 12 | "node_modules", 13 | "library", 14 | "local", 15 | "temp", 16 | "build", 17 | "settings" 18 | ] 19 | } --------------------------------------------------------------------------------