游戏热更新插件

This commit is contained in:
andrewlu 2021-02-02 00:11:00 +08:00
parent ba874af797
commit 3106b54566
40 changed files with 34326 additions and 37 deletions

51
.gitignore vendored Normal file
View File

@ -0,0 +1,51 @@
#/////////////////////////////////////////////////////////////////////////////
# Fireball Projects
#/////////////////////////////////////////////////////////////////////////////
/library/
/temp/
/local/
/build/
#/////////////////////////////////////////////////////////////////////////////
# npm files
#/////////////////////////////////////////////////////////////////////////////
npm-debug.log
node_modules/
#/////////////////////////////////////////////////////////////////////////////
# Logs and databases
#/////////////////////////////////////////////////////////////////////////////
*.log
*.sql
*.sqlite
#/////////////////////////////////////////////////////////////////////////////
# files for debugger
#/////////////////////////////////////////////////////////////////////////////
*.sln
*.pidb
*.suo
#/////////////////////////////////////////////////////////////////////////////
# OS generated files
#/////////////////////////////////////////////////////////////////////////////
.DS_Store
ehthumbs.db
Thumbs.db
#/////////////////////////////////////////////////////////////////////////////
# WebStorm files
#/////////////////////////////////////////////////////////////////////////////
.idea/
#//////////////////////////
# VS Code files
#//////////////////////////
.vscode/

View File

@ -1,37 +1,2 @@
# hot-update # hello-world
Hello world new project template.
#### 介绍
Cocos Creator 游戏项目热更新框架.
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

12
assets/Bundle2.meta Normal file
View File

@ -0,0 +1,12 @@
{
"ver": "1.1.2",
"uuid": "ff26afc9-280e-45e0-819f-d191f8740581",
"isBundle": true,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

211
assets/Bundle2/UI2.prefab Normal file
View File

@ -0,0 +1,211 @@
[
{
"__type__": "cc.Prefab",
"_name": "",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"asyncLoadAssets": false,
"readonly": false
},
{
"__type__": "cc.Node",
"_name": "UI2",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [
{
"__id__": 5
}
],
"_prefab": {
"__id__": 6
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
16.496,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "label",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
}
],
"_prefab": {
"__id__": 4
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 700,
"height": 255.6
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "这是Bundle2,修改此bundle 并上传更新包,然后运行查看效果.\n当前版本V3",
"_N$string": "这是Bundle2,修改此bundle 并上传更新包,然后运行查看效果.\n当前版本V3",
"_fontSize": 60,
"_lineHeight": 60,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
"_underlineHeight": 0,
"_N$horizontalAlign": 1,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 3,
"_N$cacheMode": 0,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "bbc419bf-1901-4df4-b291-a449a993cdeb"
},
"fileId": "5fjP6hXjVCTo6/StqazI+X",
"sync": false
},
{
"__type__": "c7040TRDPJIOYmGxy7HHERZ",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"label": null,
"text": "hello",
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "bbc419bf-1901-4df4-b291-a449a993cdeb"
},
"fileId": "",
"sync": false
}
]

View File

@ -0,0 +1,8 @@
{
"ver": "1.2.9",
"uuid": "bbc419bf-1901-4df4-b291-a449a993cdeb",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"readonly": false,
"subMetas": {}
}

28
assets/Bundle2/UI2.ts Normal file
View File

@ -0,0 +1,28 @@
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
}
// update (dt) {}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.8",
"uuid": "c70404d1-0cf2-4839-8986-c72ec71c4459",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

12
assets/Scene.meta Normal file
View File

