This commit is contained in:
2025-09-11 10:54:06 +08:00
parent 53f2037c49
commit a590433a91
7 changed files with 413 additions and 419 deletions
+40 -42
View File
@@ -135,32 +135,9 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
console.error("ChatPanel: SceneBgVideoLayer.handle 未初始化");
} else {
console.log("ChatPanel: 成功获取 SceneBgVideoLayer 实例");
this.initVideoPosition();
}
}
/**
* 初始化视频位置和属性
*/
private initVideoPosition() {
if (!this.videoLayer || !this.videoArea) return;
// 设置视频锚点为中心 (0.5, 0.5),这样视频的中心点就是定位点
this.videoLayer.setVideoAnchor(0.5, 0.5);
// 使用 videoArea 的世界坐标位置
const videoAreaWorldPos = this.videoArea.node.getWorldPosition();
this.videoLayer.setVideoWorldPosition(
this.videoLayer.node.worldPosition.x,
videoAreaWorldPos.y,
videoAreaWorldPos.z
);
this.videoLayer.setVideoScale(1);
console.log(
`ChatPanel: 初始化视频世界位置到 (${videoAreaWorldPos.x}, ${videoAreaWorldPos.y})`
);
}
register() {
Utils.addInnerEL(
InnerMsgCode.Chat_DialogRefresh,
@@ -277,15 +254,18 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
? new Size(this.videoArea.width, this.videoArea.height)
: new Size(600, 800);
const videoData = {
path: initialVideo,
size: targetSize,
bgFrameNode: this.videoArea ? this.videoArea.node : null,
};
// Set current emotion to the loaded video's emotion
this.currentEmotion = this.chatController.getCurrentEmotion();
this.videoLayer.playLocalLoopVideo(videoData);
// 使用新的统一 playVideo 方法
const videoAreaPos = this.videoArea
? this.videoArea.node.getWorldPosition()
: undefined;
this.videoLayer.playVideo(initialVideo, {
loop: true,
size: targetSize,
position: videoAreaPos,
});
// 延迟调整视频缩放
this.scheduleOnce(() => {
@@ -311,9 +291,6 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
const videoTransform = videoPlayer.node.getComponent(UITransform);
if (videoTransform && videoTransform.height > 0) {
// 设置视频锚点为中心 (0.5, 0.5),确保视频的中心点就是定位点
this.videoLayer.setVideoAnchor(0.5, 0.5);
// 计算缩放比例,使视频高度填满 videoArea
const scale = this.videoArea.height / videoTransform.height;
@@ -323,12 +300,9 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
// 获取 videoArea 的世界坐标中心点
const videoAreaWorldPos = this.videoArea.node.getWorldPosition();
// 使用世界坐标设置视频位置,确保正确对齐
this.videoLayer.setVideoWorldPosition(
this.videoLayer.node.worldPosition.x,
videoAreaWorldPos.y,
videoAreaWorldPos.z
);
// 使用新的 playVideo 方法的位置参数,如果需要更新位置
// 由于视频已经在播放,这里只调整缩放
// 位置调整已在 playVideo 中处理
console.log(
`ChatPanel: 视频缩放到 ${scale}, videoArea高度: ${this.videoArea.height}, 视频高度: ${videoTransform.height}`
@@ -408,8 +382,20 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
})`
);
// Load the new video
this.videoLayer.playVideo(matchingVideo, true);
// Load the new video with the unified playVideo method
// 获取 videoArea 的尺寸和位置
const targetSize = this.videoArea
? new Size(this.videoArea.width, this.videoArea.height)
: new Size(600, 800);
const videoAreaPos = this.videoArea
? this.videoArea.node.getWorldPosition()
: undefined;
this.videoLayer.playVideo(matchingVideo, {
loop: true,
size: targetSize,
position: videoAreaPos,
});
//ResManager.I.changeBundleVideo(this.girlVideo, matchingVideo, "Girls");
// Update current emotion state
@@ -430,7 +416,19 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
`Loading fallback video: ${fallbackVideo} (emotion: ${VideoEmotion[fallbackVideo]})`
);
this.videoLayer.playVideo(fallbackVideo, true);
// 获取 videoArea 的尺寸和位置
const targetSize = this.videoArea
? new Size(this.videoArea.width, this.videoArea.height)
: new Size(600, 800);
const videoAreaPos = this.videoArea
? this.videoArea.node.getWorldPosition()
: undefined;
this.videoLayer.playVideo(fallbackVideo, {
loop: true,
size: targetSize,
position: videoAreaPos,
});
// Update current emotion state to the fallback video's emotion
this.currentEmotion = this.chatController.getCurrentEmotion();