适配效果优化

This commit is contained in:
2025-08-13 16:17:44 +08:00
parent 8048584f38
commit 5300d68462
10 changed files with 1482 additions and 216 deletions
+67 -13
View File
@@ -117,24 +117,78 @@ export class SceneBgVideoLayer extends li_BaseView {
playLocalLoopVideo(data:any) {
ResManager.I.changeBundleVideo(this.videoPlayer,data.path,"Chat18x",(res:VideoClip)=>{
this.videoPlayer.play();
let uiT:UITransform = this.videoPlayer.node.getComponent(UITransform);
const videoSize = uiT.contentSize;
const targetSize = data.size;
console.log('Video size:', videoSize, 'Target size:', targetSize);
// 计算宽度和高度的缩放比例
const scaleX = targetSize.width / videoSize.width;
const scaleY = targetSize.height / videoSize.height;
// 选择较大的缩放比例以填满整个区域(可能超出但不会有黑边)
const scale = Math.max(scaleX, scaleY);
// 移除之前的事件监听器,避免重复绑定
this.videoPlayer.node.off(VideoPlayer.EventType.READY_TO_PLAY, this.onVideoReadyToPlay, this);
console.log(`Video scaling: scaleX=${scaleX}, scaleY=${scaleY}, final scale=${scale}`);
this.videoPlayer.node.setScale(new Vec3(scale, scale, 1));
// 添加视频准备完成事件监听
this.videoPlayer.node.on(VideoPlayer.EventType.READY_TO_PLAY, this.onVideoReadyToPlay, this);
// 保存当前数据供回调使用
this.currentVideoData = data;
// 也立即尝试调整(以防已经准备好)
this.adjustVideoToFillFrame(data.size, data.bgFrameNode);
});
}
private currentVideoData: any = null;
private onVideoReadyToPlay = () => {
if (this.currentVideoData) {
this.adjustVideoToFillFrame(this.currentVideoData.size, this.currentVideoData.bgFrameNode);
}
}
adjustVideoToFillFrame(targetSize: any, bgFrameNode?: Node) {
if (!this.videoPlayer) return;
const tryAdjust = () => {
let uiT: UITransform = this.videoPlayer.node.getComponent(UITransform);
const videoSize = uiT.contentSize;
console.log('Video size:', videoSize, 'Target size:', targetSize);
if (videoSize.width > 0 && videoSize.height > 0) {
// 计算宽度和高度的缩放比例
const scaleX = targetSize.width / videoSize.width;
const scaleY = targetSize.height / videoSize.height;
// 选择较大的缩放比例以填满整个区域(可能超出但不会有黑边)
const scale = Math.max(scaleX, scaleY);
console.log(`Video scaling: scaleX=${scaleX}, scaleY=${scaleY}, final scale=${scale}`);
this.videoPlayer.node.setScale(new Vec3(scale, scale, 1));
// 只有传入bgFrameNode时才调整位置
if (bgFrameNode && isValid(bgFrameNode) && bgFrameNode.position) {
this.videoPlayer.node.setPosition(
bgFrameNode.position.x,
bgFrameNode.position.y,
bgFrameNode.position.z
);
console.log(`Video positioned to bgFrame center: ${bgFrameNode.position}`);
}
return true;
}
return false;
};
// 立即尝试一次
if (!tryAdjust()) {
// 如果失败,延迟尝试
this.scheduleOnce(() => {
if (!tryAdjust()) {
// 再次延迟尝试
this.scheduleOnce(() => {
tryAdjust();
}, 0.5);
}
}, 0.1);
}
}
/**播放循环视频 */
playLoopVideo(path: string, force = false) {
if (this.remoteLoopPath == path && !force) {
+9 -15
View File
@@ -12,6 +12,7 @@ import {
import li_BaseView from "../../Main/Common/li_BaseView";
import LanguageUtils, { LanguageType } from "../../Main/Common/LanguageUtils";
import AudioManager from "../../Main/Manager/AudioManager";
import ConfigManager from "../../chat18x/manager/ConfigManager";
const { ccclass, property } = _decorator;
@@ -28,6 +29,9 @@ export class SimpleLanguagePanel extends li_BaseView {
@property(Button)
private closeBtn: Button = null;
@property(Node)
private languageDrawdown: Node = null;
@property(Label)
private titleLabel: Label = null;
@@ -62,13 +66,14 @@ export class SimpleLanguagePanel extends li_BaseView {
onEnable() {
this.currentSelectedLang = LanguageUtils.CurrentLanguage;
this.updateSelection();
this.languageDrawdown.active = false;
}
public onClickLanguageSelect() {
this.languageDrawdown.active = true;
}
private initUI() {
if (this.titleLabel) {
this.titleLabel.string = this.getMultiLangTitle();
}
// 初始化语言按钮数组
this.initLanguageButton(this.btnEnglish, LanguageType.EN, "English");
this.initLanguageButton(this.btnChinese, LanguageType.CN, "中文");
@@ -77,17 +82,6 @@ export class SimpleLanguagePanel extends li_BaseView {
this.initLanguageButton(this.btnGerman, LanguageType.DE, "Deutsch");
}
private getMultiLangTitle(): string {
const titles = [
"Select Language",
"选择语言",
"भाषा चुनें",
"Choisir la langue",
"Sprache wählen",
];
return titles.join(" / ");
}
private initLanguageButton(
button: Button,
language: LanguageType,