@ -0,0 +1,12 @@
{
"ver": "1.1.2",
"uuid": "29f52784-2fca-467b-92e7-8fd9ef8c57b7",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

870
assets/Scene/main.fire Normal file
View File

@ -0,0 +1,870 @@
[
{
"__type__": "cc.SceneAsset",
"_name": "",
"_objFlags": 0,
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": false,
"_components": [],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_is3DNode": true,
"_groupIndex": 0,
"groupIndex": 0,
"autoReleaseAssets": false,
"_id": "2d2f792f-a40c-49bb-a189-ed176a246e49"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
},
{
"__id__": 5
},
{
"__id__": 8
},
{
"__id__": 15
}
],
"_active": true,
"_components": [
{
"__id__": 17
},
{
"__id__": 18
},
{
"__id__": 19
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 252,
"g": 252,
"b": 252,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
360,
640,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "a286bbGknJLZpRpxROV6M94"
},
{
"__type__": "cc.Node",
"_name": "Main Camera",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
533.7828766106993,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "f0ixqB+GBOMbfKORwx0VPu"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 3
},
"_enabled": true,
"_cullingMask": 4294967295,
"_clearFlags": 7,
"_backgroundColor": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": -1,
"_zoomRatio": 1,
"_targetTexture": null,
"_fov": 60,
"_orthoSize": 10,
"_nearClip": 1,
"_farClip": 4096,
"_ortho": true,
"_rect": {
"__type__": "cc.Rect",
"x": 0,
"y": 0,
"width": 1,
"height": 1
},
"_renderStages": 1,
"_alignWithScreen": true,
"_id": "21z5rLVsFBE5l0B1964Ml1"
},
{
"__type__": "cc.Node",
"_name": "background",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 6
},
{
"__id__": 7
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 27,
"g": 38,
"b": 46,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "e2e0crkOLxGrpMxpbC4iQg1"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 5
},
"_enabled": true,
"alignMode": 0,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 200,
"_originalHeight": 150,
"_id": "330Jnh1udCDJa2UO+Fyo0h"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 5
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "410fb916-8721-4663-bab8-34397391ace7"
},
"_type": 1,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "e0OWRwtTtFPpXd1W9n/sxX"
},
{
"__type__": "cc.Node",
"_name": "New Button",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [
{
"__id__": 9
}
],
"_active": true,
"_components": [
{
"__id__": 13
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
-297.894,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "33FfEsK/xFTbLplMf/NdVj"
},
{
"__type__": "cc.Node",
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 8
},
"_children": [
{
"__id__": 10
}
],
"_active": true,
"_components": [
{
"__id__": 12
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 200,
"height": 80
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "fafa3QQgVGrqBpniPchowP"
},
{
"__type__": "cc.Node",
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 9
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 11
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 113.4,
"height": 50.4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "4bd1rDK75Is4e5/XmGWoZQ"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 10
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "打开Bundle2",
"_N$string": "打开Bundle2",
"_fontSize": 20,
"_lineHeight": 40,
"_enableWrapText": false,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
"_underlineHeight": 0,
"_N$horizontalAlign": 1,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_N$cacheMode": 1,
"_id": "15LSK2O/1LKKSrM/efiXyO"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 9
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"_type": 1,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "f624EmhetHyqALXq9Luw9u"
},
{
"__type__": "cc.Button",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 8
},
"_enabled": true,
"_normalMaterial": null,
"_grayMaterial": null,
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [
{
"__id__": 14
}
],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$transition": 2,
"transition": 2,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 230,
"g": 230,
"b": 230,
"a": 255
},
"_N$pressedColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"pressedColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"_N$hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 120,
"g": 120,
"b": 120,
"a": 200
},
"_N$normalSprite": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"_N$pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"_N$hoverSprite": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"hoverSprite": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"_N$disabledSprite": {
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 9
},
"_id": "a9iPEeHWRBiriZDp0ceEYG"
},
{
"__type__": "cc.ClickEvent",
"target": {
"__id__": 2
},
"component": "",
"_componentId": "e1b90/rohdEk4SdmmEZANaD",
"handler": "onOpenBundle",
"customEventData": ""
},
{
"__type__": "cc.Node",
"_name": "New Label",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 16
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 300.04,
"height": 50.4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "bdswgX6ZtFJ6UUp1IapNmB"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 15
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "当前为新版本:V3",
"_N$string": "当前为新版本:V3",
"_fontSize": 40,
"_lineHeight": 40,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
"_underlineHeight": 0,
"_N$horizontalAlign": 1,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_N$cacheMode": 0,
"_id": "02rwAxQkdCwJhb9K1iFaUf"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_fitWidth": false,
"_fitHeight": true,
"_id": "d6LvozHEZAgrXkspnmqmen"
},
{
"__type__": "e1b90/rohdEk4SdmmEZANaD",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_id": "c4ziET/jdL3ZcIO08EL+a1"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_id": "e2HaHTdAZFbryDj3biqKSY"
}
]

View File

@ -0,0 +1,7 @@
{
"ver": "1.2.9",
"uuid": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}

12
assets/Script.meta Normal file
View File

