Commit f457fb4c authored by 李维's avatar 李维

优化运行内存占用

parent 07ad5cb2
......@@ -2222,7 +2222,7 @@
}
],
"_prefab": null,
"_opacity": 255,
"_opacity": 0,
"_color": {
"__type__": "cc.Color",
"r": 255,
......@@ -5714,7 +5714,7 @@
}
],
"_prefab": null,
"_opacity": 255,
"_opacity": 0,
"_color": {
"__type__": "cc.Color",
"r": 255,
......@@ -6661,7 +6661,7 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 99.4,
"width": 0,
"height": 50.4
},
"_anchorPoint": {
......@@ -6917,7 +6917,7 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 133.48,
"width": 0,
"height": 50.4
},
"_anchorPoint": {
......@@ -13501,7 +13501,7 @@
}
],
"_prefab": null,
"_opacity": 255,
"_opacity": 0,
"_color": {
"__type__": "cc.Color",
"r": 255,
......@@ -14799,7 +14799,7 @@
"horizontal": true,
"vertical": false,
"inertia": true,
"brake": 0.3,
"brake": 0.1,
"elastic": true,
"bounceDuration": 0.23,
"scrollEvents": [],
......@@ -14823,11 +14823,7 @@
"_parent": {
"__id__": 326
},
"_children": [
{
"__id__": 329
}
],
"_children": [],
"_active": true,
"_components": [
{
......@@ -14890,6 +14886,9 @@
"__id__": 319
},
"_children": [
{
"__id__": 327
},
{
"__id__": 325
}
......@@ -14897,10 +14896,10 @@
"_active": true,
"_components": [
{
"__id__": 327
"__id__": 355
},
{
"__id__": 328
"__id__": 356
}
],
"_prefab": null,
......@@ -14951,78 +14950,31 @@
"groupIndex": 0,
"_id": "16Ee3RAltNSq6ywFjGSc+9"
},
{
"__type__": "cc.Mask",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 326
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_spriteFrame": null,
"_type": 0,
"_segments": 64,
"_N$alphaThreshold": 0,
"_N$inverted": false,
"_id": "87fhMa41NMAroj+avlPSZC"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 326
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 40,
"_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": 1920,
"_originalHeight": 0,
"_id": "becVdD2FBPx7Yq9xNFms1v"
},
{
"__type__": "cc.Node",
"_name": "item",
"_objFlags": 0,
"_parent": {
"__id__": 325
"__id__": 326
},
"_children": [
{
"__id__": 330
"__id__": 328
},
{
"__id__": 332
"__id__": 330
},
{
"__id__": 335
"__id__": 333
}
],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 355
"__id__": 353
},
{
"__id__": 356
"__id__": 354
}
],
"_prefab": null,
......@@ -15048,7 +15000,7 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
85.5,
-874.5,
0,
0,
0,
......@@ -15078,13 +15030,13 @@
"_name": "label",
"_objFlags": 0,
"_parent": {
"__id__": 329
"__id__": 327
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 331
"__id__": 329
}
],
"_prefab": null,
......@@ -15140,7 +15092,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 330
"__id__": 328
},
"_enabled": true,
"_materials": [
......@@ -15175,16 +15127,16 @@
"_name": "cards",
"_objFlags": 0,
"_parent": {
"__id__": 329
"__id__": 327
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 333
"__id__": 331
},
{
"__id__": 334
"__id__": 332
}
],
"_prefab": null,
......@@ -15240,7 +15192,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 332
"__id__": 330
},
"_enabled": false,
"_materials": [
......@@ -15272,7 +15224,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 332
"__id__": 330
},
"_enabled": true,
"_layoutSize": {
......@@ -15304,29 +15256,29 @@
"_name": "sub_item",
"_objFlags": 0,
"_parent": {
"__id__": 329
"__id__": 327
},
"_children": [
{
"__id__": 336
"__id__": 334
},
{
"__id__": 343
"__id__": 341
},
{
"__id__": 345
"__id__": 343
},
{
"__id__": 349
"__id__": 347
},
{
"__id__": 350
"__id__": 348
}
],
"_active": false,
"_components": [
{
"__id__": 354
"__id__": 352
}
],
"_prefab": null,
......@@ -15382,14 +15334,14 @@
"_name": "point",
"_objFlags": 0,
"_parent": {
"__id__": 335
"__id__": 333
},
"_children": [
{
"__id__": 337
"__id__": 335
},
{
"__id__": 339
"__id__": 337
}
],
"_active": true,
......@@ -15447,13 +15399,13 @@
"_name": "bg",
"_objFlags": 0,
"_parent": {
"__id__": 336
"__id__": 334
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 338
"__id__": 336
}
],
"_prefab": null,
......@@ -15509,7 +15461,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 337
"__id__": 335
},
"_enabled": true,
"_materials": [
......@@ -15541,17 +15493,17 @@
"_name": "blue",
"_objFlags": 0,
"_parent": {
"__id__": 336
"__id__": 334
},
"_children": [
{
"__id__": 340
"__id__": 338
}
],
"_active": true,
"_components": [
{
"__id__": 342
"__id__": 340
}
],
"_prefab": null,
......@@ -15607,13 +15559,13 @@
"_name": "icon_check",
"_objFlags": 0,
"_parent": {
"__id__": 339
"__id__": 337
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 341
"__id__": 339
}
],
"_prefab": null,
......@@ -15669,7 +15621,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 340
"__id__": 338
},
"_enabled": true,
"_materials": [
......@@ -15701,7 +15653,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 339
"__id__": 337
},
"_enabled": true,
"_materials": [
......@@ -15733,13 +15685,13 @@
"_name": "label",
"_objFlags": 0,
"_parent": {
"__id__": 335
"__id__": 333
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 344
"__id__": 342
}
],
"_prefab": null,
......@@ -15795,7 +15747,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 343
"__id__": 341
},
"_enabled": true,
"_materials": [
......@@ -15830,17 +15782,17 @@
"_name": "mask",
"_objFlags": 0,
"_parent": {
"__id__": 335
"__id__": 333
},
"_children": [
{
"__id__": 346
"__id__": 344
}
],
"_active": true,
"_components": [
{
"__id__": 348
"__id__": 346
}
],
"_prefab": null,
......@@ -15896,13 +15848,13 @@
"_name": "pic_frame",
"_objFlags": 0,
"_parent": {
"__id__": 345
"__id__": 343
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 347
"__id__": 345
}
],
"_prefab": null,
......@@ -15958,7 +15910,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 346
"__id__": 344
},
"_enabled": false,
"_materials": [
......@@ -15990,7 +15942,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 345
"__id__": 343
},
"_enabled": true,
"_materials": [
......@@ -16012,7 +15964,7 @@
"_name": "pint_layer",
"_objFlags": 0,
"_parent": {
"__id__": 335
"__id__": 333
},
"_children": [],
"_active": true,
......@@ -16070,17 +16022,17 @@
"_name": "bg_cover_mask",
"_objFlags": 0,
"_parent": {
"__id__": 335
"__id__": 333
},
"_children": [
{
"__id__": 351
"__id__": 349
}
],
"_active": true,
"_components": [
{
"__id__": 353
"__id__": 351
}
],
"_prefab": null,
......@@ -16136,13 +16088,13 @@
"_name": "icon_lock",
"_objFlags": 0,
"_parent": {
"__id__": 350
"__id__": 348
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 352
"__id__": 350
}
],
"_prefab": null,
......@@ -16198,7 +16150,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 351
"__id__": 349
},
"_enabled": true,
"_materials": [
......@@ -16230,7 +16182,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 350
"__id__": 348
},
"_enabled": true,
"_materials": [
......@@ -16262,7 +16214,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 335
"__id__": 333
},
"_enabled": true,
"_materials": [
......@@ -16294,7 +16246,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 329
"__id__": 327
},
"_enabled": true,
"_materials": [
......@@ -16326,7 +16278,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 329
"__id__": 327
},
"_enabled": true,
"_layoutSize": {
......@@ -16353,6 +16305,53 @@
"_N$affectedByScale": false,
"_id": "78jW+6mPJHeJ7L1xUmTDvX"
},
{
"__type__": "cc.Mask",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 326
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_spriteFrame": null,
"_type": 0,
"_segments": 64,
"_N$alphaThreshold": 0,
"_N$inverted": false,
"_id": "87fhMa41NMAroj+avlPSZC"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 326
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 40,
"_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": 1920,
"_originalHeight": 0,
"_id": "becVdD2FBPx7Yq9xNFms1v"
},
{
"__type__": "cc.Layout",
"_name": "",
......@@ -18386,7 +18385,7 @@
}
],
"_prefab": null,
"_opacity": 255,
"_opacity": 0,
"_color": {
"__type__": "cc.Color",
"r": 255,
......@@ -34699,7 +34698,7 @@
}
],
"_prefab": null,
"_opacity": 255,
"_opacity": 0,
"_color": {
"__type__": "cc.Color",
"r": 255,
......@@ -36567,7 +36566,7 @@
}
],
"_prefab": null,
"_opacity": 255,
"_opacity": 0,
"_color": {
"__type__": "cc.Color",
"r": 255,
......@@ -39148,7 +39147,7 @@
}
],
"_prefab": null,
"_opacity": 255,
"_opacity": 0,
"_color": {
"__type__": "cc.Color",
"r": 255,
......@@ -43629,7 +43628,7 @@
}
],
"_prefab": null,
"_opacity": 255,
"_opacity": 0,
"_color": {
"__type__": "cc.Color",
"r": 255,
......@@ -46176,7 +46175,7 @@
}
],
"_prefab": null,
"_opacity": 255,
"_opacity": 0,
"_color": {
"__type__": "cc.Color",
"r": 255,
......
......@@ -45,7 +45,6 @@ export default class MissionPageClass extends PageComponentBaseClass {
configData = [];
userInfo = null
nameLblStr = "";
headSprStr = "";
handleClickBackBtn() {
const vc = this.Viewer.getComponent("PageViewer");
......@@ -76,6 +75,15 @@ export default class MissionPageClass extends PageComponentBaseClass {
// unitConfigData 是从Unit层传进来的config配置参数,如果是从模板返回到Mission层,这个配置文件是没有的
const customBgUrl = unitConfigData && unitConfigData.mission_bg_url ? unitConfigData.mission_bg_url : "";
this.initCustomBg(customBgUrl);
const headSprStr = unitConfigData && unitConfigData.teacher_avatar ? unitConfigData.teacher_avatar : "";
if(headSprStr) {
getSprNodeByUrl(headSprStr, (spr) => {
this.headNode.addChild(spr.node);
spr.srcBlendFactor = cc.macro.BlendFactor.ONE;
setSprNodeMaxLen(spr.node, this.headNode.width, this.headNode.height);
this.headNode.active = true;
});
}
this.loading.active = true;
this.scrollView.opacity = 0;
......@@ -125,12 +133,17 @@ export default class MissionPageClass extends PageComponentBaseClass {
let _data = JSON.parse(rows[0].data)
this.configData = _data.pages;
this.nameLblStr = _data.title;
this.headSprStr = _data.teacher_avatar;
bgImageUrl = _data.bg_image_url;
}
}
this.refreshConfig()
if (this.configData && this.configData.length > 0) {
this.btn_preview.active = true;
this.headNode.active = false;
} else {
this.btn_preview.active = false;
this.headNode.active = false;
}
// 数据汇报
if (this.node["pData"] && this.node["pData"].id != null) {
......@@ -147,22 +160,6 @@ export default class MissionPageClass extends PageComponentBaseClass {
}
}
refreshConfig() {
if (this.configData && this.configData.length > 0) {
this.btn_preview.active = true;
this.headNode.active = false;
getSprNodeByUrl(this.headSprStr, (spr) => {
this.headNode.addChild(spr.node);
spr.srcBlendFactor = cc.macro.BlendFactor.ONE;
setSprNodeMaxLen(spr.node, this.headNode.width, this.headNode.height);
this.headNode.active = true;
});
} else {
this.btn_preview.active = false;
this.headNode.active = false;
}
}
getConfigData() {
return this.configData
}
......
......@@ -20,16 +20,16 @@ export default class PageComponentBaseClass extends cc.Component {
initPageHook(node: cc.Node) {
// 注册PageViwer发来的beforeMount事件 [页面即将被显示]
node.on("beforeMount", ()=>this.beforeMount());
node.on("beforeMount", (data)=>this.beforeMount(data));
// 注册PageViwer发来的mounted事件 [页面已经切换完毕]
node.on("mounted", ()=>this.mounted());
node.on("mounted", (data)=>this.mounted(data));
// 注册PageViwer发来的unmounted事件 [页面已经切换完毕]
node.on("unmounted", ()=>this.unmounted());
node.on("unmounted", (data)=>this.unmounted(data));
}
// 页面即将被显示
beforeMount() {}
mounted() {}
unmounted() {}
beforeMount(data) {}
mounted(data) {}
unmounted(data) {}
// update (dt) {}
}
......@@ -162,14 +162,23 @@ export default class PageViewerClass extends cc.Component {
}
switchView(inPage, outPage, aniType) {
// 页面切换两秒后 执行垃圾回收
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS || cc.sys.os == cc.sys.OS_ANDROID) {
setTimeout(()=>{
cc.sys.garbageCollect()
}, 2000)
}
if(inPage.active == false) {
inPage.active = true
}
if(aniType == "leftIn" || aniType == "rightIn") {
let targetX = -this.node.width;
if(aniType == "leftIn") {
targetX = -targetX
}
inPage.active = true;
inPage.opacity = 255;
inPage.x = -targetX;
outPage.active = true;
outPage.opacity = 255;
cc.tween(inPage)
.to(0.2, {
x: 0
......@@ -181,7 +190,7 @@ export default class PageViewerClass extends cc.Component {
x: targetX
})
.call(() => {
outPage.active = false;
outPage.opacity = 0;
outPage.emit("unmounted")
resovle(true)
})
......@@ -193,8 +202,8 @@ export default class PageViewerClass extends cc.Component {
targetY = -targetY
}
inPage.y = -targetY;
inPage.active = true;
outPage.active = true;
inPage.opacity = 255;
outPage.opacity = 255;
cc.tween(inPage)
.to(0.2, {
y: 0
......@@ -206,7 +215,7 @@ export default class PageViewerClass extends cc.Component {
y: targetY
})
.call(() => {
outPage.active = false;
outPage.opacity = 0;
outPage.emit("unmounted")
resovle(true)
})
......@@ -214,16 +223,16 @@ export default class PageViewerClass extends cc.Component {
})
} else {
if(outPage) {
outPage.active = false;
outPage.opacity = 0;
outPage.emit("unmounted")
} else {
// 未传移除页面 则全部移除
for(let key in PageMap) {
this[PageMap[key]].active = false;
this[PageMap[key]].opacity = 0;
this[PageMap[key]].emit("unmounted");
}
}
inPage.active = true;
inPage.opacity = 255;
inPage.x = 0;
inPage.y = 0;
return new Promise((resovle, reject)=>{
......@@ -232,6 +241,7 @@ export default class PageViewerClass extends cc.Component {
}, 200)
})
}
}
// update (dt) {}
}
......@@ -48,30 +48,34 @@ export default class UnitPageClass extends PageComponentBaseClass {
// 调用父类中的初始化页面生命周期钩子方法
super.initPageHook(this.node);
this.initBg();
this.listItem = cc.find("view/content/item", this.unitScrollView);
this.listItem = cc.find("view/item", this.unitScrollView);
}
// 页面即将显示
async beforeMount() {
this.isDestory = false;
const svNode = this.unitScrollView;
const sv = svNode.getComponent(cc.ScrollView);
const content = sv.content;
content.removeAllChildren();
}
// 页面显示
async mounted() {
this.listItem = cc.find("view/item", this.unitScrollView);
const sv = this.unitScrollView.getComponent(cc.ScrollView);
this.svContent = sv.content;
await this.initView();
}
// 页面隐藏
isDestory = false;
async unmounted() {
const sv = cc.find("middleLayer/Views/UnitPage/unit_list_node/scrollView")
sv.off("scrolling")
const content = this.svContent;
this.unitScrollView.off("scrolling")
content.destroyAllChildren();
this.isDestory = true;
this.lastUpdate = 0;
this.allListItemNodes.forEach(node => {
node && node.destroy()
})
this.allListItemNodes = [];
}
......@@ -187,9 +191,7 @@ export default class UnitPageClass extends PageComponentBaseClass {
this.allListItemNodes = [];
const svNode = this.unitScrollView;
svNode.opacity = 0;
const n1Date = new Date()
const resData = await this.Viewer.getComponent("PageViewer").getSyllabusTreeByPid(this.node['syllabus_pid'])
console.log("接口SyllabusTree`响应时间:", new Date() - n1Date)
let rows = []
this.configData = null
let bgImageUrl = null;
......@@ -206,29 +208,20 @@ export default class UnitPageClass extends PageComponentBaseClass {
}
if (rows.length == 0) {
const svNode = this.unitScrollView;
const sv = svNode.getComponent(cc.ScrollView);
const content = sv.content;
content.removeAllChildren();
this.svContent.destroyAllChildren();
return;
}
this.initCustomBg(bgImageUrl);
const n2Date = new Date()
await this.getAndStoreSyllabusStatus(rows);
console.log("接口SyllabusStatus响应时间:", new Date() - n2Date)
// const svNode = this.unitScrollView;
const view = cc.find("view", svNode);
view.width = svNode.width;
view.height = svNode.height;
const nowDate = new Date();
const sv = svNode.getComponent(cc.ScrollView);
this.getUnitItemDataArr(rows, sv);
const time = new Date() - nowDate
console.log("创建节点时间: ", time)
svNode.opacity = 255;
this.refreshConfig()
}
......@@ -243,15 +236,13 @@ export default class UnitPageClass extends PageComponentBaseClass {
}
listItem;
g_content = null;
svContent = null;
async getUnitItemDataArr(dataArr, sv) {
const content = this.g_content = sv.content;
content.removeAllChildren();
const content = sv.content;
sv.scrollToTop();
content.width = sv.node.width;
content.height = sv.node.height;
content.removeAllChildren();
let listItem = this.listItem;
let subItem = cc.find("/sub_item", listItem);
......@@ -263,6 +254,7 @@ export default class UnitPageClass extends PageComponentBaseClass {
}
const data = dataArr[i];
const itemNode = cc.instantiate(listItem);
itemNode.active = true;
const cardsContainer = cc.find("/cards", itemNode)
let listLabel = cc.find("/label", itemNode);
itemNode['data'] = data;
......@@ -364,8 +356,11 @@ export default class UnitPageClass extends PageComponentBaseClass {
lastUpdate = 0;
update (dt) {
if(this.isDestory) {
return
}
if(this.lastUpdate < this.allListItemNodes.length) {
this.allListItemNodes[this.lastUpdate++].parent = this.g_content
this.allListItemNodes[this.lastUpdate++].parent = this.svContent
}
}
}
......
......@@ -116,7 +116,6 @@ export function playAudioByUrl(audio_url, cb = null) {
}
}
export function btnClickAnima(btn, time = 0.15, rate = 1.05) {
btn.tmpScale = btn.scale;
btn.on(cc.Node.EventType.TOUCH_START, () => {
......@@ -138,12 +137,15 @@ export function btnClickAnima(btn, time = 0.15, rate = 1.05) {
export function getSpriteFrimeByUrl(url, cb) {
cc.loader.load({ url }, (err, img) => {
const spriteFrame = new cc.SpriteFrame(img)
if(!url) {
return
}
cc.assetManager.loadRemote(url, (error, texture2D) => {
const spriteFrame = new cc.SpriteFrame(texture2D)
if (cb) {
cb(spriteFrame);
}
})
});
}
export function appearAnim(node, time=1, callback=null) {
......
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