import { _decorator, Component, Node, sys, Widget } from 'cc'; const { ccclass, property } = _decorator; @ccclass('FrameBg') export class FrameBg extends Component { protected onLoad() { // 判断平台 if (sys.isMobile) { // 手机端添加Widget组件 const widget = this.node.addComponent(Widget); widget.isAlignLeft = true; widget.isAlignRight = true; widget.isAlignTop = true; widget.isAlignBottom = true; widget.left = 0; widget.right = 0; widget.top = 0; widget.bottom = 0; widget.updateAlignment(); } // PC端不做处理 } start() { } update(deltaTime: number) { } }