imageItem 缓存池
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { NodePool, instantiate, Node, isValid } from "cc";
|
||||
import { DetailImageItem } from "../uiitems/DetailImageItem";
|
||||
|
||||
export class DetailImageItemPool {
|
||||
private static _instance: DetailImageItemPool = null;
|
||||
|
||||
private _pool: NodePool;
|
||||
private _template: Node = null;
|
||||
|
||||
private constructor() {
|
||||
this._pool = new NodePool();
|
||||
}
|
||||
|
||||
public static get Instance(): DetailImageItemPool {
|
||||
if (!this._instance) {
|
||||
this._instance = new DetailImageItemPool();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
public setTemplate(template: Node): void {
|
||||
this._template = template;
|
||||
}
|
||||
|
||||
public get(): Node {
|
||||
let node: Node = null;
|
||||
|
||||
if (this._pool.size() > 0) {
|
||||
node = this._pool.get();
|
||||
} else {
|
||||
if (this._template) {
|
||||
node = instantiate(this._template);
|
||||
}
|
||||
}
|
||||
|
||||
if (node) {
|
||||
const item = node.getComponent(DetailImageItem);
|
||||
if (item && item.reset) {
|
||||
item.reset();
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
public put(node: Node): void {
|
||||
if (node && isValid(node)) {
|
||||
node.removeFromParent();
|
||||
this._pool.put(node);
|
||||
}
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this._pool.clear();
|
||||
}
|
||||
|
||||
public getPoolSize(): number {
|
||||
return this._pool.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "da0fc97b-079e-4f2f-b288-779e5729c21b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "c651522c-4a0f-45c1-85ac-118560c04f90",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
Node,
|
||||
Sprite,
|
||||
VideoPlayer,
|
||||
instantiate,
|
||||
UITransform,
|
||||
Size,
|
||||
Vec3,
|
||||
@@ -14,6 +13,7 @@ import li_BaseView from "db://assets/Scripts/Main/Common/li_BaseView";
|
||||
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
|
||||
import { DetailImageItem } from "../../uiitems/DetailImageItem";
|
||||
import { NavigationManager, PanelType } from "../../manager/NavigationManager";
|
||||
import { DetailImageItemPool } from "../../manager/DetailImageItemPool";
|
||||
import { ConfigManager } from "../../manager/ConfigManager";
|
||||
import LanguageUtils from "../../../Main/Common/LanguageUtils";
|
||||
import Utils from "../../../Main/Common/Utils";
|
||||
@@ -82,6 +82,8 @@ export class GirlDetailPanel extends li_BaseView {
|
||||
|
||||
//this.refresh();
|
||||
|
||||
DetailImageItemPool.Instance.setTemplate(this.imgItemInst.node);
|
||||
|
||||
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
|
||||
this.girlName.string = LanguageUtils.getText(this.nameKey);
|
||||
let desc = "";
|
||||
@@ -279,35 +281,22 @@ export class GirlDetailPanel extends li_BaseView {
|
||||
resIds: number[]
|
||||
) {
|
||||
for (let i = this.imgsLayout.children.length - 1; i >= 0; i--) {
|
||||
this.imgsLayout.children[i].destroy();
|
||||
DetailImageItemPool.Instance.put(this.imgsLayout.children[i]);
|
||||
}
|
||||
|
||||
let count = resIds.length;
|
||||
for (let i = 0; i < count; i++) {
|
||||
let newNode = instantiate(this.imgItemInst.node);
|
||||
let item = newNode.getComponent(DetailImageItem);
|
||||
let resId = resIds[i];
|
||||
item.refresh(this, type, category, id, resId);
|
||||
newNode.active = true;
|
||||
this.imgsLayout.addChild(newNode);
|
||||
let newNode = DetailImageItemPool.Instance.get();
|
||||
if (newNode) {
|
||||
let item = newNode.getComponent(DetailImageItem);
|
||||
let resId = resIds[i];
|
||||
item.refresh(this, type, category, id, resId);
|
||||
newNode.active = true;
|
||||
this.imgsLayout.addChild(newNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化视频位置和属性
|
||||
*/
|
||||
private initVideoPosition() {
|
||||
if (!this.videoLayer || !this.videoArea) return;
|
||||
|
||||
// 使用 videoArea 的世界坐标位置
|
||||
const videoAreaWorldPos = this.videoArea.node.getWorldPosition();
|
||||
// 视频位置和缩放已在 playVideo 中处理
|
||||
//this.videoLayer.setVideoScale(1);
|
||||
console.log(
|
||||
`GirlDetailPanel: 初始化视频世界位置到 (${videoAreaWorldPos.x}, ${videoAreaWorldPos.y})`
|
||||
);
|
||||
}
|
||||
|
||||
OnClickChatBtn() {
|
||||
// 使用带过渡动画的导航方法
|
||||
NavigationManager.Instance.switchToPanel(PanelType.CHAT);
|
||||
@@ -340,6 +329,11 @@ export class GirlDetailPanel extends li_BaseView {
|
||||
//console.log("GirlDetailPanel: 销毁时停止视频播放");
|
||||
}
|
||||
|
||||
// 回收所有使用中的节点到对象池
|
||||
for (let i = this.imgsLayout.children.length - 1; i >= 0; i--) {
|
||||
DetailImageItemPool.Instance.put(this.imgsLayout.children[i]);
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,4 +222,25 @@ export class DetailImageItem extends Component {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.base = null;
|
||||
this.url = "";
|
||||
this.isImage = false;
|
||||
this.category = 0;
|
||||
this.girlId = 0;
|
||||
this.resId = 0;
|
||||
this.type = null;
|
||||
this.isVisible = false;
|
||||
|
||||
this.question.active = true;
|
||||
this.video.enabled = false;
|
||||
this.priceFrame.active = false;
|
||||
this.loading.active = false;
|
||||
this.videoPrice.string = "";
|
||||
|
||||
if (this.img && this.img.spriteFrame) {
|
||||
this.img.spriteFrame = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,21 +24,21 @@
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 403
|
||||
},
|
||||
{
|
||||
"__id__": 405
|
||||
},
|
||||
{
|
||||
"__id__": 407
|
||||
},
|
||||
{
|
||||
"__id__": 409
|
||||
},
|
||||
{
|
||||
"__id__": 411
|
||||
},
|
||||
{
|
||||
"__id__": 413
|
||||
},
|
||||
{
|
||||
"__id__": 415
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 417
|
||||
"__id__": 411
|
||||
},
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
@@ -88,23 +88,23 @@
|
||||
"__id__": 15
|
||||
},
|
||||
{
|
||||
"__id__": 391
|
||||
"__id__": 385
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 402
|
||||
"__id__": 396
|
||||
},
|
||||
{
|
||||
"__id__": 404
|
||||
"__id__": 398
|
||||
},
|
||||
{
|
||||
"__id__": 406
|
||||
"__id__": 400
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 408
|
||||
"__id__": 402
|
||||
},
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
@@ -426,17 +426,17 @@
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 384
|
||||
"__id__": 378
|
||||
},
|
||||
{
|
||||
"__id__": 386
|
||||
"__id__": 380
|
||||
},
|
||||
{
|
||||
"__id__": 388
|
||||
"__id__": 382
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 390
|
||||
"__id__": 384
|
||||
},
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
@@ -7037,31 +7037,28 @@
|
||||
},
|
||||
{
|
||||
"__id__": 347
|
||||
},
|
||||
{
|
||||
"__id__": 367
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 367
|
||||
},
|
||||
{
|
||||
"__id__": 369
|
||||
},
|
||||
{
|
||||
"__id__": 371
|
||||
},
|
||||
{
|
||||
"__id__": 373
|
||||
},
|
||||
{
|
||||
"__id__": 375
|
||||
},
|
||||
{
|
||||
"__id__": 377
|
||||
},
|
||||
{
|
||||
"__id__": 379
|
||||
},
|
||||
{
|
||||
"__id__": 381
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 383
|
||||
"__id__": 377
|
||||
},
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
@@ -8475,165 +8472,6 @@
|
||||
"targetOverrides": null,
|
||||
"nestedPrefabInstanceRoots": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "resID",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
"__id__": 304
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 368
|
||||
},
|
||||
{
|
||||
"__id__": 370
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 372
|
||||
},
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_lrot": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1
|
||||
},
|
||||
"_lscale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1
|
||||
},
|
||||
"_mobility": 0,
|
||||
"_layer": 33554432,
|
||||
"_euler": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.UITransform",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 367
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 369
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 79.19427490234375,
|
||||
"height": 54.4
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "bcBKPuun9BloOABIN9mapU"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 367
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 371
|
||||
},
|
||||
"_customMaterial": null,
|
||||
"_srcBlendFactor": 2,
|
||||
"_dstBlendFactor": 4,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_string": "label",
|
||||
"_horizontalAlign": 1,
|
||||
"_verticalAlign": 1,
|
||||
"_actualFontSize": 35.6,
|
||||
"_fontSize": 35.6,
|
||||
"_fontFamily": "Arial",
|
||||
"_lineHeight": 40,
|
||||
"_overflow": 0,
|
||||
"_enableWrapText": true,
|
||||
"_font": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_isItalic": false,
|
||||
"_isBold": false,
|
||||
"_isUnderline": false,
|
||||
"_underlineHeight": 2,
|
||||
"_cacheMode": 0,
|
||||
"_enableOutline": true,
|
||||
"_outlineColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 0,
|
||||
"b": 0,
|
||||
"a": 255
|
||||
},
|
||||
"_outlineWidth": 2,
|
||||
"_enableShadow": false,
|
||||
"_shadowColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 0,
|
||||
"b": 0,
|
||||
"a": 255
|
||||
},
|
||||
"_shadowOffset": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 2,
|
||||
"y": 2
|
||||
},
|
||||
"_shadowBlur": 2,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "afOpupHGJCM6HANoU8k3zT"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
"__id__": 1
|
||||
},
|
||||
"asset": {
|
||||
"__id__": 0
|
||||
},
|
||||
"fileId": "cdDIgyOJxGjK+HeIfe4Zal",
|
||||
"instance": null,
|
||||
"targetOverrides": null,
|
||||
"nestedPrefabInstanceRoots": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.UITransform",
|
||||
"_name": "",
|
||||
@@ -8644,7 +8482,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 374
|
||||
"__id__": 368
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
@@ -8672,7 +8510,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 376
|
||||
"__id__": 370
|
||||
},
|
||||
"clickEvents": [],
|
||||
"_interactable": true,
|
||||
@@ -8730,7 +8568,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 378
|
||||
"__id__": 372
|
||||
},
|
||||
"img": {
|
||||
"__id__": 308
|
||||
@@ -8766,7 +8604,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 380
|
||||
"__id__": 374
|
||||
},
|
||||
"_type": 0,
|
||||
"_inverted": false,
|
||||
@@ -8788,7 +8626,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 382
|
||||
"__id__": 376
|
||||
},
|
||||
"_customMaterial": null,
|
||||
"_srcBlendFactor": 2,
|
||||
@@ -8847,7 +8685,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 385
|
||||
"__id__": 379
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
@@ -8875,7 +8713,7 @@
|
||||
},
|
||||
"_enabled": false,
|
||||
"__prefab": {
|
||||
"__id__": 387
|
||||
"__id__": 381
|
||||
},
|
||||
"_customMaterial": null,
|
||||
"_srcBlendFactor": 2,
|
||||
@@ -8920,7 +8758,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 389
|
||||
"__id__": 383
|
||||
},
|
||||
"_alignFlags": 40,
|
||||
"_target": null,
|
||||
@@ -8971,20 +8809,20 @@
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 392
|
||||
"__id__": 386
|
||||
},
|
||||
{
|
||||
"__id__": 394
|
||||
"__id__": 388
|
||||
},
|
||||
{
|
||||
"__id__": 396
|
||||
"__id__": 390
|
||||
},
|
||||
{
|
||||
"__id__": 399
|
||||
"__id__": 393
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 401
|
||||
"__id__": 395
|
||||
},
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
@@ -9021,11 +8859,11 @@
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 391
|
||||
"__id__": 385
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 393
|
||||
"__id__": 387
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
@@ -9049,11 +8887,11 @@
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 391
|
||||
"__id__": 385
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 395
|
||||
"__id__": 389
|
||||
},
|
||||
"_customMaterial": null,
|
||||
"_srcBlendFactor": 2,
|
||||
@@ -9094,15 +8932,15 @@
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 391
|
||||
"__id__": 385
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 397
|
||||
"__id__": 391
|
||||
},
|
||||
"clickEvents": [
|
||||
{
|
||||
"__id__": 398
|
||||
"__id__": 392
|
||||
}
|
||||
],
|
||||
"_interactable": true,
|
||||
@@ -9142,7 +8980,7 @@
|
||||
"_duration": 0.1,
|
||||
"_zoomScale": 0.9,
|
||||
"_target": {
|
||||
"__id__": 391
|
||||
"__id__": 385
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
@@ -9166,11 +9004,11 @@
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 391
|
||||
"__id__": 385
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 400
|
||||
"__id__": 394
|
||||
},
|
||||
"_alignFlags": 9,
|
||||
"_target": null,
|
||||
@@ -9219,7 +9057,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 403
|
||||
"__id__": 397
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
@@ -9247,7 +9085,7 @@
|
||||
},
|
||||
"_enabled": false,
|
||||
"__prefab": {
|
||||
"__id__": 405
|
||||
"__id__": 399
|
||||
},
|
||||
"_customMaterial": null,
|
||||
"_srcBlendFactor": 2,
|
||||
@@ -9292,7 +9130,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 407
|
||||
"__id__": 401
|
||||
},
|
||||
"_alignFlags": 45,
|
||||
"_target": null,
|
||||
@@ -9341,7 +9179,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 410
|
||||
"__id__": 404
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
@@ -9369,7 +9207,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 412
|
||||
"__id__": 406
|
||||
},
|
||||
"_alignFlags": 45,
|
||||
"_target": null,
|
||||
@@ -9405,7 +9243,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 414
|
||||
"__id__": 408
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
@@ -9423,7 +9261,7 @@
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 416
|
||||
"__id__": 410
|
||||
},
|
||||
"m_rootNode": null,
|
||||
"videoArea": {
|
||||
@@ -9457,7 +9295,7 @@
|
||||
"__id__": 15
|
||||
},
|
||||
"imgItemInst": {
|
||||
"__id__": 377
|
||||
"__id__": 371
|
||||
},
|
||||
"imgsLayout": {
|
||||
"__id__": 271
|
||||
|
||||
Reference in New Issue
Block a user