mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-06-04 00:19:33 +08:00
添加热更新demo
This commit is contained in:
67
HotUpdateDemo/.gitignore
vendored
Normal file
67
HotUpdateDemo/.gitignore
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# Fireball Projects
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
library/
|
||||
temp/
|
||||
local/
|
||||
build/
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# Logs and databases
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# files for debugger
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
*.sln
|
||||
*.csproj
|
||||
*.pidb
|
||||
*.unityproj
|
||||
*.suo
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# OS generated files
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
.DS_Store
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# exvim files
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
*UnityVS.meta
|
||||
*.err
|
||||
*.err.meta
|
||||
*.exvim
|
||||
*.exvim.meta
|
||||
*.vimentry
|
||||
*.vimentry.meta
|
||||
*.vimproject
|
||||
*.vimproject.meta
|
||||
.vimfiles.*/
|
||||
.exvim.*/
|
||||
quick_gen_project_*_autogen.bat
|
||||
quick_gen_project_*_autogen.bat.meta
|
||||
quick_gen_project_*_autogen.sh
|
||||
quick_gen_project_*_autogen.sh.meta
|
||||
.exvim.app
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# webstorm files
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
.idea/
|
||||
|
||||
#//////////////////////////
|
||||
# VS Code
|
||||
#//////////////////////////
|
||||
|
||||
.vscode/
|
||||
2
HotUpdateDemo/README.md
Normal file
2
HotUpdateDemo/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# 热更新Demo
|
||||
如果喜欢上[简书](https://www.jianshu.com/u/33b882c6c780)关注我吧。我会不定时更新Cocos Creator教程与上传demo到github
|
||||
6
HotUpdateDemo/assets/Scene.meta
Normal file
6
HotUpdateDemo/assets/Scene.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "29f52784-2fca-467b-92e7-8fd9ef8c57b7",
|
||||
"isGroup": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
418
HotUpdateDemo/assets/Scene/helloworld.fire
Normal file
418
HotUpdateDemo/assets/Scene/helloworld.fire
Normal file
@@ -0,0 +1,418 @@
|
||||
[
|
||||
{
|
||||
"__type__": "cc.SceneAsset",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_rawFiles": null,
|
||||
"scene": {
|
||||
"__id__": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Scene",
|
||||
"_objFlags": 0,
|
||||
"_parent": null,
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 2
|
||||
}
|
||||
],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [],
|
||||
"_prefab": null,
|
||||
"_id": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_opacityModifyRGB": false,
|
||||
"groupIndex": 0,
|
||||
"autoReleaseAssets": false
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Canvas",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 3
|
||||
},
|
||||
{
|
||||
"__id__": 6
|
||||
},
|
||||
{
|
||||
"__id__": 8
|
||||
}
|
||||
],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 10
|
||||
},
|
||||
{
|
||||
"__id__": 11
|
||||
},
|
||||
{
|
||||
"__id__": 12
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_id": "a286bbGknJLZpRpxROV6M94",
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 252,
|
||||
"g": 252,
|
||||
"b": 252,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 960,
|
||||
"height": 640
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 480,
|
||||
"y": 320
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_opacityModifyRGB": false,
|
||||
"groupIndex": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "background",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_children": [],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 4
|
||||
},
|
||||
{
|
||||
"__id__": 5
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_id": "e2e0crkOLxGrpMxpbC4iQg1",
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 27,
|
||||
"g": 38,
|
||||
"b": 46,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 960,
|
||||
"height": 640
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_opacityModifyRGB": false,
|
||||
"groupIndex": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 3
|
||||
},
|
||||
"_enabled": true,
|
||||
"isAlignOnce": true,
|
||||
"_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
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 3
|
||||
},
|
||||
"_enabled": true,
|
||||
"_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,
|
||||
"_srcBlendFactor": 770,
|
||||
"_dstBlendFactor": 771,
|
||||
"_atlas": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "cocos",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_children": [],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 7
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_id": "c4f30YOS65G64U2TwufdJ+2",
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 195,
|
||||
"height": 270
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 50
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_opacityModifyRGB": false,
|
||||
"groupIndex": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_enabled": true,
|
||||
"_spriteFrame": {
|
||||
"__uuid__": "31bc895a-c003-4566-a9f3-2e54ae1c17dc"
|
||||
},
|
||||
"_type": 0,
|
||||
"_sizeMode": 1,
|
||||
"_fillType": 0,
|
||||
"_fillCenter": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_fillStart": 0,
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_srcBlendFactor": 770,
|
||||
"_dstBlendFactor": 771,
|
||||
"_atlas": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "label",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_children": [],
|
||||
"_tag": -1,
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 9
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_id": "31f1bH7V69Ajr1iXhluMpTB",
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_cascadeOpacityEnabled": true,
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 147,
|
||||
"height": 60
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_scaleX": 1,
|
||||
"_scaleY": 1,
|
||||
"_position": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": -180
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_localZOrder": 0,
|
||||
"_globalZOrder": 0,
|
||||
"_opacityModifyRGB": false,
|
||||
"groupIndex": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 8
|
||||
},
|
||||
"_enabled": true,
|
||||
"_useOriginalSize": false,
|
||||
"_actualFontSize": 40,
|
||||
"_fontSize": 60,
|
||||
"_lineHeight": 60,
|
||||
"_enableWrapText": true,
|
||||
"_N$file": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_N$string": "Label",
|
||||
"_N$horizontalAlign": 1,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Canvas",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"_designResolution": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 960,
|
||||
"height": 640
|
||||
},
|
||||
"_fitWidth": false,
|
||||
"_fitHeight": true
|
||||
},
|
||||
{
|
||||
"__type__": "280c3rsZJJKnZ9RqbALVwtK",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"label": {
|
||||
"__id__": 9
|
||||
},
|
||||
"text": "Hello, World"
|
||||
},
|
||||
{
|
||||
"__type__": "ca6fbSYPa9P2JPPqQFdB0OQ",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"manifestUrl": {
|
||||
"__uuid__": "2857653b-09b5-4724-a067-615f6905fbc2"
|
||||
}
|
||||
}
|
||||
]
|
||||
7
HotUpdateDemo/assets/Scene/helloworld.fire.meta
Normal file
7
HotUpdateDemo/assets/Scene/helloworld.fire.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||
"asyncLoadAssets": false,
|
||||
"autoReleaseAssets": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
6
HotUpdateDemo/assets/Script.meta
Normal file
6
HotUpdateDemo/assets/Script.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "4734c20c-0db8-4eb2-92ea-e692f4d70934",
|
||||
"isGroup": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
22
HotUpdateDemo/assets/Script/HelloWorld.js
Normal file
22
HotUpdateDemo/assets/Script/HelloWorld.js
Normal file
@@ -0,0 +1,22 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
label: {
|
||||
default: null,
|
||||
type: cc.Label
|
||||
},
|
||||
// defaults, set visually when attaching this script to the Canvas
|
||||
text: 'Hello, World!'
|
||||
},
|
||||
|
||||
// use this for initialization
|
||||
onLoad: function () {
|
||||
this.label.string = this.text;
|
||||
},
|
||||
|
||||
// called every frame
|
||||
update: function (dt) {
|
||||
|
||||
},
|
||||
});
|
||||
9
HotUpdateDemo/assets/Script/HelloWorld.js.meta
Normal file
9
HotUpdateDemo/assets/Script/HelloWorld.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "280c3aec-6492-4a9d-9f51-a9b00b570b4a",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
221
HotUpdateDemo/assets/Script/HotUpdate.js
Normal file
221
HotUpdateDemo/assets/Script/HotUpdate.js
Normal file
@@ -0,0 +1,221 @@
|
||||
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
manifestUrl: cc.RawAsset,
|
||||
},
|
||||
|
||||
// LIFE-CYCLE CALLBACKS:
|
||||
|
||||
onLoad() {
|
||||
|
||||
this.init();
|
||||
this.checkUpdate();
|
||||
},
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
init() {
|
||||
this._storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + 'blackjack-remote-asset');
|
||||
cc.log('Storage path for remote asset : ' + this._storagePath);
|
||||
|
||||
this.versionCompareHandle = function (versionA, versionB) {
|
||||
console.log('versionA=' + versionA + ' versionB=' + versionB);
|
||||
var vA = versionA.split('.');
|
||||
var vB = versionB.split('.');
|
||||
for (var i = 0; i < vA.length; ++i) {
|
||||
var a = parseInt(vA[i]);
|
||||
var b = parseInt(vB[i] || 0);
|
||||
if (a === b) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
return a - b;
|
||||
}
|
||||
}
|
||||
if (vB.length > vA.length) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
this._am = new jsb.AssetsManager('', this._storagePath, this.versionCompareHandle);
|
||||
if (!cc.sys.ENABLE_GC_FOR_NATIVE_OBJECTS) {
|
||||
this._am.retain();
|
||||
}
|
||||
|
||||
this._am.setVerifyCallback(function (path, asset) {
|
||||
var compressed = asset.compressed;
|
||||
if (compressed) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (cc.sys.os === cc.sys.OS_ANDROID) {
|
||||
this._am.setMaxConcurrentTask(2);
|
||||
}
|
||||
},
|
||||
|
||||
//热更新完成 or 不需要热更新 进入游戏
|
||||
onEnterGame: function () {
|
||||
|
||||
},
|
||||
/**
|
||||
* 检查更新
|
||||
*/
|
||||
checkUpdate: function () {
|
||||
console.log('start checkUpdate');
|
||||
// if (this._updating) {
|
||||
// // this.panel.info.string = 'Checking or updating ...';
|
||||
// return;
|
||||
// }
|
||||
if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
|
||||
this._am.loadLocalManifest(this.manifestUrl);
|
||||
}
|
||||
if (!this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) {
|
||||
this.panel.info.string = 'Failed to load local manifest ...';
|
||||
return;
|
||||
}
|
||||
this._checkListener = new jsb.EventListenerAssetsManager(this._am, this.checkCb.bind(this));
|
||||
cc.eventManager.addListener(this._checkListener, 1);
|
||||
|
||||
this._am.checkUpdate();
|
||||
},
|
||||
|
||||
/**
|
||||
* 执行热更新逻辑
|
||||
*/
|
||||
hotUpdate: function () {
|
||||
console.log('start hotUpdate');
|
||||
if (this._am && !this._updating) {
|
||||
this._updateListener = new jsb.EventListenerAssetsManager(this._am, this.updateCb.bind(this));
|
||||
cc.eventManager.addListener(this._updateListener, 1);
|
||||
|
||||
if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
|
||||
this._am.loadLocalManifest(this.manifestUrl);
|
||||
}
|
||||
|
||||
this._am.update();
|
||||
this._updating = true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 检查热更回调函数
|
||||
*/
|
||||
checkCb: function (event) {
|
||||
cc.log('Code: ' + event.getEventCode());
|
||||
let isNewVersion = false;
|
||||
switch (event.getEventCode()) {
|
||||
case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
|
||||
/*0 本地没有配置文件*/
|
||||
console.log('ERROR_NO_LOCAL_MANIFEST');
|
||||
break;
|
||||
case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
|
||||
/*1下载配置文件错误*/
|
||||
case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:
|
||||
/*2 解析文件错误*/
|
||||
console.log('ERROR_PARSE_MANIFEST');
|
||||
break;
|
||||
case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:
|
||||
/*3 已经是最新的*/
|
||||
console.log('ALREADY_UP_TO_DATE');
|
||||
break;
|
||||
case jsb.EventAssetsManager.NEW_VERSION_FOUND:
|
||||
/*4发现新的更新*/
|
||||
isNewVersion = true;
|
||||
cc.eventManager.removeListener(this._checkListener);
|
||||
this._checkListener = null;
|
||||
console.log('have new version');
|
||||
//开始更新版本
|
||||
this.hotUpdate();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (!isNewVersion) {
|
||||
cc.eventManager.removeListener(this._checkListener);
|
||||
this._checkListener = null;
|
||||
//进入游戏
|
||||
this.onEnterGame();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 热更回调函数
|
||||
*/
|
||||
updateCb: function (event) {
|
||||
var needRestart = false;
|
||||
var failed = false;
|
||||
switch (event.getEventCode()) {
|
||||
case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
|
||||
// this.panel.info.string = 'No local manifest file found, hot update skipped.';
|
||||
failed = true;
|
||||
break;
|
||||
case jsb.EventAssetsManager.UPDATE_PROGRESSION:
|
||||
//显示进度
|
||||
// this.panel.byteProgress.progress = event.getPercent();
|
||||
// this.panel.fileProgress.progress = event.getPercentByFile();
|
||||
break;
|
||||
case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
|
||||
case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:
|
||||
// this.panel.info.string = 'Fail to download manifest file, hot update skipped.';
|
||||
failed = true;
|
||||
break;
|
||||
case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:
|
||||
// this.panel.info.string = 'Already up to date with the latest remote version.';
|
||||
failed = true;
|
||||
break;
|
||||
case jsb.EventAssetsManager.UPDATE_FINISHED:
|
||||
// this.panel.info.string = 'Update finished. ' + event.getMessage();
|
||||
needRestart = true;
|
||||
break;
|
||||
case jsb.EventAssetsManager.UPDATE_FAILED:
|
||||
// this.panel.info.string = 'Update failed. ' + event.getMessage();
|
||||
// this.panel.retryBtn.active = true;
|
||||
this._updating = false;
|
||||
this._canRetry = true;
|
||||
break;
|
||||
case jsb.EventAssetsManager.ERROR_UPDATING:
|
||||
// this.panel.info.string = 'Asset update error: ' + event.getAssetId() + ', ' + event.getMessage();
|
||||
break;
|
||||
case jsb.EventAssetsManager.ERROR_DECOMPRESS:
|
||||
// this.panel.info.string = event.getMessage();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//下载失败
|
||||
if (failed) {
|
||||
console.log('Hotupdate failure');
|
||||
cc.eventManager.removeListener(this._updateListener);
|
||||
this._updateListener = null;
|
||||
this._updating = false;
|
||||
}
|
||||
|
||||
if (needRestart) {
|
||||
console.log('Hotupdate success');
|
||||
cc.eventManager.removeListener(this._updateListener);
|
||||
this._updateListener = null;
|
||||
var searchPaths = jsb.fileUtils.getSearchPaths();
|
||||
var newPaths = this._am.getLocalManifest().getSearchPaths();
|
||||
// console.log(JSON.stringify(newPaths));
|
||||
Array.prototype.unshift(searchPaths, newPaths);
|
||||
|
||||
cc.sys.localStorage.setItem('HotUpdateSearchPaths', JSON.stringify(searchPaths));
|
||||
jsb.fileUtils.setSearchPaths(searchPaths);
|
||||
cc.audioEngine.stopAll();
|
||||
cc.game.restart();
|
||||
}
|
||||
},
|
||||
|
||||
// update (dt) {},
|
||||
});
|
||||
9
HotUpdateDemo/assets/Script/HotUpdate.js.meta
Normal file
9
HotUpdateDemo/assets/Script/HotUpdate.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "ca6fb498-3daf-4fd8-93cf-a9015d074390",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
6
HotUpdateDemo/assets/Texture.meta
Normal file
6
HotUpdateDemo/assets/Texture.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "7b81d4e8-ec84-4716-968d-500ac1d78a54",
|
||||
"isGroup": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
BIN
HotUpdateDemo/assets/Texture/HelloWorld.png
Normal file
BIN
HotUpdateDemo/assets/Texture/HelloWorld.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
30
HotUpdateDemo/assets/Texture/HelloWorld.png.meta
Normal file
30
HotUpdateDemo/assets/Texture/HelloWorld.png.meta
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4",
|
||||
"type": "sprite",
|
||||
"wrapMode": "clamp",
|
||||
"filterMode": "bilinear",
|
||||
"subMetas": {
|
||||
"HelloWorld": {
|
||||
"ver": "1.0.3",
|
||||
"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": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
HotUpdateDemo/assets/Texture/singleColor.png
Normal file
BIN
HotUpdateDemo/assets/Texture/singleColor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
30
HotUpdateDemo/assets/Texture/singleColor.png.meta
Normal file
30
HotUpdateDemo/assets/Texture/singleColor.png.meta
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "a8027877-d8d6-4645-97a0-52d4a0123dba",
|
||||
"type": "sprite",
|
||||
"wrapMode": "clamp",
|
||||
"filterMode": "bilinear",
|
||||
"subMetas": {
|
||||
"singleColor": {
|
||||
"ver": "1.0.3",
|
||||
"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": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
HotUpdateDemo/assets/project.manifest
Normal file
1
HotUpdateDemo/assets/project.manifest
Normal file
@@ -0,0 +1 @@
|
||||
{"packageUrl":"http://192.168.0.124/remote-assets/","remoteManifestUrl":"http://192.168.0.124/remote-assets/project.manifest","remoteVersionUrl":"http://192.168.0.124/remote-assets/version.manifest","version":"1.0.1","assets":{"src/jsb_polyfill.jsc":{"size":135144,"md5":"42d63902662204a5c7d28ffa600287c0"},"src/project.jsc":{"size":1728,"md5":"4a3bdd3b921d5c7cc5f245f0189e4ac1"},"src/settings.jsc":{"size":504,"md5":"8a9e673701fb83412db34bc530c91af8"},"res/import/05/05dd1dc0e.json":{"size":2190,"md5":"cb72214a1510295a2b9115062a9daa20"},"res/raw-assets/project.manifest":{"size":750,"md5":"4c4d16b69633cccdf8a27a3f1409f8d4"},"res/raw-assets/Texture/HelloWorld.png":{"size":37864,"md5":"a69a0b857f7462f4dd0d00bb5231a721"},"res/raw-assets/Texture/singleColor.png":{"size":17197,"md5":"5825642f69b6fed137482bf89f8f1fd5"}},"searchPaths":[]}
|
||||
5
HotUpdateDemo/assets/project.manifest.meta
Normal file
5
HotUpdateDemo/assets/project.manifest.meta
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "2857653b-09b5-4724-a067-615f6905fbc2",
|
||||
"subMetas": {}
|
||||
}
|
||||
1
HotUpdateDemo/assets/version.manifest
Normal file
1
HotUpdateDemo/assets/version.manifest
Normal file
@@ -0,0 +1 @@
|
||||
{"packageUrl":"http://192.168.0.124/remote-assets/","remoteManifestUrl":"http://192.168.0.124/remote-assets/project.manifest","remoteVersionUrl":"http://192.168.0.124/remote-assets/version.manifest","version":"1.0.1"}
|
||||
5
HotUpdateDemo/assets/version.manifest.meta
Normal file
5
HotUpdateDemo/assets/version.manifest.meta
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "5a4d5cda-d694-467c-9587-3653e9b41f0c",
|
||||
"subMetas": {}
|
||||
}
|
||||
244
HotUpdateDemo/build-templates/jsb-binary/main.js
Normal file
244
HotUpdateDemo/build-templates/jsb-binary/main.js
Normal file
@@ -0,0 +1,244 @@
|
||||
(function () {
|
||||
|
||||
if (window.cc && cc.sys.isNative) {
|
||||
var hotUpdateSearchPaths = cc.sys.localStorage.getItem('HotUpdateSearchPaths');
|
||||
if (hotUpdateSearchPaths) {
|
||||
jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths));
|
||||
}
|
||||
}
|
||||
function boot () {
|
||||
|
||||
var settings = window._CCSettings;
|
||||
window._CCSettings = undefined;
|
||||
|
||||
if ( !settings.debug ) {
|
||||
var uuids = settings.uuids;
|
||||
|
||||
var rawAssets = settings.rawAssets;
|
||||
var assetTypes = settings.assetTypes;
|
||||
var realRawAssets = settings.rawAssets = {};
|
||||
for (var mount in rawAssets) {
|
||||
var entries = rawAssets[mount];
|
||||
var realEntries = realRawAssets[mount] = {};
|
||||
for (var id in entries) {
|
||||
var entry = entries[id];
|
||||
var type = entry[1];
|
||||
// retrieve minified raw asset
|
||||
if (typeof type === 'number') {
|
||||
entry[1] = assetTypes[type];
|
||||
}
|
||||
// retrieve uuid
|
||||
realEntries[uuids[id] || id] = entry;
|
||||
}
|
||||
}
|
||||
|
||||
var scenes = settings.scenes;
|
||||
for (var i = 0; i < scenes.length; ++i) {
|
||||
var scene = scenes[i];
|
||||
if (typeof scene.uuid === 'number') {
|
||||
scene.uuid = uuids[scene.uuid];
|
||||
}
|
||||
}
|
||||
|
||||
var packedAssets = settings.packedAssets;
|
||||
for (var packId in packedAssets) {
|
||||
var packedIds = packedAssets[packId];
|
||||
for (var j = 0; j < packedIds.length; ++j) {
|
||||
if (typeof packedIds[j] === 'number') {
|
||||
packedIds[j] = uuids[packedIds[j]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// init engine
|
||||
var canvas;
|
||||
|
||||
if (cc.sys.isBrowser) {
|
||||
canvas = document.getElementById('GameCanvas');
|
||||
}
|
||||
|
||||
if (false) {
|
||||
var ORIENTATIONS = {
|
||||
'portrait': 1,
|
||||
'landscape left': 2,
|
||||
'landscape right': 3
|
||||
};
|
||||
BK.Director.screenMode = ORIENTATIONS[settings.orientation];
|
||||
initAdapter();
|
||||
}
|
||||
|
||||
function setLoadingDisplay () {
|
||||
// Loading splash scene
|
||||
var splash = document.getElementById('splash');
|
||||
var progressBar = splash.querySelector('.progress-bar span');
|
||||
cc.loader.onProgress = function (completedCount, totalCount, item) {
|
||||
var percent = 100 * completedCount / totalCount;
|
||||
if (progressBar) {
|
||||
progressBar.style.width = percent.toFixed(2) + '%';
|
||||
}
|
||||
};
|
||||
splash.style.display = 'block';
|
||||
progressBar.style.width = '0%';
|
||||
|
||||
cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, function () {
|
||||
splash.style.display = 'none';
|
||||
});
|
||||
}
|
||||
|
||||
var onStart = function () {
|
||||
cc.view.resizeWithBrowserSize(true);
|
||||
|
||||
if (!false && !false) {
|
||||
// UC browser on many android devices have performance issue with retina display
|
||||
if (cc.sys.os !== cc.sys.OS_ANDROID || cc.sys.browserType !== cc.sys.BROWSER_TYPE_UC) {
|
||||
cc.view.enableRetina(true);
|
||||
}
|
||||
if (cc.sys.isBrowser) {
|
||||
setLoadingDisplay();
|
||||
}
|
||||
|
||||
if (cc.sys.isMobile) {
|
||||
if (settings.orientation === 'landscape') {
|
||||
cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
else if (settings.orientation === 'portrait') {
|
||||
cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
|
||||
}
|
||||
cc.view.enableAutoFullScreen([
|
||||
cc.sys.BROWSER_TYPE_BAIDU,
|
||||
cc.sys.BROWSER_TYPE_WECHAT,
|
||||
cc.sys.BROWSER_TYPE_MOBILE_QQ,
|
||||
cc.sys.BROWSER_TYPE_MIUI,
|
||||
].indexOf(cc.sys.browserType) < 0);
|
||||
}
|
||||
|
||||
// Limit downloading max concurrent task to 2,
|
||||
// more tasks simultaneously may cause performance draw back on some android system / brwosers.
|
||||
// You can adjust the number based on your own test result, you have to set it before any loading process to take effect.
|
||||
if (cc.sys.isBrowser && cc.sys.os === cc.sys.OS_ANDROID) {
|
||||
cc.macro.DOWNLOAD_MAX_CONCURRENT = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// init assets
|
||||
cc.AssetLibrary.init({
|
||||
libraryPath: 'res/import',
|
||||
rawAssetsBase: 'res/raw-',
|
||||
rawAssets: settings.rawAssets,
|
||||
packedAssets: settings.packedAssets,
|
||||
md5AssetsMap: settings.md5AssetsMap
|
||||
});
|
||||
|
||||
if (false) {
|
||||
cc.Pipeline.Downloader.PackDownloader._doPreload("WECHAT_SUBDOMAIN", settings.WECHAT_SUBDOMAIN_DATA);
|
||||
}
|
||||
|
||||
var launchScene = settings.launchScene;
|
||||
|
||||
// load scene
|
||||
cc.director.loadScene(launchScene, null,
|
||||
function () {
|
||||
if (cc.sys.isBrowser) {
|
||||
// show canvas
|
||||
canvas.style.visibility = '';
|
||||
var div = document.getElementById('GameDiv');
|
||||
if (div) {
|
||||
div.style.backgroundImage = '';
|
||||
}
|
||||
}
|
||||
cc.loader.onProgress = null;
|
||||
console.log('Success to load scene: ' + launchScene);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// jsList
|
||||
var jsList = settings.jsList;
|
||||
|
||||
if (false) {
|
||||
BK.Script.loadlib();
|
||||
}
|
||||
else
|
||||
{
|
||||
var bundledScript = settings.debug ? 'src/project.dev.js' : 'src/project.js';
|
||||
if (jsList) {
|
||||
jsList = jsList.map(function (x) {
|
||||
return 'src/' + x;
|
||||
});
|
||||
jsList.push(bundledScript);
|
||||
}
|
||||
else {
|
||||
jsList = [bundledScript];
|
||||
}
|
||||
}
|
||||
|
||||
// anysdk scripts
|
||||
if (cc.sys.isNative && cc.sys.isMobile) {
|
||||
// jsList = jsList.concat(['src/anysdk/jsb_anysdk.js', 'src/anysdk/jsb_anysdk_constants.js']);
|
||||
}
|
||||
|
||||
var option = {
|
||||
//width: width,
|
||||
//height: height,
|
||||
id: 'GameCanvas',
|
||||
scenes: settings.scenes,
|
||||
debugMode: settings.debug ? cc.DebugMode.INFO : cc.DebugMode.ERROR,
|
||||
showFPS: (!false && !false) && settings.debug,
|
||||
frameRate: 60,
|
||||
jsList: jsList,
|
||||
groupList: settings.groupList,
|
||||
collisionMatrix: settings.collisionMatrix,
|
||||
renderMode: 0
|
||||
}
|
||||
|
||||
cc.game.run(option, onStart);
|
||||
}
|
||||
|
||||
if (false) {
|
||||
BK.Script.loadlib('GameRes://libs/qqplay-adapter.js');
|
||||
BK.Script.loadlib('GameRes://src/settings.js');
|
||||
BK.Script.loadlib();
|
||||
BK.Script.loadlib('GameRes://libs/qqplay-downloader.js');
|
||||
qqPlayDownloader.REMOTE_SERVER_ROOT = "";
|
||||
var prevPipe = cc.loader.md5Pipe || cc.loader.assetLoader;
|
||||
cc.loader.insertPipeAfter(prevPipe, qqPlayDownloader);
|
||||
// <plugin script code>
|
||||
boot();
|
||||
return;
|
||||
}
|
||||
|
||||
if (false) {
|
||||
require(window._CCSettings.debug ? 'cocos2d-js.js' : 'cocos2d-js-min.js');
|
||||
var prevPipe = cc.loader.md5Pipe || cc.loader.assetLoader;
|
||||
cc.loader.insertPipeAfter(prevPipe, wxDownloader);
|
||||
boot();
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.jsb) {
|
||||
require('src/settings.js');
|
||||
require('src/jsb_polyfill.js');
|
||||
boot();
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.document) {
|
||||
var splash = document.getElementById('splash');
|
||||
splash.style.display = 'block';
|
||||
|
||||
var cocos2d = document.createElement('script');
|
||||
cocos2d.async = true;
|
||||
cocos2d.src = window._CCSettings.debug ? 'cocos2d-js.js' : 'cocos2d-js-min.js';
|
||||
|
||||
var engineLoaded = function () {
|
||||
document.body.removeChild(cocos2d);
|
||||
cocos2d.removeEventListener('load', engineLoaded, false);
|
||||
window.eruda && eruda.init() && eruda.get('console').config.set('displayUnenumerable', false);
|
||||
boot();
|
||||
};
|
||||
cocos2d.addEventListener('load', engineLoaded, false);
|
||||
document.body.appendChild(cocos2d);
|
||||
}
|
||||
|
||||
})();
|
||||
20635
HotUpdateDemo/creator.d.ts
vendored
Normal file
20635
HotUpdateDemo/creator.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
15
HotUpdateDemo/jsconfig.json
Normal file
15
HotUpdateDemo/jsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode",
|
||||
"library",
|
||||
"local",
|
||||
"settings",
|
||||
"temp"
|
||||
]
|
||||
}
|
||||
244
HotUpdateDemo/main.js
Normal file
244
HotUpdateDemo/main.js
Normal file
@@ -0,0 +1,244 @@
|
||||
(function () {
|
||||
|
||||
if (window.cc && cc.sys.isNative) {
|
||||
var hotUpdateSearchPaths = cc.sys.localStorage.getItem('HotUpdateSearchPaths');
|
||||
if (hotUpdateSearchPaths) {
|
||||
jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths));
|
||||
}
|
||||
}
|
||||
function boot () {
|
||||
|
||||
var settings = window._CCSettings;
|
||||
window._CCSettings = undefined;
|
||||
|
||||
if ( !settings.debug ) {
|
||||
var uuids = settings.uuids;
|
||||
|
||||
var rawAssets = settings.rawAssets;
|
||||
var assetTypes = settings.assetTypes;
|
||||
var realRawAssets = settings.rawAssets = {};
|
||||
for (var mount in rawAssets) {
|
||||
var entries = rawAssets[mount];
|
||||
var realEntries = realRawAssets[mount] = {};
|
||||
for (var id in entries) {
|
||||
var entry = entries[id];
|
||||
var type = entry[1];
|
||||
// retrieve minified raw asset
|
||||
if (typeof type === 'number') {
|
||||
entry[1] = assetTypes[type];
|
||||
}
|
||||
// retrieve uuid
|
||||
realEntries[uuids[id] || id] = entry;
|
||||
}
|
||||
}
|
||||
|
||||
var scenes = settings.scenes;
|
||||
for (var i = 0; i < scenes.length; ++i) {
|
||||
var scene = scenes[i];
|
||||
if (typeof scene.uuid === 'number') {
|
||||
scene.uuid = uuids[scene.uuid];
|
||||
}
|
||||
}
|
||||
|
||||
var packedAssets = settings.packedAssets;
|
||||
for (var packId in packedAssets) {
|
||||
var packedIds = packedAssets[packId];
|
||||
for (var j = 0; j < packedIds.length; ++j) {
|
||||
if (typeof packedIds[j] === 'number') {
|
||||
packedIds[j] = uuids[packedIds[j]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// init engine
|
||||
var canvas;
|
||||
|
||||
if (cc.sys.isBrowser) {
|
||||
canvas = document.getElementById('GameCanvas');
|
||||
}
|
||||
|
||||
if (false) {
|
||||
var ORIENTATIONS = {
|
||||
'portrait': 1,
|
||||
'landscape left': 2,
|
||||
'landscape right': 3
|
||||
};
|
||||
BK.Director.screenMode = ORIENTATIONS[settings.orientation];
|
||||
initAdapter();
|
||||
}
|
||||
|
||||
function setLoadingDisplay () {
|
||||
// Loading splash scene
|
||||
var splash = document.getElementById('splash');
|
||||
var progressBar = splash.querySelector('.progress-bar span');
|
||||
cc.loader.onProgress = function (completedCount, totalCount, item) {
|
||||
var percent = 100 * completedCount / totalCount;
|
||||
if (progressBar) {
|
||||
progressBar.style.width = percent.toFixed(2) + '%';
|
||||
}
|
||||
};
|
||||
splash.style.display = 'block';
|
||||
progressBar.style.width = '0%';
|
||||
|
||||
cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, function () {
|
||||
splash.style.display = 'none';
|
||||
});
|
||||
}
|
||||
|
||||
var onStart = function () {
|
||||
cc.view.resizeWithBrowserSize(true);
|
||||
|
||||
if (!false && !false) {
|
||||
// UC browser on many android devices have performance issue with retina display
|
||||
if (cc.sys.os !== cc.sys.OS_ANDROID || cc.sys.browserType !== cc.sys.BROWSER_TYPE_UC) {
|
||||
cc.view.enableRetina(true);
|
||||
}
|
||||
if (cc.sys.isBrowser) {
|
||||
setLoadingDisplay();
|
||||
}
|
||||
|
||||
if (cc.sys.isMobile) {
|
||||
if (settings.orientation === 'landscape') {
|
||||
cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
else if (settings.orientation === 'portrait') {
|
||||
cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
|
||||
}
|
||||
cc.view.enableAutoFullScreen([
|
||||
cc.sys.BROWSER_TYPE_BAIDU,
|
||||
cc.sys.BROWSER_TYPE_WECHAT,
|
||||
cc.sys.BROWSER_TYPE_MOBILE_QQ,
|
||||
cc.sys.BROWSER_TYPE_MIUI,
|
||||
].indexOf(cc.sys.browserType) < 0);
|
||||
}
|
||||
|
||||
// Limit downloading max concurrent task to 2,
|
||||
// more tasks simultaneously may cause performance draw back on some android system / brwosers.
|
||||
// You can adjust the number based on your own test result, you have to set it before any loading process to take effect.
|
||||
if (cc.sys.isBrowser && cc.sys.os === cc.sys.OS_ANDROID) {
|
||||
cc.macro.DOWNLOAD_MAX_CONCURRENT = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// init assets
|
||||
cc.AssetLibrary.init({
|
||||
libraryPath: 'res/import',
|
||||
rawAssetsBase: 'res/raw-',
|
||||
rawAssets: settings.rawAssets,
|
||||
packedAssets: settings.packedAssets,
|
||||
md5AssetsMap: settings.md5AssetsMap
|
||||
});
|
||||
|
||||
if (false) {
|
||||
cc.Pipeline.Downloader.PackDownloader._doPreload("WECHAT_SUBDOMAIN", settings.WECHAT_SUBDOMAIN_DATA);
|
||||
}
|
||||
|
||||
var launchScene = settings.launchScene;
|
||||
|
||||
// load scene
|
||||
cc.director.loadScene(launchScene, null,
|
||||
function () {
|
||||
if (cc.sys.isBrowser) {
|
||||
// show canvas
|
||||
canvas.style.visibility = '';
|
||||
var div = document.getElementById('GameDiv');
|
||||
if (div) {
|
||||
div.style.backgroundImage = '';
|
||||
}
|
||||
}
|
||||
cc.loader.onProgress = null;
|
||||
console.log('Success to load scene: ' + launchScene);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// jsList
|
||||
var jsList = settings.jsList;
|
||||
|
||||
if (false) {
|
||||
BK.Script.loadlib();
|
||||
}
|
||||
else
|
||||
{
|
||||
var bundledScript = settings.debug ? 'src/project.dev.js' : 'src/project.js';
|
||||
if (jsList) {
|
||||
jsList = jsList.map(function (x) {
|
||||
return 'src/' + x;
|
||||
});
|
||||
jsList.push(bundledScript);
|
||||
}
|
||||
else {
|
||||
jsList = [bundledScript];
|
||||
}
|
||||
}
|
||||
|
||||
// anysdk scripts
|
||||
if (cc.sys.isNative && cc.sys.isMobile) {
|
||||
// jsList = jsList.concat(['src/anysdk/jsb_anysdk.js', 'src/anysdk/jsb_anysdk_constants.js']);
|
||||
}
|
||||
|
||||
var option = {
|
||||
//width: width,
|
||||
//height: height,
|
||||
id: 'GameCanvas',
|
||||
scenes: settings.scenes,
|
||||
debugMode: settings.debug ? cc.DebugMode.INFO : cc.DebugMode.ERROR,
|
||||
showFPS: (!false && !false) && settings.debug,
|
||||
frameRate: 60,
|
||||
jsList: jsList,
|
||||
groupList: settings.groupList,
|
||||
collisionMatrix: settings.collisionMatrix,
|
||||
renderMode: 0
|
||||
}
|
||||
|
||||
cc.game.run(option, onStart);
|
||||
}
|
||||
|
||||
if (false) {
|
||||
BK.Script.loadlib('GameRes://libs/qqplay-adapter.js');
|
||||
BK.Script.loadlib('GameRes://src/settings.js');
|
||||
BK.Script.loadlib();
|
||||
BK.Script.loadlib('GameRes://libs/qqplay-downloader.js');
|
||||
qqPlayDownloader.REMOTE_SERVER_ROOT = "";
|
||||
var prevPipe = cc.loader.md5Pipe || cc.loader.assetLoader;
|
||||
cc.loader.insertPipeAfter(prevPipe, qqPlayDownloader);
|
||||
// <plugin script code>
|
||||
boot();
|
||||
return;
|
||||
}
|
||||
|
||||
if (false) {
|
||||
require(window._CCSettings.debug ? 'cocos2d-js.js' : 'cocos2d-js-min.js');
|
||||
var prevPipe = cc.loader.md5Pipe || cc.loader.assetLoader;
|
||||
cc.loader.insertPipeAfter(prevPipe, wxDownloader);
|
||||
boot();
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.jsb) {
|
||||
require('src/settings.js');
|
||||
require('src/jsb_polyfill.js');
|
||||
boot();
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.document) {
|
||||
var splash = document.getElementById('splash');
|
||||
splash.style.display = 'block';
|
||||
|
||||
var cocos2d = document.createElement('script');
|
||||
cocos2d.async = true;
|
||||
cocos2d.src = window._CCSettings.debug ? 'cocos2d-js.js' : 'cocos2d-js-min.js';
|
||||
|
||||
var engineLoaded = function () {
|
||||
document.body.removeChild(cocos2d);
|
||||
cocos2d.removeEventListener('load', engineLoaded, false);
|
||||
window.eruda && eruda.init() && eruda.get('console').config.set('displayUnenumerable', false);
|
||||
boot();
|
||||
};
|
||||
cocos2d.addEventListener('load', engineLoaded, false);
|
||||
document.body.appendChild(cocos2d);
|
||||
}
|
||||
|
||||
})();
|
||||
4
HotUpdateDemo/project.json
Normal file
4
HotUpdateDemo/project.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"engine": "cocos2d-html5",
|
||||
"packages": "packages"
|
||||
}
|
||||
41
HotUpdateDemo/settings/builder.json
Normal file
41
HotUpdateDemo/settings/builder.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"appKey": "",
|
||||
"appSecret": "",
|
||||
"encryptJs": true,
|
||||
"excludeScenes": [],
|
||||
"fb-instant-games": {},
|
||||
"includeAnySDK": false,
|
||||
"includeSDKBox": false,
|
||||
"inlineSpriteFrames": true,
|
||||
"inlineSpriteFrames_native": true,
|
||||
"jailbreakPlatform": false,
|
||||
"md5Cache": false,
|
||||
"mergeStartScene": false,
|
||||
"oauthLoginServer": "",
|
||||
"optimizeHotUpdate": false,
|
||||
"orientation": {
|
||||
"landscapeLeft": true,
|
||||
"landscapeRight": true,
|
||||
"portrait": false,
|
||||
"upsideDown": false
|
||||
},
|
||||
"packageName": "org.cocos2d.helloworld",
|
||||
"privateKey": "",
|
||||
"qqplay": {
|
||||
"REMOTE_SERVER_ROOT": "",
|
||||
"orientation": "portrait"
|
||||
},
|
||||
"renderMode": "0",
|
||||
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||
"title": "hello_world",
|
||||
"webOrientation": "auto",
|
||||
"wechatgame": {
|
||||
"REMOTE_SERVER_ROOT": "",
|
||||
"appid": "wx6ac3f5090a6b99c5",
|
||||
"isSubdomain": false,
|
||||
"orientation": "portrait",
|
||||
"subContext": ""
|
||||
},
|
||||
"xxteaKey": "6c430076-9042-40",
|
||||
"zipCompressJs": true
|
||||
}
|
||||
7
HotUpdateDemo/settings/builder.panel.json
Normal file
7
HotUpdateDemo/settings/builder.panel.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"excludeScenes": [],
|
||||
"packageName": "org.cocos2d.helloworld",
|
||||
"platform": "web-mobile",
|
||||
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||
"title": "HelloWorld"
|
||||
}
|
||||
28
HotUpdateDemo/settings/project.json
Normal file
28
HotUpdateDemo/settings/project.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"collision-matrix": [
|
||||
[
|
||||
true
|
||||
]
|
||||
],
|
||||
"excluded-modules": [],
|
||||
"group-list": [
|
||||
"default"
|
||||
],
|
||||
"start-scene": "current",
|
||||
"design-resolution-width": 960,
|
||||
"design-resolution-height": 640,
|
||||
"fit-width": false,
|
||||
"fit-height": true,
|
||||
"use-project-simulator-setting": false,
|
||||
"simulator-orientation": false,
|
||||
"use-customize-simulator": false,
|
||||
"simulator-resolution": {
|
||||
"width": 960,
|
||||
"height": 640
|
||||
},
|
||||
"cocos-analytics": {
|
||||
"enable": false,
|
||||
"appID": "13798",
|
||||
"appSecret": "959b3ac0037d0f3c2fdce94f8421a9b2"
|
||||
}
|
||||
}
|
||||
BIN
HotUpdateDemo/template-banner.png
Normal file
BIN
HotUpdateDemo/template-banner.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
5
HotUpdateDemo/template.json
Normal file
5
HotUpdateDemo/template.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "TEMPLATES.helloworld.name",
|
||||
"desc": "TEMPLATES.helloworld.desc",
|
||||
"banner": "template-banner.png"
|
||||
}
|
||||
1
HotUpdateDemo/version_generator.bat
Normal file
1
HotUpdateDemo/version_generator.bat
Normal file
@@ -0,0 +1 @@
|
||||
node version_generator.js -v 1.0.1 -u http://192.168.0.124/remote-assets/ -s build/jsb-binary/ -d assets/
|
||||
115
HotUpdateDemo/version_generator.js
Normal file
115
HotUpdateDemo/version_generator.js
Normal file
@@ -0,0 +1,115 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var crypto = require('crypto');
|
||||
|
||||
var manifest = {
|
||||
packageUrl: 'http://localhost/tutorial-hot-update/remote-assets/',
|
||||
remoteManifestUrl: 'http://localhost/tutorial-hot-update/remote-assets/project.manifest',
|
||||
remoteVersionUrl: 'http://localhost/tutorial-hot-update/remote-assets/version.manifest',
|
||||
version: '1.0.0',
|
||||
assets: {},
|
||||
searchPaths: []
|
||||
};
|
||||
|
||||
var dest = './remote-assets/';
|
||||
var src = './jsb/';
|
||||
|
||||
// Parse arguments
|
||||
var i = 2;
|
||||
while ( i < process.argv.length) {
|
||||
var arg = process.argv[i];
|
||||
|
||||
switch (arg) {
|
||||
case '--url' :
|
||||
case '-u' :
|
||||
var url = process.argv[i+1];
|
||||
manifest.packageUrl = url;
|
||||
manifest.remoteManifestUrl = url + 'project.manifest';
|
||||
manifest.remoteVersionUrl = url + 'version.manifest';
|
||||
i += 2;
|
||||
break;
|
||||
case '--version' :
|
||||
case '-v' :
|
||||
manifest.version = process.argv[i+1];
|
||||
i += 2;
|
||||
break;
|
||||
case '--src' :
|
||||
case '-s' :
|
||||
src = process.argv[i+1];
|
||||
i += 2;
|
||||
break;
|
||||
case '--dest' :
|
||||
case '-d' :
|
||||
dest = process.argv[i+1];
|
||||
i += 2;
|
||||
break;
|
||||
default :
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function readDir (dir, obj) {
|
||||
var stat = fs.statSync(dir);
|
||||
if (!stat.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
var subpaths = fs.readdirSync(dir), subpath, size, md5, compressed, relative;
|
||||
for (var i = 0; i < subpaths.length; ++i) {
|
||||
if (subpaths[i][0] === '.') {
|
||||
continue;
|
||||
}
|
||||
subpath = path.join(dir, subpaths[i]);
|
||||
stat = fs.statSync(subpath);
|
||||
if (stat.isDirectory()) {
|
||||
readDir(subpath, obj);
|
||||
}
|
||||
else if (stat.isFile()) {
|
||||
// Size in Bytes
|
||||
size = stat['size'];
|
||||
md5 = crypto.createHash('md5').update(fs.readFileSync(subpath, 'binary')).digest('hex');
|
||||
compressed = path.extname(subpath).toLowerCase() === '.zip';
|
||||
|
||||
relative = path.relative(src, subpath);
|
||||
relative = relative.replace(/\\/g, '/');
|
||||
relative = encodeURI(relative);
|
||||
obj[relative] = {
|
||||
'size' : size,
|
||||
'md5' : md5
|
||||
};
|
||||
if (compressed) {
|
||||
obj[relative].compressed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mkdirSync = function (path) {
|
||||
try {
|
||||
fs.mkdirSync(path);
|
||||
} catch(e) {
|
||||
if ( e.code != 'EEXIST' ) throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate res and src folder
|
||||
readDir(path.join(src, 'src'), manifest.assets);
|
||||
readDir(path.join(src, 'res'), manifest.assets);
|
||||
|
||||
var destManifest = path.join(dest, 'project.manifest');
|
||||
var destVersion = path.join(dest, 'version.manifest');
|
||||
|
||||
mkdirSync(dest);
|
||||
|
||||
fs.writeFile(destManifest, JSON.stringify(manifest), (err) => {
|
||||
if (err) throw err;
|
||||
console.log('Manifest successfully generated');
|
||||
});
|
||||
|
||||
delete manifest.assets;
|
||||
delete manifest.searchPaths;
|
||||
fs.writeFile(destVersion, JSON.stringify(manifest), (err) => {
|
||||
if (err) throw err;
|
||||
console.log('Version successfully generated');
|
||||
});
|
||||
Reference in New Issue
Block a user