@ -0,0 +1,12 @@
{
"ver": "1.1.2",
"uuid": "4734c20c-0db8-4eb2-92ea-e692f4d70934",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

View File

@ -0,0 +1,18 @@
const {ccclass, property} = cc._decorator;
@ccclass
export default class Helloworld extends cc.Component {
onOpenBundle() {
cc.assetManager.loadBundle("Bundle2", (err, bundle) => {
if (err) {
console.error("ERROR", err);
return;
}
bundle.load<cc.Prefab>("UI2", cc.Prefab, (err2, ui2) => {
const ui = cc.instantiate(ui2);
this.node.addChild(ui);
});
});
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.8",
"uuid": "e1b90feb-a217-4493-849d-9a611900d683",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

12
assets/Texture.meta Normal file
View File

@ -0,0 +1,12 @@
{
"ver": "1.1.2",
"uuid": "7b81d4e8-ec84-4716-968d-500ac1d78a54",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -0,0 +1,36 @@
{
"ver": "2.3.5",
"uuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 195,
"height": 270,
"platformSettings": {},
"subMetas": {
"HelloWorld": {
"ver": "1.0.4",
"uuid": "31bc895a-c003-4566-a9f3-2e54ae1c17dc",
"rawTextureUuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 195,
"height": 270,
"rawWidth": 195,
"rawHeight": 270,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 B

View File

@ -0,0 +1,36 @@
{
"ver": "2.3.5",
"uuid": "a8027877-d8d6-4645-97a0-52d4a0123dba",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 2,
"height": 2,
"platformSettings": {},
"subMetas": {
"singleColor": {
"ver": "1.0.4",
"uuid": "410fb916-8721-4663-bab8-34397391ace7",
"rawTextureUuid": "a8027877-d8d6-4645-97a0-52d4a0123dba",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 2,
"height": 2,
"rawWidth": 2,
"rawHeight": 2,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

32069
creator.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

13
jsconfig.json Normal file
View File

@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs"
},
"exclude": [
"node_modules",
"library",
"local",
"settings",
"temp"
]
}

View File

@ -0,0 +1,17 @@
{
"versionCfg": {
"versionCode": "3",
"versionName": "1.0.2",
"versionType": "dev",
"versionLog": "adfadsfdsfdsfsdf",
"baseUrl": "https://cdn-awdxc.8zy.com/"
},
"ftpCfg": {
"host": "106.55.246.140",
"port": "2121",
"user": "cos1",
"password": "dkJrWrVy11",
"rootPath": "temp001/",
"keepalive": 100000
}
}

View File

@ -0,0 +1,155 @@
'use strict';
const fs = require('fs');
const FileUtil = require('./FileUtils');
const Client = require("ftp");
class FileUploader {
ftps = {};
maxClients = 3;
options = {};
queue = [];
setOption(options, maxThread) {
this.options = options;
this.maxClients = maxThread || 1;
}
prepare() {
const currLen = Object.keys(this.ftps).length;
logger.info('准备创建上传线程:', this.maxClients, currLen);
if (currLen < this.maxClients) {
for (let i = this.maxClients - Object.keys(this.ftps).length; i > 0; i--) {
let name = "Thread-" + Math.random();
this.ftps[name] = new UploadThread(this.options);
}
}
}
destroy() {
for (let id in this.ftps) {
this.ftps[id].destroy();
delete this.ftps[id];
}
}
/**
* 上传文件目录到ftp服务器
* @param source
* @param dst
*/
upload(source, dst) {
const st = fs.statSync(source);
if (st.isFile()) {
this.queue.push({src: source, dst: dst})
} else if (st.isDirectory()) {
const files = FileUtil.listDirsAndFiles(source);
const startIndex = (source.endsWith('\\') || source.endsWith('/')) ? source.length - 1 : source.length;
const remoteStr = (dst.endsWith('\\') || dst.endsWith('/')) ? dst.substring(0, dst.length - 1) : dst;
for (let i of files.files) {
//bugfix: 这里目标文件路径必须是 linux文件路径.否则ftp会做为普通文件直接上传,而不包含目录.
this.queue.push({src: i, dst: (remoteStr + i.substring(startIndex)).replace(/\\/g, '/')});
}
}
this.checkUpload();
}
async checkUpload() {
// 准备上传线程.
this.prepare();
let once = null;
while ((once = this.queue.shift()) != null) {
const readyFtps = Object.values(this.ftps);
const index = Math.floor(Math.random() * readyFtps.length);
readyFtps[index].addTask(once);
}
}
}
class UploadThread {
ftp = null;
queue = [];
ready = false;
stopped = false;
options = null;
constructor(options) {
this.options = options;
this.ftp = this.newConnection();
this.run();
}
addTask(once) {
this.queue.push(once);
if (this.stopped) {
this.ftp = this.newConnection();
}
}
newConnection() {
this.ready = false;
const ftp = new Client();
ftp.on('ready', () => {
logger.log('ftp ready');
this.ready = true;
});
ftp.on('close', () => {
logger.log('ftp client has close');
this.ready = false;
});
ftp.on('end', () => {
logger.log('ftp client has end');
this.ready = false;
});
ftp.on('error', (err) => {
logger.log('ftp client has an error : ', JSON.stringify(err));
this.ready = false;
});
ftp.connect(this.options);
return ftp;
}
destroy() {
this.stopped = true;
}
async sleep(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
// 定时循环.直到destroy()执行.
async run() {
while (!this.stopped) {
if (!this.ready || this.queue.length <= 0) {
await this.sleep(500);
continue;
}
const once = this.queue[0];
const err = await this.uploadOnce(this.ftp, once);
if (!err) {
this.queue.shift();
logger.info('上传完成:', once.src);
continue;
} else {
logger.warn('上传失败,准备重试:', once.src);
this.ftp.end();
// 上传失败有可能是线程强制结束导致的上传失败.
if (!this.stopped) {
this.ftp = this.newConnection();
}
}
}
this.ftp.end();
}
uploadOnce(ftp, once) {
return new Promise(resolve => {
ftp.put(once.src, once.dst, false, resolve)
});
}
}
module.exports = function () {
return new FileUploader();
}

View File

@ -0,0 +1,75 @@
const fs = require('fs')
const path = require('path')
// console adapter.
global.logger = global.logger || {};
logger.log = (Editor && Editor.log) || console.log;
logger.info = (Editor && Editor.info) || console.info;
logger.warn = (Editor && Editor.warn) || console.warn;
logger.error = (Editor && Editor.error) || console.error;
logger.success = (Editor && Editor.success) || (Editor && Editor.info) || console.log;
class FileUtil {
/*
* 获取window上的文件目录以及文件列表信息
* @param { String } localDir 本地路径
* @return { files, dirs }
* */
listDirsAndFiles(localDir) {
const dirs = []
const files = []
const dir = fs.readdirSync(localDir)
for (let i = 0; i < dir.length; i++) {
const p = path.join(localDir, dir[i])
const stat = fs.statSync(p)
if (stat.isDirectory()) {
dirs.push(p)
const children = this.listDirsAndFiles(p)
dirs.push(...children.dirs)
files.push(...children.files)
} else {
files.push(p)
}
}
return {
files,
dirs
}
}
/**
* 拷贝文件或目录
* @param src
* @param dst
*/
copy(src, dst) {
const st = fs.statSync(src);
if (st.isFile()) {
var readable = fs.createReadStream(src);//创建读取流
var writable = fs.createWriteStream(dst);//创建写入流
readable.pipe(writable);
return;
} else if (!st.isDirectory()) {
return;
}
if (!fs.existsSync(dst)) {
fs.mkdirSync(dst, {recursive: true});
}
//读取目录
const paths = fs.readdirSync(src);
for (let path of paths) {
this.copy(src + '/' + path, dst + '/' + path);
}
};
write(filePath, content) {
const pathInfo = path.parse(filePath);
// console.log('写文件:', filePath, pathInfo.dir)
if (!fs.existsSync(pathInfo.dir)) {
fs.mkdirSync(pathInfo.dir, {recursive: true});
}
fs.writeFileSync(filePath, content, 'utf-8');
}
}
module.exports = new FileUtil();

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,90 @@
'use strict';
const fs = require('fs');
const {join} = require('path');
const FileUtil = require('./js/FileUtils');
const FileUpload = require('./js/FileUploader');
// 生成更新文件.
const doMakeUpdatePackage = function (opt, cb) {
if (opt.platform == 'android' || opt.platform == 'ios') {
try {
const configStr = fs.readFileSync(
Editor.url('packages://update-manager/.settings.conf'), 'utf-8');
const configJson = JSON.parse(configStr || "{}");
if (typeof configJson.versionCfg.versionCode === 'undefined') {
logger.warn("未配置更新版本,不生成热更Patch");
cb && cb();
return;
}
if (!configJson.versionCfg.versionType || configJson.versionCfg.versionType.length <= 0) {
configJson.versionCfg.versionType = 'dev';
}
const bundleVers = {};
for (let b of opt.bundles) {
bundleVers[b.name] = b.version;
}
saveNewVersionInfo(opt, bundleVers, configJson);
const remoteDir = join(opt.dest, 'remote');
const assetDir = join(opt.dest, 'assets');
FileUtil.copy(assetDir, remoteDir);
cb && cb();
} catch (e) {
logger.log("未生成更新包", e);
cb && cb();
}
} else {
cb && cb();
}
};
const saveNewVersionInfo = function (opt, bundleVers, configJson) {
const data = {
versionCode: configJson.versionCfg.versionCode,
versionName: configJson.versionCfg.versionName,
server: `${configJson.versionCfg.baseUrl}${configJson.ftpCfg.rootPath}${configJson.versionCfg.versionType}/${configJson.versionCfg.versionCode}`
};
const updateInfo = Object.assign(data, {bundles: bundleVers})
// 将版本更新信息写入文件
let targetUpdatePath = join(opt.dest, `remote/update-${configJson.versionCfg.versionType}.json`)
FileUtil.write(targetUpdatePath, JSON.stringify(updateInfo, null, 2));
logger.log("更新信息存储位置:", targetUpdatePath);
};
module.exports = {
load() {
Editor.Builder.on('build-finished', doMakeUpdatePackage);
try {
fs.readFileSync(
Editor.url('packages://update-manager/.settings.conf'), 'utf-8');
} catch (e) {
fs.writeFileSync(
Editor.url('packages://update-manager/.settings.conf'), JSON.stringify({}, null, 2), 'utf-8');
}
},
unload() {
Editor.Builder.removeListener('build-finished', doMakeUpdatePackage);
},
messages: {
'open'() {
Editor.Panel.open('update-manager');
},
'upload'(event, dir, dst, options) {
logger.info('upload....');
if (!this.ftp) {
this.ftp = FileUpload();
}
this.ftp.setOption(options, options.maxThread);
this.ftp.upload(dir, dst);
},
'uploadStop'() {
if (this.ftp) {
this.ftp.destroy();
this.ftp = null;
}
}
},
};

View File

@ -0,0 +1,53 @@
{
"name": "update-manager",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npm.taobao.org/core-util-is/download/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"ftp": {
"version": "0.3.10",
"resolved": "https://registry.npm.taobao.org/ftp/download/ftp-0.3.10.tgz",
"integrity": "sha1-kZfYYa2BQvPmPVqDv+TFn3MwiF0=",
"requires": {
"readable-stream": "1.1.x",
"xregexp": "2.0.0"
}
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npm.taobao.org/inherits/download/inherits-2.0.4.tgz?cache=0&sync_timestamp=1606706255906&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Finherits%2Fdownload%2Finherits-2.0.4.tgz",
"integrity": "sha1-D6LGT5MpF8NDOg3tVTY6rjdBa3w="
},
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npm.taobao.org/isarray/download/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npm.taobao.org/readable-stream/download/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npm.taobao.org/string_decoder/download/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"xregexp": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/xregexp/download/xregexp-2.0.0.tgz?cache=0&sync_timestamp=1607403606167&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fxregexp%2Fdownload%2Fxregexp-2.0.0.tgz",
"integrity": "sha1-UqY+VsoLhKfzpfPWGHLxJq16WUM="
}
}
}

View File

@ -0,0 +1,22 @@
{
"name": "update-manager",
"version": "0.0.1",
"description": "用于配置热更新信息.",
"author": "Andrewlu",
"main": "main.js",
"main-menu": {
"i18n:MAIN_MENU.package.title/热更新配置": {
"message": "update-manager:open"
}
},
"panel": {
"main": "panel/index.html",
"type": "simple",
"title": "热更新配置",
"width": 500,
"height": 600
},
"dependencies": {
"ftp": "^0.3.10"
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,266 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- import CSS -->
<link rel="stylesheet" href="./element-ui/index.css">
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #3646ea;
background-color: #fafcfc;
padding: 35px;
height: 100%;
}
</style>
</head>
<body style="height: 1000px;">
<div id="app">
<el-tabs v-model="tabName">
<el-tab-pane label="版本配置" name="versionConfig" style="height: 400px;">
<el-form ref="version" :model="versionCfg" label-width="100px">
<el-tooltip effect="dark" :content="tip.versionCode" open-delay=500 placement="top">
<el-form-item label="新版本号:">
<el-input type="number" v-model="versionCfg.versionCode" placeholder="1"></el-input>
</el-form-item>
</el-tooltip>
<el-tooltip effect="dark" :content="tip.versionName" open-delay=500 placement="top">
<el-form-item label="版本名称:">
<el-input v-model="versionCfg.versionName" placeholder="1.0.0"></el-input>
</el-form-item>
</el-tooltip>
<el-tooltip effect="dark" :content="tip.versionType" open-delay=500 placement="top">
<el-form-item label="版本类型:">
<el-input v-model="versionCfg.versionType" placeholder="dev"></el-input>
</el-form-item>
</el-tooltip>
<el-tooltip effect="dark" :content="tip.baseUrl" open-delay=500 placement="top">
<el-form-item label="热更地址:">
<el-input v-model="versionCfg.baseUrl"
placeholder="https://cdn-xxx.com"></el-input>
</el-form-item>
</el-tooltip>
<el-tooltip effect="dark" :content="tip.versionLog" open-delay=500 placement="top">
<el-form-item label="版本描述:">
<el-input type="textarea" v-model="versionCfg.versionLog"
placeholder="版本更新内容..."></el-input>
</el-form-item>
</el-tooltip>
</el-form>
</el-tab-pane>
<el-tab-pane label="上传配置" name="ftpConfig" style="height: 400px;">
<el-form ref="ftpCfg" :model="ftpCfg" label-width="100px">
<el-tooltip effect="dark" :content="tip.ip" placement="top" open-delay=500>
<el-form-item label="IP:">
<el-col :span="18">
<el-input type="text" v-model="ftpCfg.host" placeholder="127.0.0.1"></el-input>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="4">
<el-input type="number" v-model="ftpCfg.port" placeholder="端口号"></el-input>
</el-col>
</el-form-item>
</el-tooltip>
<el-tooltip effect="dark" :content="tip.user" open-delay=500 placement="top">
<el-form-item label="登录帐号:">
<el-col :span="11">
<el-input type="text" v-model="ftpCfg.user" placeholder="登录帐号"></el-input>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="11">
<el-input type="password" v-model="ftpCfg.password" placeholder="密码"></el-input>
</el-col>
</el-form-item>
</el-tooltip>
<el-tooltip effect="dark" content="FTP长连接持续心跳时间" open-delay=500 placement="top">
<el-form-item label="KeepAlive:">
<el-input type="number" v-model="ftpCfg.keepalive" placeholder="10000"></el-input>
</el-form-item>
</el-tooltip>
<el-tooltip effect="dark" content="FTP同时上传文件数,数量越大,上传效率越高<br/>受限于带宽性能,并非越大越好,推荐5~10" open-delay=500
placement="top">
<el-form-item label="并发数量:">
<el-input type="number" v-model="ftpCfg.maxThread" placeholder="5"></el-input>
</el-form-item>
</el-tooltip>
<el-tooltip effect="dark" :content="tip.rootPath" open-delay=500 placement="top">
<el-form-item label="FTP目录:">
<el-input v-model="ftpCfg.rootPath"
placeholder="TempDir/"></el-input>
</el-form-item>
</el-tooltip>
<el-tooltip effect="dark" content="勾选后仅会上传热更描述文件,<br/>需要手动上传remote目录" open-delay=500 placement="top">
<el-form-item label="手动上传:">
<el-switch v-model="ftpCfg.onlyJson"></el-switch>
</el-form-item>
</el-tooltip>
</el-form>
</el-tab-pane>
<el-tab-pane label="使用帮助" name="help" style="height: 400px;">
<div style="height: 300px;">
<el-alert :closable="false"
title="如不需要发布新版本,可无需做任何操作,以正常步骤打包发布即可"
type="info">
</el-alert>
<el-divider content-position="left"></el-divider>
<el-steps direction="vertical" :active="1" space="100px">
<el-step title="版本配置"
description="使用前需要先配置版本信息,并点击保存配置."></el-step>
<el-step title="构建版本"
description="开始构建版本,构建完成后会在构建目录中生成remote文件夹以及update-dev.json更新描述文件"></el-step>
<el-step title="上传更新包"
description="构建完成时,如需发布新版本,则需要点击[上传更新包],更新包会向游戏代码中注入热更逻辑."></el-step>
</el-steps>
</div>
</el-tab-pane>
</el-tabs>
<el-row>
<el-col :span="8">
<el-button type="success" @click="onSave">保存配置信息</el-button>
</el-col>
<el-col :span="8">
<el-button type="danger" @click="onUpload">上传更新包</el-button>
</el-col>
<el-col :span="8">
<el-button type="warning" @click="onStopUpload">终止上传</el-button>
</el-col>
</el-row>
</div>
</body>
<!-- import Vue before Element -->
<script src="../js/vue.2.5.16.js"></script>
<!-- import JavaScript -->
<script src="./element-ui/index.js"></script>
<script>
const fs = require('fs');
const path = require('path');
new Vue({
el: '#app',
data() {
return {
tabName: "versionConfig",
projectPath: "",
versionCfg: {
versionCode: 1,
versionName: "1.0.0",
versionType: "dev",
versionLog: "",
baseUrl: ""
},
ftpCfg: {
host: "127.0.0.1",
port: 21,
user: "",
password: "",
rootPath: "",
keepalive: 100000,
onlyJson: false,
maxThread: 5
},
tip: {
versionCode: "递增版本号,如果与旧版本号相同,则会替换线上版本包.",
versionName: "版本号名称,示例:1.0.0, 用于游戏内显示",
versionType: "版本类型,用于标记当前版本所处的线上环境类型,<br/>如灰度包,内测包,发布包等,不同类型的版本物理隔离,不会相互影响",
versionLog: "版本发布日志,用于游戏内显示更新内容.",
baseUrl: "FTP上传服务器对应的CDN访问URL,仅需要填写根域名即可.",
ip: "FTP上传IP地址,示例:127.0.0.1",
port: "FTP端口号,默认21",
user: "FTP登录验证帐号及密码",
rootPath: "FTP文件上传根目录"
}
};
},
created: function () {
let data = fs.readFileSync(
Editor.url('packages://update-manager/.settings.conf'), 'utf-8');
if (data) {
Object.assign(this, JSON.parse(data));
}
this.projectPath = Editor.url('packages://update-manager');
this.projectPath = this.projectPath.substring(0, this.projectPath.length - 'packages/update-manager'.length)
Editor.log('当前项目路径:', this.projectPath);
},
methods: {
onSave() {
if (!this.versionCfg.baseUrl.endsWith('/') && this.versionCfg.baseUrl.length > 0) {
this.versionCfg.baseUrl += "/";
}
if (!this.ftpCfg.rootPath.endsWith('/') && this.ftpCfg.rootPath.length > 0) {
this.ftpCfg.rootPath += "/";
}
const data = Object.assign({}, {versionCfg: this.versionCfg, ftpCfg: this.ftpCfg});
fs && fs.writeFileSync && fs.writeFileSync(
Editor.url('packages://update-manager/.settings.conf'), JSON.stringify(data, null, 2), 'utf-8');
this.$message({message: "配置保存成功!", type: "success"});
},
onUpload() {
Editor.info("准备上传更新包");
this.$message("准备上传更新包");
if (!this.versionCfg.baseUrl.endsWith('/') && this.versionCfg.baseUrl.length > 0) {
this.versionCfg.baseUrl += "/";
}
if (!this.ftpCfg.rootPath.endsWith('/') && this.ftpCfg.rootPath.length > 0) {
this.ftpCfg.rootPath += "/";
}
let filePath = `update-${this.versionCfg.versionType}.json`;
const uploadDstPath = `${this.ftpCfg.rootPath}${this.versionCfg.versionType}/${filePath}`;
let updateUrl = `${this.versionCfg.baseUrl}${uploadDstPath}`;
const serverUrl = `${this.versionCfg.baseUrl}${this.ftpCfg.rootPath}${this.versionCfg.versionType}/${this.versionCfg.versionCode}`;
if (!this.notifyMainJs(updateUrl, serverUrl)) {
return;
}
if (this.ftpCfg.onlyJson) {
Editor.warn('当前仅上传JSON文件,请手动上传remote目录');
return;
}
// 上传更新描述文件.
const updateJsonPath = path.join(this.projectPath, `build/jsb-link/remote/${filePath}`);
Editor.Ipc.sendToMain('update-manager:upload', updateJsonPath, uploadDstPath, this.ftpCfg);
// 上传远程更新包.
let uploadZipPath = path.join(this.projectPath, `build/jsb-link/remote`);
let uploadZipDstPath = `${this.ftpCfg.rootPath}${this.versionCfg.versionType}/${this.versionCfg.versionCode}/remote`;
Editor.Ipc.sendToMain('update-manager:upload', uploadZipPath, uploadZipDstPath, this.ftpCfg);
},
onStopUpload() {
Editor.Ipc.sendToMain('update-manager:uploadStop');
},
notifyMainJs(updateUrl, serverUrl) {
this.$message.info("notifyMainJs");
const filePath = path.join(this.projectPath, 'build/jsb-link/main.js');
const exists = fs.existsSync(filePath);
if (!exists) {
this.$message.error('main.js 不存在,请重新构建');
return false;
}
let mainjs = fs.readFileSync(filePath, 'utf-8');
let varJs = `window.updateUrl="${updateUrl}";\r\n`;
let remoteJs = `window.remoteUrl="${serverUrl}";\r\n`;
// preMainJS read.
const preMain = fs && fs.readFileSync && fs.readFileSync(
Editor.url('packages://update-manager/templates/pre_main.js'), 'utf-8');
if (!mainjs.startsWith(varJs)) {
mainjs = mainjs.replace('window.boot();', 'window.beforeBoot();');
mainjs = varJs + remoteJs + preMain + mainjs;
fs && fs.writeFileSync && fs.writeFileSync(filePath, mainjs, 'utf-8');
}
this.$message.success("Main.js 热更代码注入成功");
return true;
}
}
})
</script>
</html>

View File

@ -0,0 +1,90 @@
window.beforeBoot = function () {
cc.log("游戏正在启动中.")
if (window.remoteUrl) {
const settings = window._CCSettings;
settings.server = window.remoteUrl;
cc.log("远程资源地址:", settings.server);
}
let url = window.updateUrl || false;
if (!url) {
cc.log("未配置版本更新地址,跳过更新.")
window.boot();
return;
}
url += `?_t=${Math.random()}`;
cc.log("请求更新地址:", url);
get(url, function (err, asset) {
cc.log("请求更新信息:", url, err && err.toLocaleString(), JSON.stringify(asset));
if (err || !asset) {
window.boot();
return;
}
window.mergeVersion(asset);
window.boot();
cc.log("游戏已启动.");
});
};
window.mergeVersion = function (updateInfo) {
const currentVer = cc.sys.localStorage.getItem("currentVer");
let isFirstRun = false;
let newVerFlag = false;
if (!currentVer) {
isFirstRun = true;
cc.log("当前为首次运行");
} else {
const oldVerInfo = JSON.parse(currentVer);
if (oldVerInfo && oldVerInfo.versionCode != updateInfo.versionCode) {
newVerFlag = true;
cc.log("发现新版本信息:", updateInfo.versionCode, oldVerInfo.versionCode);
}
}
const settings = window._CCSettings;
if (updateInfo.server) {
settings.server = updateInfo.server;
cc.log("更新远程资源地址:", updateInfo.server);
}
const bundleVers = updateInfo.bundles
if (bundleVers) {
let changed = false;
for (let b in bundleVers) {
if (bundleVers[b] != settings.bundleVers[b]) {
// 配置中的bundleVer版本不一致,则添加到remote列表中去,以供远程加载.
if (settings.remoteBundles.indexOf(b) < 0) {
settings.remoteBundles.push(b);
}
changed = true;
cc.log("发现更新Bundle:", b);
}
}
settings.bundleVers = bundleVers;
// 如果首次运行,但检测版本有差异,则标记有更新.
if (isFirstRun && changed) {
newVerFlag = true;
cc.log("标记为新版本.");
}
}
cc.sys.localStorage.setItem('newVerFlag', newVerFlag ? 1 : 0);
cc.sys.localStorage.setItem('firstRunFlag', isFirstRun ? 1 : 0);
cc.sys.localStorage.setItem('currentVer', JSON.stringify(updateInfo));
}
// ajax 请求.
function get(url, cb) {
const ajax = new XMLHttpRequest();
ajax.open("get", url, true);
ajax.setRequestHeader("Content-Type", "application/json;charset=utf-8");
ajax.onreadystatechange = function () {
if (ajax.readyState == 4) {
if (ajax.status == 200) {
var response = JSON.parse(ajax.responseText)
cb && cb(null, response);
return;
} else {
cb && cb("request error!");
}
}
}
ajax.send(null);
}

8
project.json Normal file
View File

@ -0,0 +1,8 @@
{
"engine": "cocos2d-html5",
"packages": "packages",
"version": "2.4.3",
"name": "hot-update",
"id": "5a9ea02b-de95-4488-8be4-82a72e441e5e",
"isNew": false
}

53
settings/builder.json Normal file
View File

@ -0,0 +1,53 @@
{
"excludeScenes": [],
"orientation": {
"landscapeLeft": false,
"landscapeRight": false,
"portrait": true,
"upsideDown": false
},
"packageName": "org.cocos2d.helloworld",
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"title": "hello_world",
"webOrientation": "auto",
"inlineSpriteFrames": true,
"inlineSpriteFrames_native": true,
"mainCompressionType": "default",
"mainIsRemote": false,
"optimizeHotUpdate": false,
"md5Cache": true,
"nativeMd5Cache": true,
"encryptJs": false,
"xxteaKey": "fe6a7fcd-48c1-44",
"zipCompressJs": true,
"fb-instant-games": {},
"android": {
"REMOTE_SERVER_ROOT": "",
"packageName": "org.cocos2d.demo"
},
"ios": {
"REMOTE_SERVER_ROOT": "",
"packageName": "org.cocos2d.demo"
},
"mac": {
"REMOTE_SERVER_ROOT": "",
"height": 720,
"packageName": "org.cocos2d.demo",
"width": 1280
},
"win32": {
"REMOTE_SERVER_ROOT": "",
"height": 720,
"width": 1280
},
"android-instant": {
"REMOTE_SERVER_ROOT": "",
"host": "",
"packageName": "org.cocos2d.demo",
"pathPattern": "",
"recordPath": "",
"scheme": "https",
"skipRecord": false
},
"appBundle": false
}

View File

@ -0,0 +1,7 @@
{
"excludeScenes": [],
"packageName": "org.cocos2d.helloworld",
"platform": "web-mobile",
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"title": "HelloWorld"
}

37
settings/project.json Normal file
View File

@ -0,0 +1,37 @@
{
"collision-matrix": [
[
true
]
],
"excluded-modules": [],
"group-list": [
"default"
],
"start-scene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"design-resolution-width": 720,
"design-resolution-height": 1280,
"fit-width": false,
"fit-height": true,
"use-project-simulator-setting": false,
"simulator-orientation": false,
"use-customize-simulator": true,
"simulator-resolution": {
"height": 640,
"width": 960
},
"last-module-event-record-time": 1612193235939,
"assets-sort-type": "name",
"facebook": {
"appID": "",
"audience": {
"enable": false
},
"enable": false,
"live": {
"enable": false
}
},
"preview-port": 7456,
"clear-simulator-cache": true
}

6
settings/services.json Normal file
View File

@ -0,0 +1,6 @@
{
"game": {
"name": "未知游戏",
"appid": "UNKNOW"
}
}

BIN
template-banner.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

5
template.json Normal file
View File

@ -0,0 +1,5 @@
{
"name": "TEMPLATES.helloworld-ts.name",
"desc": "TEMPLATES.helloworld-ts.desc",
"banner": "template-banner.png"
}

19
tsconfig.json Normal file
View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [ "es2015", "es2017", "dom" ],
"target": "es5",
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "temp/vscode-dist",
"forceConsistentCasingInFileNames": true
},
"exclude": [
"node_modules",
"library",
"local",
"temp",
"build",
"settings"
]
}