Commit 603b660d authored by liujiangnan's avatar liujiangnan

feat: 预加载相关

parent b0d768b7
......@@ -298,16 +298,16 @@
"__id__": 22
},
{
"__id__": 98
"__id__": 100
}
],
"_active": true,
"_components": [
{
"__id__": 133
"__id__": 135
},
{
"__id__": 134
"__id__": 136
}
],
"_prefab": null,
......@@ -1077,12 +1077,15 @@
},
{
"__id__": 90
},
{
"__id__": 97
}
],
"_active": true,
"_components": [
{
"__id__": 97
"__id__": 99
}
],
"_prefab": null,
......@@ -4689,6 +4692,101 @@
},
"_id": "27BjR9SvZAhY/aQBzv9ezW"
},
{
"__type__": "cc.Node",
"_name": "ProgressLabel",
"_objFlags": 0,
"_parent": {
"__id__": 22
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 98
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 88.95,
"height": 50.4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-17,
-185,
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": "4a4jPKza9MU70DqzTZHZ00"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 97
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "0 / 0",
"_N$string": "0 / 0",
"_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": "ee0WrmR8hIQbOtXJqrMoQ5"
},
{
"__type__": "cc.Widget",
"_name": "",
......@@ -4725,25 +4823,25 @@
},
"_children": [
{
"__id__": 99
"__id__": 101
},
{
"__id__": 105
"__id__": 107
},
{
"__id__": 108
"__id__": 110
},
{
"__id__": 116
"__id__": 118
},
{
"__id__": 124
"__id__": 126
}
],
"_active": true,
"_components": [
{
"__id__": 132
"__id__": 134
}
],
"_prefab": null,
......@@ -4799,20 +4897,20 @@
"_name": "content",
"_objFlags": 0,
"_parent": {
"__id__": 98
"__id__": 100
},
"_children": [
{
"__id__": 100
"__id__": 102
}
],
"_active": false,
"_components": [
{
"__id__": 103
"__id__": 105
},
{
"__id__": 104
"__id__": 106
}
],
"_prefab": null,
......@@ -4868,16 +4966,16 @@
"_name": "label",
"_objFlags": 0,
"_parent": {
"__id__": 99
"__id__": 101
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 101
"__id__": 103
},
{
"__id__": 102
"__id__": 104
}
],
"_prefab": null,
......@@ -4933,7 +5031,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 100
"__id__": 102
},
"_enabled": true,
"_materials": [
......@@ -4966,7 +5064,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 100
"__id__": 102
},
"_enabled": true,
"alignMode": 1,
......@@ -4993,7 +5091,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 99
"__id__": 101
},
"_enabled": true,
"_layoutSize": {
......@@ -5025,7 +5123,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 99
"__id__": 101
},
"_enabled": true,
"alignMode": 2,
......@@ -5052,16 +5150,16 @@
"_name": "bg",
"_objFlags": 0,
"_parent": {
"__id__": 98
"__id__": 100
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 106
"__id__": 108
},
{
"__id__": 107
"__id__": 109
}
],
"_prefab": null,
......@@ -5117,7 +5215,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 105
"__id__": 107
},
"_enabled": true,
"_materials": [
......@@ -5149,7 +5247,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 105
"__id__": 107
},
"_enabled": true,
"alignMode": 1,
......@@ -5176,26 +5274,26 @@
"_name": "Console",
"_objFlags": 0,
"_parent": {
"__id__": 98
"__id__": 100
},
"_children": [
{
"__id__": 109
"__id__": 111
}
],
"_active": false,
"_components": [
{
"__id__": 112
"__id__": 114
},
{
"__id__": 113
"__id__": 115
},
{
"__id__": 114
"__id__": 116
},
{
"__id__": 115
"__id__": 117
}
],
"_prefab": null,
......@@ -5251,16 +5349,16 @@
"_name": "content",
"_objFlags": 0,
"_parent": {
"__id__": 108
"__id__": 110
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 110
"__id__": 112
},
{
"__id__": 111
"__id__": 113
}
],
"_prefab": null,
......@@ -5316,7 +5414,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 109
"__id__": 111
},
"_enabled": true,
"_layoutSize": {
......@@ -5348,7 +5446,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 109
"__id__": 111
},
"_enabled": true,
"alignMode": 1,
......@@ -5375,7 +5473,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 108
"__id__": 110
},
"_enabled": true,
"alignMode": 2,
......@@ -5402,7 +5500,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 108
"__id__": 110
},
"_enabled": true,
"_materials": [
......@@ -5422,7 +5520,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 108
"__id__": 110
},
"_enabled": true,
"horizontal": false,
......@@ -5434,10 +5532,10 @@
"scrollEvents": [],
"cancelInnerEvents": true,
"_N$content": {
"__id__": 109
"__id__": 111
},
"content": {
"__id__": 109
"__id__": 111
},
"_id": "43wBGhGBpFP7OYyNM+j0Ho"
},
......@@ -5446,7 +5544,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 108
"__id__": 110
},
"_enabled": true,
"_layoutSize": {
......@@ -5478,20 +5576,20 @@
"_name": "BtnClose",
"_objFlags": 0,
"_parent": {
"__id__": 98
"__id__": 100
},
"_children": [
{
"__id__": 117
"__id__": 119
}
],
"_active": false,
"_components": [
{
"__id__": 122
"__id__": 124
},
{
"__id__": 123
"__id__": 125
}
],
"_prefab": null,
......@@ -5547,20 +5645,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 116
"__id__": 118
},
"_children": [
{
"__id__": 118
"__id__": 120
}
],
"_active": true,
"_components": [
{
"__id__": 120
"__id__": 122
},
{
"__id__": 121
"__id__": 123
}
],
"_prefab": null,
......@@ -5616,13 +5714,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 117
"__id__": 119
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 119
"__id__": 121
}
],
"_prefab": null,
......@@ -5678,7 +5776,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 118
"__id__": 120
},
"_enabled": true,
"_materials": [
......@@ -5711,7 +5809,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 117
"__id__": 119
},
"_enabled": true,
"_materials": [
......@@ -5743,7 +5841,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 117
"__id__": 119
},
"_enabled": true,
"alignMode": 0,
......@@ -5770,7 +5868,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 116
"__id__": 118
},
"_enabled": true,
"_normalMaterial": null,
......@@ -5843,7 +5941,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 117
"__id__": 119
},
"_id": "54SC9WcmBAZ6cTznyI0o+3"
},
......@@ -5852,7 +5950,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 116
"__id__": 118
},
"_enabled": true,
"alignMode": 1,
......@@ -5879,20 +5977,20 @@
"_name": "BtnOpen",
"_objFlags": 0,
"_parent": {
"__id__": 98
"__id__": 100
},
"_children": [
{
"__id__": 125
"__id__": 127
}
],
"_active": true,
"_components": [
{
"__id__": 130
"__id__": 132
},
{
"__id__": 131
"__id__": 133
}
],
"_prefab": null,
......@@ -5948,20 +6046,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 124
"__id__": 126
},
"_children": [
{
"__id__": 126
"__id__": 128
}
],
"_active": true,
"_components": [
{
"__id__": 128
"__id__": 130
},
{
"__id__": 129
"__id__": 131
}
],
"_prefab": null,
......@@ -6017,13 +6115,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 125
"__id__": 127
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 127
"__id__": 129
}
],
"_prefab": null,
......@@ -6079,7 +6177,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 126
"__id__": 128
},
"_enabled": true,
"_materials": [
......@@ -6112,7 +6210,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 125
"__id__": 127
},
"_enabled": true,
"_materials": [
......@@ -6144,7 +6242,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 125
"__id__": 127
},
"_enabled": true,
"alignMode": 0,
......@@ -6171,7 +6269,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 124
"__id__": 126
},
"_enabled": true,
"_normalMaterial": null,
......@@ -6244,7 +6342,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 125
"__id__": 127
},
"_id": "81HoUuRyJOppi+n4Av/u0p"
},
......@@ -6253,7 +6351,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 124
"__id__": 126
},
"_enabled": true,
"alignMode": 1,
......@@ -6280,7 +6378,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 98
"__id__": 100
},
"_enabled": true,
"alignMode": 1,
......
......@@ -2,7 +2,8 @@
import {initAir} from './air';
cc.Class({
extends: cc.Component,
properties: {},
properties: {
},
callNetworkApiPost(uri, data, callBack) {
const xhr = new XMLHttpRequest();
......@@ -38,10 +39,22 @@ cc.Class({
xhr.send();
},
// 需要预加载的数量
preloadCount: null,
// 统计已加载的数量
loadedCount: null,
onLoad() {
this.preloadCount = 0;
this.loadedCount = 0;
initAir(this);
this.preloadBundle();
this.preloadSource();
if(!window.preloadBundleAndSourcesFlag){
// 只加载一次就行了
window.preloadBundleAndSourcesFlag = true;
cc.find("middleLayer/ui/ProgressLabel").active = true;
this.preloadBundle();
this.preloadSource();
}
},
start() {
......@@ -73,16 +86,7 @@ cc.Class({
middleLayer.log("middleLayer.log('像这样在这里打log')");
},
// 需要预加载的数量
preloadCount: 0,
// 统计已加载的数量
loadedCount: 0,
preloadBundle() {
if(window.air.bundleLoaded){
// 限制只加载一次
return;
}
window.air.bundleLoaded = true;
let platform = "web_desktop";
if(cc.sys.os == cc.sys.OS_IOS){
platform = "ios";
......@@ -107,6 +111,7 @@ cc.Class({
bundle.preloadScene(scene.sceneName, ()=>{}, ()=>{
console.log(`${scene.sceneName}场景预加载结束`);
_this.loadedCount ++;
_this.updateProcessBar();
i++;
if(i<scenes.length){
setTimeout(() => {
......@@ -123,11 +128,6 @@ cc.Class({
},
preloadSource() {
if(window.air.sourceLoaded){
// 限制只加载一次
return;
}
window.air.sourceLoaded = true;
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allresources`, {orgid: 507}, (datastr) => {
const data = JSON.parse(datastr);
const rows = data.rows;
......@@ -142,6 +142,7 @@ cc.Class({
console.log(err)
}
this.loadedCount ++;
this.updateProcessBar();
if (i === len-1) {
batchLoad();
}
......@@ -153,6 +154,14 @@ cc.Class({
});
},
updateProcessBar() {
const label = cc.find("middleLayer/ui/ProgressLabel").getComponent(cc.Label);
label.string = `正在加载:${this.loadedCount} / ${this.preloadCount}`;
if(this.loadedCount > this.preloadCount * 0.99){
cc.find("middleLayer/ui/ProgressLabel").active = false;
}
},
asyncDelayLog(str) {
console.log(str);
return new Promise((resolve, reject) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment