update
This commit is contained in:
@@ -39,9 +39,22 @@ export class ChatContentsLayout extends Component {
|
||||
}
|
||||
this.bubbles = [];
|
||||
|
||||
this.updateDialogLayout(dialogs);
|
||||
|
||||
// 清理多余的缓存气泡,避免内存泄漏
|
||||
this.cleanupExcessCachedBubbles();
|
||||
}
|
||||
|
||||
private updateDialogLayout(dialogs: Dialog[]) {
|
||||
let initPosY: number = BUTTOM_Y;
|
||||
for (let i = dialogs.length - 1; i >= 0; i--) {
|
||||
const dialog = dialogs[i]; //倒序
|
||||
let pendingUpdates = 0;
|
||||
|
||||
const updateNextBubble = (index: number) => {
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dialog = dialogs[index];
|
||||
let newBubble: DialogBubble = null;
|
||||
|
||||
// 尝试从缓存中获取合适的气泡
|
||||
@@ -69,17 +82,25 @@ export class ChatContentsLayout extends Component {
|
||||
}
|
||||
|
||||
newBubble.node.active = true;
|
||||
let offset = newBubble.updateBubbleContent(dialog.content);
|
||||
|
||||
let pos = newBubble.node.position;
|
||||
newBubble.node.position = new Vec3(pos.x, initPosY, pos.z);
|
||||
|
||||
initPosY += offset + 20;
|
||||
|
||||
pendingUpdates++;
|
||||
newBubble.updateBubbleContent(dialog.content, (actualHeight: number) => {
|
||||
initPosY += actualHeight + 20;
|
||||
pendingUpdates--;
|
||||
|
||||
// 当当前气泡更新完成后,处理下一个
|
||||
if (pendingUpdates === 0) {
|
||||
updateNextBubble(index - 1);
|
||||
}
|
||||
});
|
||||
|
||||
this.bubbles.push(newBubble);
|
||||
}
|
||||
};
|
||||
|
||||
// 清理多余的缓存气泡,避免内存泄漏
|
||||
this.cleanupExcessCachedBubbles();
|
||||
// 从最后一个对话开始处理(倒序)
|
||||
updateNextBubble(dialogs.length - 1);
|
||||
}
|
||||
|
||||
private cleanupExcessCachedBubbles() {
|
||||
|
||||
Reference in New Issue
Block a user