// ScreenAdapter.ts
import { _decorator, Component, view, ResolutionPolicy } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('ScreenAdapter')
export class ScreenAdapter extends Component {
    @property
    designWidth: number = 1080;   // 默认设计宽度

    @property
    designHeight: number = 1920;  // 默认设计高度

    onLoad() {
        this.applyAdapter();
    }

    /**
     * 应用屏幕适配
     */
    applyAdapter() {
        // const frameSize = view.getFrameSize();
        // const aspect = frameSize.width / frameSize.height;
        // const designAspect = this.designWidth / this.designHeight;

        // if (aspect > designAspect) {
        //     // 屏幕更宽 → 固定高度，保证上下完整
        //     view.setDesignResolutionSize(this.designWidth, this.designHeight, ResolutionPolicy.FIXED_HEIGHT);
        //     console.log('[ScreenAdapter] Use FIXED_HEIGHT, aspect =', aspect.toFixed(2));
        // } else {
        //     // 屏幕更窄 → 固定宽度，保证左右完整
        //     view.setDesignResolutionSize(this.designWidth, this.designHeight, ResolutionPolicy.FIXED_WIDTH);
        //     console.log('[ScreenAdapter] Use FIXED_WIDTH, aspect =', aspect.toFixed(2));
        // }
    }
}
